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 {};
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;
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);
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);
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;
437 template<class U> bool owner_before(weak_ptr<U> const& b) const;
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;
535 template<class U> bool owner_before(weak_ptr<U> const& b) const;
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;
550 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
551 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
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;
560 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
561 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
565 class enable_shared_from_this
568 constexpr enable_shared_from_this() noexcept;
569 enable_shared_from_this(enable_shared_from_this const&) noexcept;
570 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
571 ~enable_shared_from_this();
573 shared_ptr<T> shared_from_this();
574 shared_ptr<T const> shared_from_this() const;
578 bool atomic_is_lock_free(const shared_ptr<T>* p);
580 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
582 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
584 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
586 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
588 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
591 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
594 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
597 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
600 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
601 shared_ptr<T> w, memory_order success,
602 memory_order failure);
605 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
606 shared_ptr<T> w, memory_order success,
607 memory_order failure);
609 template <class T> struct hash;
610 template <class T, class D> struct hash<unique_ptr<T, D> >;
611 template <class T> struct hash<shared_ptr<T> >;
614 enum class pointer_safety { relaxed, preferred, strict };
615 void declare_reachable(void *p);
616 template <class T> T *undeclare_reachable(T *p);
617 void declare_no_pointers(char *p, size_t n);
618 void undeclare_no_pointers(char *p, size_t n);
619 pointer_safety get_pointer_safety() noexcept;
621 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
628 #include <type_traits>
636 #include <__functional_base>
642 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
646 #include <__undef_min_max>
648 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
649 #pragma GCC system_header
652 _LIBCPP_BEGIN_NAMESPACE_STD
654 template <class _ValueType>
655 inline _LIBCPP_ALWAYS_INLINE
656 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
657 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
658 defined(__ATOMIC_RELAXED) && \
659 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
660 return __atomic_load_n(__value, __ATOMIC_RELAXED);
666 template <class _ValueType>
667 inline _LIBCPP_ALWAYS_INLINE
668 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
669 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
670 defined(__ATOMIC_ACQUIRE) && \
671 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
672 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
678 // addressof moved to <type_traits>
680 template <class _Tp> class allocator;
683 class _LIBCPP_TEMPLATE_VIS allocator<void>
686 typedef void* pointer;
687 typedef const void* const_pointer;
688 typedef void value_type;
690 template <class _Up> struct rebind {typedef allocator<_Up> other;};
694 class _LIBCPP_TEMPLATE_VIS allocator<const void>
697 typedef const void* pointer;
698 typedef const void* const_pointer;
699 typedef const void value_type;
701 template <class _Up> struct rebind {typedef allocator<_Up> other;};
707 struct __has_element_type
710 struct __two {char __lx; char __lxx;};
711 template <class _Up> static __two __test(...);
712 template <class _Up> static char __test(typename _Up::element_type* = 0);
714 static const bool value = sizeof(__test<_Tp>(0)) == 1;
717 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
718 struct __pointer_traits_element_type;
720 template <class _Ptr>
721 struct __pointer_traits_element_type<_Ptr, true>
723 typedef typename _Ptr::element_type type;
726 #ifndef _LIBCPP_HAS_NO_VARIADICS
728 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
729 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
731 typedef typename _Sp<_Tp, _Args...>::element_type type;
734 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
735 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
740 #else // _LIBCPP_HAS_NO_VARIADICS
742 template <template <class> class _Sp, class _Tp>
743 struct __pointer_traits_element_type<_Sp<_Tp>, true>
745 typedef typename _Sp<_Tp>::element_type type;
748 template <template <class> class _Sp, class _Tp>
749 struct __pointer_traits_element_type<_Sp<_Tp>, false>
754 template <template <class, class> class _Sp, class _Tp, class _A0>
755 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
757 typedef typename _Sp<_Tp, _A0>::element_type type;
760 template <template <class, class> class _Sp, class _Tp, class _A0>
761 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
766 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
767 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
769 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
772 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
773 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
778 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
779 class _A1, class _A2>
780 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
782 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
785 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
786 class _A1, class _A2>
787 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
792 #endif // _LIBCPP_HAS_NO_VARIADICS
795 struct __has_difference_type
798 struct __two {char __lx; char __lxx;};
799 template <class _Up> static __two __test(...);
800 template <class _Up> static char __test(typename _Up::difference_type* = 0);
802 static const bool value = sizeof(__test<_Tp>(0)) == 1;
805 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
806 struct __pointer_traits_difference_type
808 typedef ptrdiff_t type;
811 template <class _Ptr>
812 struct __pointer_traits_difference_type<_Ptr, true>
814 typedef typename _Ptr::difference_type type;
817 template <class _Tp, class _Up>
821 struct __two {char __lx; char __lxx;};
822 template <class _Xp> static __two __test(...);
823 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
825 static const bool value = sizeof(__test<_Tp>(0)) == 1;
828 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
829 struct __pointer_traits_rebind
831 #ifndef _LIBCPP_CXX03_LANG
832 typedef typename _Tp::template rebind<_Up> type;
834 typedef typename _Tp::template rebind<_Up>::other type;
838 #ifndef _LIBCPP_HAS_NO_VARIADICS
840 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
841 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
843 #ifndef _LIBCPP_CXX03_LANG
844 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
846 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
850 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
851 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
853 typedef _Sp<_Up, _Args...> type;
856 #else // _LIBCPP_HAS_NO_VARIADICS
858 template <template <class> class _Sp, class _Tp, class _Up>
859 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
861 #ifndef _LIBCPP_CXX03_LANG
862 typedef typename _Sp<_Tp>::template rebind<_Up> type;
864 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
868 template <template <class> class _Sp, class _Tp, class _Up>
869 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
871 typedef _Sp<_Up> type;
874 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
875 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
877 #ifndef _LIBCPP_CXX03_LANG
878 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
880 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
884 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
885 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
887 typedef _Sp<_Up, _A0> type;
890 template <template <class, class, class> class _Sp, class _Tp, class _A0,
891 class _A1, class _Up>
892 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
894 #ifndef _LIBCPP_CXX03_LANG
895 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
897 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
901 template <template <class, class, class> class _Sp, class _Tp, class _A0,
902 class _A1, class _Up>
903 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
905 typedef _Sp<_Up, _A0, _A1> type;
908 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
909 class _A1, class _A2, class _Up>
910 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
912 #ifndef _LIBCPP_CXX03_LANG
913 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
915 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
919 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
920 class _A1, class _A2, class _Up>
921 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
923 typedef _Sp<_Up, _A0, _A1, _A2> type;
926 #endif // _LIBCPP_HAS_NO_VARIADICS
928 template <class _Ptr>
929 struct _LIBCPP_TEMPLATE_VIS pointer_traits
931 typedef _Ptr pointer;
932 typedef typename __pointer_traits_element_type<pointer>::type element_type;
933 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
935 #ifndef _LIBCPP_CXX03_LANG
936 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
938 template <class _Up> struct rebind
939 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
940 #endif // _LIBCPP_CXX03_LANG
945 _LIBCPP_INLINE_VISIBILITY
946 static pointer pointer_to(typename conditional<is_void<element_type>::value,
947 __nat, element_type>::type& __r)
948 {return pointer::pointer_to(__r);}
952 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
954 typedef _Tp* pointer;
955 typedef _Tp element_type;
956 typedef ptrdiff_t difference_type;
958 #ifndef _LIBCPP_CXX03_LANG
959 template <class _Up> using rebind = _Up*;
961 template <class _Up> struct rebind {typedef _Up* other;};
967 _LIBCPP_INLINE_VISIBILITY
968 static pointer pointer_to(typename conditional<is_void<element_type>::value,
969 __nat, element_type>::type& __r) _NOEXCEPT
970 {return _VSTD::addressof(__r);}
973 template <class _From, class _To>
974 struct __rebind_pointer {
975 #ifndef _LIBCPP_CXX03_LANG
976 typedef typename pointer_traits<_From>::template rebind<_To> type;
978 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
984 namespace __has_pointer_type_imp
986 template <class _Up> static __two __test(...);
987 template <class _Up> static char __test(typename _Up::pointer* = 0);
991 struct __has_pointer_type
992 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
996 namespace __pointer_type_imp
999 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1000 struct __pointer_type
1002 typedef typename _Dp::pointer type;
1005 template <class _Tp, class _Dp>
1006 struct __pointer_type<_Tp, _Dp, false>
1011 } // __pointer_type_imp
1013 template <class _Tp, class _Dp>
1014 struct __pointer_type
1016 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1019 template <class _Tp>
1020 struct __has_const_pointer
1023 struct __two {char __lx; char __lxx;};
1024 template <class _Up> static __two __test(...);
1025 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1027 static const bool value = sizeof(__test<_Tp>(0)) == 1;
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>
1047 struct __has_void_pointer
1050 struct __two {char __lx; char __lxx;};
1051 template <class _Up> static __two __test(...);
1052 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1054 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1057 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1058 struct __void_pointer
1060 typedef typename _Alloc::void_pointer type;
1063 template <class _Ptr, class _Alloc>
1064 struct __void_pointer<_Ptr, _Alloc, false>
1066 #ifndef _LIBCPP_CXX03_LANG
1067 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1069 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1073 template <class _Tp>
1074 struct __has_const_void_pointer
1077 struct __two {char __lx; char __lxx;};
1078 template <class _Up> static __two __test(...);
1079 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1081 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1084 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1085 struct __const_void_pointer
1087 typedef typename _Alloc::const_void_pointer type;
1090 template <class _Ptr, class _Alloc>
1091 struct __const_void_pointer<_Ptr, _Alloc, false>
1093 #ifndef _LIBCPP_CXX03_LANG
1094 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1096 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1100 template <class _Tp>
1101 inline _LIBCPP_INLINE_VISIBILITY
1103 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1108 template <class _Pointer>
1109 inline _LIBCPP_INLINE_VISIBILITY
1110 typename pointer_traits<_Pointer>::element_type*
1111 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1113 return _VSTD::__to_raw_pointer(__p.operator->());
1116 template <class _Tp>
1117 struct __has_size_type
1120 struct __two {char __lx; char __lxx;};
1121 template <class _Up> static __two __test(...);
1122 template <class _Up> static char __test(typename _Up::size_type* = 0);
1124 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1127 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1130 typedef typename make_unsigned<_DiffType>::type type;
1133 template <class _Alloc, class _DiffType>
1134 struct __size_type<_Alloc, _DiffType, true>
1136 typedef typename _Alloc::size_type type;
1139 template <class _Tp>
1140 struct __has_propagate_on_container_copy_assignment
1143 struct __two {char __lx; char __lxx;};
1144 template <class _Up> static __two __test(...);
1145 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1147 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1150 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1151 struct __propagate_on_container_copy_assignment
1153 typedef false_type type;
1156 template <class _Alloc>
1157 struct __propagate_on_container_copy_assignment<_Alloc, true>
1159 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1162 template <class _Tp>
1163 struct __has_propagate_on_container_move_assignment
1166 struct __two {char __lx; char __lxx;};
1167 template <class _Up> static __two __test(...);
1168 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1170 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1173 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1174 struct __propagate_on_container_move_assignment
1176 typedef false_type type;
1179 template <class _Alloc>
1180 struct __propagate_on_container_move_assignment<_Alloc, true>
1182 typedef typename _Alloc::propagate_on_container_move_assignment type;
1185 template <class _Tp>
1186 struct __has_propagate_on_container_swap
1189 struct __two {char __lx; char __lxx;};
1190 template <class _Up> static __two __test(...);
1191 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1193 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1196 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1197 struct __propagate_on_container_swap
1199 typedef false_type type;
1202 template <class _Alloc>
1203 struct __propagate_on_container_swap<_Alloc, true>
1205 typedef typename _Alloc::propagate_on_container_swap type;
1208 template <class _Tp>
1209 struct __has_is_always_equal
1212 struct __two {char __lx; char __lxx;};
1213 template <class _Up> static __two __test(...);
1214 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1216 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1219 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1220 struct __is_always_equal
1222 typedef typename _VSTD::is_empty<_Alloc>::type type;
1225 template <class _Alloc>
1226 struct __is_always_equal<_Alloc, true>
1228 typedef typename _Alloc::is_always_equal type;
1231 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1232 struct __has_rebind_other
1235 struct __two {char __lx; char __lxx;};
1236 template <class _Xp> static __two __test(...);
1237 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1239 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1242 template <class _Tp, class _Up>
1243 struct __has_rebind_other<_Tp, _Up, false>
1245 static const bool value = false;
1248 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1249 struct __allocator_traits_rebind
1251 typedef typename _Tp::template rebind<_Up>::other type;
1254 #ifndef _LIBCPP_HAS_NO_VARIADICS
1256 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1257 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1259 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1262 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1263 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1265 typedef _Alloc<_Up, _Args...> type;
1268 #else // _LIBCPP_HAS_NO_VARIADICS
1270 template <template <class> class _Alloc, class _Tp, class _Up>
1271 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1273 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1276 template <template <class> class _Alloc, class _Tp, class _Up>
1277 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1279 typedef _Alloc<_Up> type;
1282 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1283 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1285 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1288 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1289 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1291 typedef _Alloc<_Up, _A0> type;
1294 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1295 class _A1, class _Up>
1296 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1298 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1301 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1302 class _A1, class _Up>
1303 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1305 typedef _Alloc<_Up, _A0, _A1> type;
1308 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1309 class _A1, class _A2, class _Up>
1310 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1312 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1315 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1316 class _A1, class _A2, class _Up>
1317 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1319 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1322 #endif // _LIBCPP_HAS_NO_VARIADICS
1324 #ifndef _LIBCPP_CXX03_LANG
1326 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1328 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1329 -> decltype(__a.allocate(__sz, __p), true_type());
1331 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1333 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1336 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1337 struct __has_allocate_hint
1338 : integral_constant<bool,
1340 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1341 declval<_SizeType>(),
1342 declval<_ConstVoidPtr>())),
1347 #else // _LIBCPP_CXX03_LANG
1349 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350 struct __has_allocate_hint
1355 #endif // _LIBCPP_CXX03_LANG
1357 #if !defined(_LIBCPP_CXX03_LANG)
1359 template <class _Alloc, class _Tp, class ..._Args>
1360 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1361 _VSTD::declval<_Args>()...),
1363 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1365 template <class _Alloc, class _Pointer, class ..._Args>
1367 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1369 template <class _Alloc, class _Pointer, class ..._Args>
1370 struct __has_construct
1371 : integral_constant<bool,
1373 decltype(__has_construct_test(declval<_Alloc>(),
1374 declval<_Pointer>(),
1375 declval<_Args>()...)),
1380 template <class _Alloc, class _Pointer>
1382 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1383 -> decltype(__a.destroy(__p), true_type());
1385 template <class _Alloc, class _Pointer>
1387 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1390 template <class _Alloc, class _Pointer>
1391 struct __has_destroy
1392 : integral_constant<bool,
1394 decltype(__has_destroy_test(declval<_Alloc>(),
1395 declval<_Pointer>())),
1400 template <class _Alloc>
1402 __has_max_size_test(_Alloc&& __a)
1403 -> decltype(__a.max_size(), true_type());
1405 template <class _Alloc>
1407 __has_max_size_test(const volatile _Alloc& __a)
1410 template <class _Alloc>
1411 struct __has_max_size
1412 : integral_constant<bool,
1414 decltype(__has_max_size_test(declval<_Alloc&>())),
1419 template <class _Alloc>
1421 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1422 -> decltype(__a.select_on_container_copy_construction(), true_type());
1424 template <class _Alloc>
1426 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1429 template <class _Alloc>
1430 struct __has_select_on_container_copy_construction
1431 : integral_constant<bool,
1433 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1438 #else // _LIBCPP_CXX03_LANG
1440 #ifndef _LIBCPP_HAS_NO_VARIADICS
1442 template <class _Alloc, class _Pointer, class ..._Args>
1443 struct __has_construct
1448 #else // _LIBCPP_HAS_NO_VARIADICS
1450 template <class _Alloc, class _Pointer, class _Args>
1451 struct __has_construct
1456 #endif // _LIBCPP_HAS_NO_VARIADICS
1458 template <class _Alloc, class _Pointer>
1459 struct __has_destroy
1464 template <class _Alloc>
1465 struct __has_max_size
1470 template <class _Alloc>
1471 struct __has_select_on_container_copy_construction
1476 #endif // _LIBCPP_CXX03_LANG
1478 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1479 struct __alloc_traits_difference_type
1481 typedef typename pointer_traits<_Ptr>::difference_type type;
1484 template <class _Alloc, class _Ptr>
1485 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1487 typedef typename _Alloc::difference_type type;
1490 template <class _Alloc>
1491 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1493 typedef _Alloc allocator_type;
1494 typedef typename allocator_type::value_type value_type;
1496 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1497 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1498 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1499 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1501 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1502 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1504 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1505 propagate_on_container_copy_assignment;
1506 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1507 propagate_on_container_move_assignment;
1508 typedef typename __propagate_on_container_swap<allocator_type>::type
1509 propagate_on_container_swap;
1510 typedef typename __is_always_equal<allocator_type>::type
1513 #ifndef _LIBCPP_CXX03_LANG
1514 template <class _Tp> using rebind_alloc =
1515 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1516 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1517 #else // _LIBCPP_CXX03_LANG
1518 template <class _Tp> struct rebind_alloc
1519 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1520 template <class _Tp> struct rebind_traits
1521 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1522 #endif // _LIBCPP_CXX03_LANG
1524 _LIBCPP_INLINE_VISIBILITY
1525 static pointer allocate(allocator_type& __a, size_type __n)
1526 {return __a.allocate(__n);}
1527 _LIBCPP_INLINE_VISIBILITY
1528 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1529 {return allocate(__a, __n, __hint,
1530 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1532 _LIBCPP_INLINE_VISIBILITY
1533 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1534 {__a.deallocate(__p, __n);}
1536 #ifndef _LIBCPP_HAS_NO_VARIADICS
1537 template <class _Tp, class... _Args>
1538 _LIBCPP_INLINE_VISIBILITY
1539 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1540 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1541 __a, __p, _VSTD::forward<_Args>(__args)...);}
1542 #else // _LIBCPP_HAS_NO_VARIADICS
1543 template <class _Tp>
1544 _LIBCPP_INLINE_VISIBILITY
1545 static void construct(allocator_type& __a, _Tp* __p)
1547 ::new ((void*)__p) _Tp();
1549 template <class _Tp, class _A0>
1550 _LIBCPP_INLINE_VISIBILITY
1551 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1553 ::new ((void*)__p) _Tp(__a0);
1555 template <class _Tp, class _A0, class _A1>
1556 _LIBCPP_INLINE_VISIBILITY
1557 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1560 ::new ((void*)__p) _Tp(__a0, __a1);
1562 template <class _Tp, class _A0, class _A1, class _A2>
1563 _LIBCPP_INLINE_VISIBILITY
1564 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1565 const _A1& __a1, const _A2& __a2)
1567 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1569 #endif // _LIBCPP_HAS_NO_VARIADICS
1571 template <class _Tp>
1572 _LIBCPP_INLINE_VISIBILITY
1573 static void destroy(allocator_type& __a, _Tp* __p)
1574 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1576 _LIBCPP_INLINE_VISIBILITY
1577 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1578 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1580 _LIBCPP_INLINE_VISIBILITY
1581 static allocator_type
1582 select_on_container_copy_construction(const allocator_type& __a)
1583 {return select_on_container_copy_construction(
1584 __has_select_on_container_copy_construction<const allocator_type>(),
1587 template <class _Ptr>
1588 _LIBCPP_INLINE_VISIBILITY
1591 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1593 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1594 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1597 template <class _Tp>
1598 _LIBCPP_INLINE_VISIBILITY
1602 (is_same<allocator_type, allocator<_Tp> >::value
1603 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1604 is_trivially_move_constructible<_Tp>::value,
1607 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1609 ptrdiff_t _Np = __end1 - __begin1;
1612 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1617 template <class _Iter, class _Ptr>
1618 _LIBCPP_INLINE_VISIBILITY
1621 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1623 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1624 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1627 template <class _Tp>
1628 _LIBCPP_INLINE_VISIBILITY
1632 (is_same<allocator_type, allocator<_Tp> >::value
1633 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1634 is_trivially_move_constructible<_Tp>::value,
1637 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1639 typedef typename remove_const<_Tp>::type _Vp;
1640 ptrdiff_t _Np = __end1 - __begin1;
1643 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1648 template <class _Ptr>
1649 _LIBCPP_INLINE_VISIBILITY
1652 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1654 while (__end1 != __begin1)
1656 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1661 template <class _Tp>
1662 _LIBCPP_INLINE_VISIBILITY
1666 (is_same<allocator_type, allocator<_Tp> >::value
1667 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1668 is_trivially_move_constructible<_Tp>::value,
1671 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1673 ptrdiff_t _Np = __end1 - __begin1;
1676 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1681 _LIBCPP_INLINE_VISIBILITY
1682 static pointer allocate(allocator_type& __a, size_type __n,
1683 const_void_pointer __hint, true_type)
1684 {return __a.allocate(__n, __hint);}
1685 _LIBCPP_INLINE_VISIBILITY
1686 static pointer allocate(allocator_type& __a, size_type __n,
1687 const_void_pointer, false_type)
1688 {return __a.allocate(__n);}
1690 #ifndef _LIBCPP_HAS_NO_VARIADICS
1691 template <class _Tp, class... _Args>
1692 _LIBCPP_INLINE_VISIBILITY
1693 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1694 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1695 template <class _Tp, class... _Args>
1696 _LIBCPP_INLINE_VISIBILITY
1697 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1699 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1701 #endif // _LIBCPP_HAS_NO_VARIADICS
1703 template <class _Tp>
1704 _LIBCPP_INLINE_VISIBILITY
1705 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1707 template <class _Tp>
1708 _LIBCPP_INLINE_VISIBILITY
1709 static void __destroy(false_type, allocator_type&, _Tp* __p)
1714 _LIBCPP_INLINE_VISIBILITY
1715 static size_type __max_size(true_type, const allocator_type& __a)
1716 {return __a.max_size();}
1717 _LIBCPP_INLINE_VISIBILITY
1718 static size_type __max_size(false_type, const allocator_type&)
1719 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1721 _LIBCPP_INLINE_VISIBILITY
1722 static allocator_type
1723 select_on_container_copy_construction(true_type, const allocator_type& __a)
1724 {return __a.select_on_container_copy_construction();}
1725 _LIBCPP_INLINE_VISIBILITY
1726 static allocator_type
1727 select_on_container_copy_construction(false_type, const allocator_type& __a)
1731 template <class _Traits, class _Tp>
1732 struct __rebind_alloc_helper
1734 #ifndef _LIBCPP_CXX03_LANG
1735 typedef typename _Traits::template rebind_alloc<_Tp> type;
1737 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1743 template <class _Tp>
1744 class _LIBCPP_TEMPLATE_VIS allocator
1747 typedef size_t size_type;
1748 typedef ptrdiff_t difference_type;
1749 typedef _Tp* pointer;
1750 typedef const _Tp* const_pointer;
1751 typedef _Tp& reference;
1752 typedef const _Tp& const_reference;
1753 typedef _Tp value_type;
1755 typedef true_type propagate_on_container_move_assignment;
1756 typedef true_type is_always_equal;
1758 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1760 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1761 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1762 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1763 {return _VSTD::addressof(__x);}
1764 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1765 {return _VSTD::addressof(__x);}
1766 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1768 if (__n > max_size())
1769 __throw_length_error("allocator<T>::allocate(size_t n)"
1770 " 'n' exceeds maximum supported size");
1771 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1773 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1774 {_VSTD::__libcpp_deallocate((void*)__p);}
1775 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1776 {return size_type(~0) / sizeof(_Tp);}
1777 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1778 template <class _Up, class... _Args>
1779 _LIBCPP_INLINE_VISIBILITY
1781 construct(_Up* __p, _Args&&... __args)
1783 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1785 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1786 _LIBCPP_INLINE_VISIBILITY
1788 construct(pointer __p)
1790 ::new((void*)__p) _Tp();
1792 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1794 template <class _A0>
1795 _LIBCPP_INLINE_VISIBILITY
1797 construct(pointer __p, _A0& __a0)
1799 ::new((void*)__p) _Tp(__a0);
1801 template <class _A0>
1802 _LIBCPP_INLINE_VISIBILITY
1804 construct(pointer __p, const _A0& __a0)
1806 ::new((void*)__p) _Tp(__a0);
1808 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1809 template <class _A0, class _A1>
1810 _LIBCPP_INLINE_VISIBILITY
1812 construct(pointer __p, _A0& __a0, _A1& __a1)
1814 ::new((void*)__p) _Tp(__a0, __a1);
1816 template <class _A0, class _A1>
1817 _LIBCPP_INLINE_VISIBILITY
1819 construct(pointer __p, const _A0& __a0, _A1& __a1)
1821 ::new((void*)__p) _Tp(__a0, __a1);
1823 template <class _A0, class _A1>
1824 _LIBCPP_INLINE_VISIBILITY
1826 construct(pointer __p, _A0& __a0, const _A1& __a1)
1828 ::new((void*)__p) _Tp(__a0, __a1);
1830 template <class _A0, class _A1>
1831 _LIBCPP_INLINE_VISIBILITY
1833 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1835 ::new((void*)__p) _Tp(__a0, __a1);
1837 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1838 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1841 template <class _Tp>
1842 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1845 typedef size_t size_type;
1846 typedef ptrdiff_t difference_type;
1847 typedef const _Tp* pointer;
1848 typedef const _Tp* const_pointer;
1849 typedef const _Tp& reference;
1850 typedef const _Tp& const_reference;
1851 typedef const _Tp value_type;
1853 typedef true_type propagate_on_container_move_assignment;
1854 typedef true_type is_always_equal;
1856 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1858 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1859 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1860 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1861 {return _VSTD::addressof(__x);}
1862 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1864 if (__n > max_size())
1865 __throw_length_error("allocator<const T>::allocate(size_t n)"
1866 " 'n' exceeds maximum supported size");
1867 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1869 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1870 {_VSTD::__libcpp_deallocate((void*)__p);}
1871 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1872 {return size_type(~0) / sizeof(_Tp);}
1873 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1874 template <class _Up, class... _Args>
1875 _LIBCPP_INLINE_VISIBILITY
1877 construct(_Up* __p, _Args&&... __args)
1879 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1881 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1882 _LIBCPP_INLINE_VISIBILITY
1884 construct(pointer __p)
1886 ::new((void*)__p) _Tp();
1888 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1890 template <class _A0>
1891 _LIBCPP_INLINE_VISIBILITY
1893 construct(pointer __p, _A0& __a0)
1895 ::new((void*)__p) _Tp(__a0);
1897 template <class _A0>
1898 _LIBCPP_INLINE_VISIBILITY
1900 construct(pointer __p, const _A0& __a0)
1902 ::new((void*)__p) _Tp(__a0);
1904 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1905 template <class _A0, class _A1>
1906 _LIBCPP_INLINE_VISIBILITY
1908 construct(pointer __p, _A0& __a0, _A1& __a1)
1910 ::new((void*)__p) _Tp(__a0, __a1);
1912 template <class _A0, class _A1>
1913 _LIBCPP_INLINE_VISIBILITY
1915 construct(pointer __p, const _A0& __a0, _A1& __a1)
1917 ::new((void*)__p) _Tp(__a0, __a1);
1919 template <class _A0, class _A1>
1920 _LIBCPP_INLINE_VISIBILITY
1922 construct(pointer __p, _A0& __a0, const _A1& __a1)
1924 ::new((void*)__p) _Tp(__a0, __a1);
1926 template <class _A0, class _A1>
1927 _LIBCPP_INLINE_VISIBILITY
1929 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1931 ::new((void*)__p) _Tp(__a0, __a1);
1933 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1934 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1937 template <class _Tp, class _Up>
1938 inline _LIBCPP_INLINE_VISIBILITY
1939 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1941 template <class _Tp, class _Up>
1942 inline _LIBCPP_INLINE_VISIBILITY
1943 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1945 template <class _OutputIterator, class _Tp>
1946 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1947 : public iterator<output_iterator_tag,
1948 _Tp, // purposefully not C++03
1949 ptrdiff_t, // purposefully not C++03
1950 _Tp*, // purposefully not C++03
1951 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1954 _OutputIterator __x_;
1956 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1957 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1958 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1959 {::new(&*__x_) _Tp(__element); return *this;}
1960 #if _LIBCPP_STD_VER >= 14
1961 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1962 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1964 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1965 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1966 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1967 #if _LIBCPP_STD_VER >= 14
1968 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1972 template <class _Tp>
1973 pair<_Tp*, ptrdiff_t>
1974 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1976 pair<_Tp*, ptrdiff_t> __r(0, 0);
1977 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1978 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1984 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1995 template <class _Tp>
1996 inline _LIBCPP_INLINE_VISIBILITY
1997 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1999 template <class _Tp>
2006 class _LIBCPP_TEMPLATE_VIS auto_ptr
2011 typedef _Tp element_type;
2013 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2014 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2015 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2016 : __ptr_(__p.release()) {}
2017 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2018 {reset(__p.release()); return *this;}
2019 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2020 {reset(__p.release()); return *this;}
2021 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2022 {reset(__p.__ptr_); return *this;}
2023 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2025 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2027 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2028 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2029 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2035 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2042 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2043 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2044 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2045 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2046 {return auto_ptr<_Up>(release());}
2050 class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
2053 typedef void element_type;
2056 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
2057 typename remove_cv<_T2>::type>::value,
2058 bool = is_empty<_T1>::value
2059 && !__libcpp_is_final<_T1>::value,
2060 bool = is_empty<_T2>::value
2061 && !__libcpp_is_final<_T2>::value
2063 struct __libcpp_compressed_pair_switch;
2065 template <class _T1, class _T2, bool IsSame>
2066 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2068 template <class _T1, class _T2, bool IsSame>
2069 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2071 template <class _T1, class _T2, bool IsSame>
2072 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2074 template <class _T1, class _T2>
2075 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2077 template <class _T1, class _T2>
2078 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2080 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2081 class __libcpp_compressed_pair_imp;
2083 template <class _T1, class _T2>
2084 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2090 typedef _T1 _T1_param;
2091 typedef _T2 _T2_param;
2093 typedef typename remove_reference<_T1>::type& _T1_reference;
2094 typedef typename remove_reference<_T2>::type& _T2_reference;
2096 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2097 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2099 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
2100 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2101 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2102 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2103 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2104 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2105 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2107 #ifndef _LIBCPP_HAS_NO_VARIADICS
2109 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2110 _LIBCPP_INLINE_VISIBILITY
2111 __libcpp_compressed_pair_imp(piecewise_construct_t,
2112 tuple<_Args1...> __first_args,
2113 tuple<_Args2...> __second_args,
2114 __tuple_indices<_I1...>,
2115 __tuple_indices<_I2...>)
2116 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2117 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2120 #endif // _LIBCPP_HAS_NO_VARIADICS
2122 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2123 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2125 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2126 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2128 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2129 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2130 __is_nothrow_swappable<_T2>::value)
2133 swap(__first_, __x.__first_);
2134 swap(__second_, __x.__second_);
2138 template <class _T1, class _T2>
2139 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2145 typedef _T1 _T1_param;
2146 typedef _T2 _T2_param;
2148 typedef _T1& _T1_reference;
2149 typedef typename remove_reference<_T2>::type& _T2_reference;
2151 typedef const _T1& _T1_const_reference;
2152 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2154 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
2155 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2156 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2157 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2158 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2159 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2160 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2162 #ifndef _LIBCPP_HAS_NO_VARIADICS
2164 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2165 _LIBCPP_INLINE_VISIBILITY
2166 __libcpp_compressed_pair_imp(piecewise_construct_t,
2167 tuple<_Args1...> __first_args,
2168 tuple<_Args2...> __second_args,
2169 __tuple_indices<_I1...>,
2170 __tuple_indices<_I2...>)
2171 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2172 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2175 #endif // _LIBCPP_HAS_NO_VARIADICS
2177 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2178 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2180 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2181 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2183 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2184 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2185 __is_nothrow_swappable<_T2>::value)
2188 swap(__second_, __x.__second_);
2192 template <class _T1, class _T2>
2193 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2199 typedef _T1 _T1_param;
2200 typedef _T2 _T2_param;
2202 typedef typename remove_reference<_T1>::type& _T1_reference;
2203 typedef _T2& _T2_reference;
2205 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2206 typedef const _T2& _T2_const_reference;
2208 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
2209 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2210 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2211 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2212 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
2213 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2214 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2215 is_nothrow_move_constructible<_T2>::value)
2216 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2218 #ifndef _LIBCPP_HAS_NO_VARIADICS
2220 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2221 _LIBCPP_INLINE_VISIBILITY
2222 __libcpp_compressed_pair_imp(piecewise_construct_t,
2223 tuple<_Args1...> __first_args,
2224 tuple<_Args2...> __second_args,
2225 __tuple_indices<_I1...>,
2226 __tuple_indices<_I2...>)
2227 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2228 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2232 #endif // _LIBCPP_HAS_NO_VARIADICS
2234 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2235 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2237 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2238 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2240 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2241 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2242 __is_nothrow_swappable<_T2>::value)
2245 swap(__first_, __x.__first_);
2249 template <class _T1, class _T2>
2250 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2255 typedef _T1 _T1_param;
2256 typedef _T2 _T2_param;
2258 typedef _T1& _T1_reference;
2259 typedef _T2& _T2_reference;
2261 typedef const _T1& _T1_const_reference;
2262 typedef const _T2& _T2_const_reference;
2264 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2265 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2266 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2267 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2268 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2269 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2270 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2272 #ifndef _LIBCPP_HAS_NO_VARIADICS
2274 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2275 _LIBCPP_INLINE_VISIBILITY
2276 __libcpp_compressed_pair_imp(piecewise_construct_t,
2277 tuple<_Args1...> __first_args,
2278 tuple<_Args2...> __second_args,
2279 __tuple_indices<_I1...>,
2280 __tuple_indices<_I2...>)
2281 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2282 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2285 #endif // _LIBCPP_HAS_NO_VARIADICS
2287 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2288 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2290 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2291 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2293 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2294 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2295 __is_nothrow_swappable<_T2>::value)
2300 template <class _T1, class _T2>
2301 class __compressed_pair
2302 : private __libcpp_compressed_pair_imp<_T1, _T2>
2304 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2306 typedef typename base::_T1_param _T1_param;
2307 typedef typename base::_T2_param _T2_param;
2309 typedef typename base::_T1_reference _T1_reference;
2310 typedef typename base::_T2_reference _T2_reference;
2312 typedef typename base::_T1_const_reference _T1_const_reference;
2313 typedef typename base::_T2_const_reference _T2_const_reference;
2315 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2316 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2317 : base(_VSTD::forward<_T1_param>(__t1)) {}
2318 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2319 : base(_VSTD::forward<_T2_param>(__t2)) {}
2320 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2321 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2323 #ifndef _LIBCPP_HAS_NO_VARIADICS
2325 template <class... _Args1, class... _Args2>
2326 _LIBCPP_INLINE_VISIBILITY
2327 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2328 tuple<_Args2...> __second_args)
2329 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2330 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2331 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2334 #endif // _LIBCPP_HAS_NO_VARIADICS
2336 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2337 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2339 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2340 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2342 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2343 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2344 __is_nothrow_swappable<_T2>::value)
2348 template <class _T1, class _T2>
2349 inline _LIBCPP_INLINE_VISIBILITY
2351 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2352 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2353 __is_nothrow_swappable<_T2>::value)
2356 // __same_or_less_cv_qualified
2358 template <class _Ptr1, class _Ptr2,
2359 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2360 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2363 struct __same_or_less_cv_qualified_imp
2364 : is_convertible<_Ptr1, _Ptr2> {};
2366 template <class _Ptr1, class _Ptr2>
2367 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2370 template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2371 is_same<_Ptr1, _Ptr2>::value ||
2372 __has_element_type<_Ptr1>::value>
2373 struct __same_or_less_cv_qualified
2374 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2376 template <class _Ptr1, class _Ptr2>
2377 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2382 template <class _Tp>
2383 struct _LIBCPP_TEMPLATE_VIS default_delete
2385 #ifndef _LIBCPP_CXX03_LANG
2386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2388 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2390 template <class _Up>
2391 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2392 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2393 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2395 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2396 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2401 template <class _Tp>
2402 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]>
2405 #ifndef _LIBCPP_CXX03_LANG
2406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2410 template <class _Up>
2411 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2412 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2413 template <class _Up>
2414 _LIBCPP_INLINE_VISIBILITY
2415 void operator() (_Up* __ptr,
2416 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2418 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2419 static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
2424 template <class _Tp, class _Dp = default_delete<_Tp> >
2425 class _LIBCPP_TEMPLATE_VIS unique_ptr
2428 typedef _Tp element_type;
2429 typedef _Dp deleter_type;
2430 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2432 __compressed_pair<pointer, deleter_type> __ptr_;
2434 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2435 unique_ptr(unique_ptr&);
2436 template <class _Up, class _Ep>
2437 unique_ptr(unique_ptr<_Up, _Ep>&);
2438 unique_ptr& operator=(unique_ptr&);
2439 template <class _Up, class _Ep>
2440 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2441 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2443 struct __nat {int __for_bool_;};
2445 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2446 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2448 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2451 static_assert(!is_pointer<deleter_type>::value,
2452 "unique_ptr constructed with null function pointer deleter");
2454 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2457 static_assert(!is_pointer<deleter_type>::value,
2458 "unique_ptr constructed with null function pointer deleter");
2460 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2461 : __ptr_(_VSTD::move(__p))
2463 static_assert(!is_pointer<deleter_type>::value,
2464 "unique_ptr constructed with null function pointer deleter");
2467 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2468 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2469 is_reference<deleter_type>::value,
2471 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2473 : __ptr_(__p, __d) {}
2475 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2477 : __ptr_(__p, _VSTD::move(__d))
2479 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2481 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2482 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2483 template <class _Up, class _Ep>
2484 _LIBCPP_INLINE_VISIBILITY
2485 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2488 !is_array<_Up>::value &&
2489 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2490 is_convertible<_Ep, deleter_type>::value &&
2492 !is_reference<deleter_type>::value ||
2493 is_same<deleter_type, _Ep>::value
2496 >::type = __nat()) _NOEXCEPT
2497 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2499 template <class _Up>
2500 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2502 is_convertible<_Up*, _Tp*>::value &&
2503 is_same<_Dp, default_delete<_Tp> >::value,
2505 >::type = __nat()) _NOEXCEPT
2506 : __ptr_(__p.release())
2510 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2512 reset(__u.release());
2513 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2517 template <class _Up, class _Ep>
2518 _LIBCPP_INLINE_VISIBILITY
2521 !is_array<_Up>::value &&
2522 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2523 is_assignable<deleter_type&, _Ep&&>::value,
2526 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2528 reset(__u.release());
2529 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2532 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2534 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2536 return __rv<unique_ptr>(*this);
2539 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2540 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2542 template <class _Up, class _Ep>
2543 _LIBCPP_INLINE_VISIBILITY
2545 !is_array<_Up>::value &&
2546 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2547 is_assignable<deleter_type&, _Ep&>::value,
2550 operator=(unique_ptr<_Up, _Ep> __u)
2552 reset(__u.release());
2553 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2557 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2558 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2560 template <class _Up>
2561 _LIBCPP_INLINE_VISIBILITY
2563 is_convertible<_Up*, _Tp*>::value &&
2564 is_same<_Dp, default_delete<_Tp> >::value,
2567 operator=(auto_ptr<_Up> __p)
2568 {reset(__p.release()); return *this;}
2570 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2571 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2573 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2579 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2580 {return *__ptr_.first();}
2581 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2582 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2583 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2584 {return __ptr_.second();}
2585 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2586 {return __ptr_.second();}
2587 _LIBCPP_INLINE_VISIBILITY
2588 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2589 {return __ptr_.first() != nullptr;}
2591 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2593 pointer __t = __ptr_.first();
2594 __ptr_.first() = pointer();
2598 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2600 pointer __tmp = __ptr_.first();
2601 __ptr_.first() = __p;
2603 __ptr_.second()(__tmp);
2606 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2607 {__ptr_.swap(__u.__ptr_);}
2610 template <class _Tp, class _Dp>
2611 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
2614 typedef _Tp element_type;
2615 typedef _Dp deleter_type;
2616 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2618 __compressed_pair<pointer, deleter_type> __ptr_;
2620 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2621 unique_ptr(unique_ptr&);
2622 template <class _Up>
2623 unique_ptr(unique_ptr<_Up>&);
2624 unique_ptr& operator=(unique_ptr&);
2625 template <class _Up>
2626 unique_ptr& operator=(unique_ptr<_Up>&);
2627 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2629 struct __nat {int __for_bool_;};
2631 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2632 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2634 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2637 static_assert(!is_pointer<deleter_type>::value,
2638 "unique_ptr constructed with null function pointer deleter");
2640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2643 static_assert(!is_pointer<deleter_type>::value,
2644 "unique_ptr constructed with null function pointer deleter");
2646 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2647 template <class _Pp>
2648 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2649 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
2652 static_assert(!is_pointer<deleter_type>::value,
2653 "unique_ptr constructed with null function pointer deleter");
2656 template <class _Pp>
2657 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2658 is_reference<deleter_type>::value,
2660 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2661 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2663 : __ptr_(__p, __d) {}
2665 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2666 is_reference<deleter_type>::value,
2668 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2670 : __ptr_(pointer(), __d) {}
2672 template <class _Pp>
2673 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2674 typename remove_reference<deleter_type>::type&& __d,
2675 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2677 : __ptr_(__p, _VSTD::move(__d))
2679 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2682 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2684 : __ptr_(pointer(), _VSTD::move(__d))
2686 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2689 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2690 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2692 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2694 reset(__u.release());
2695 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2699 template <class _Up, class _Ep>
2700 _LIBCPP_INLINE_VISIBILITY
2701 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2704 is_array<_Up>::value &&
2705 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2706 && is_convertible<_Ep, deleter_type>::value &&
2708 !is_reference<deleter_type>::value ||
2709 is_same<deleter_type, _Ep>::value
2714 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2717 template <class _Up, class _Ep>
2718 _LIBCPP_INLINE_VISIBILITY
2721 is_array<_Up>::value &&
2722 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2723 is_assignable<deleter_type&, _Ep&&>::value,
2726 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2728 reset(__u.release());
2729 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2732 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2734 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2737 static_assert(!is_pointer<deleter_type>::value,
2738 "unique_ptr constructed with null function pointer deleter");
2741 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2742 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2744 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2745 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2747 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2749 return __rv<unique_ptr>(*this);
2752 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2753 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2755 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2757 reset(__u->release());
2758 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2762 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2763 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2765 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2771 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2772 {return __ptr_.first()[__i];}
2773 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2774 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2775 {return __ptr_.second();}
2776 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2777 {return __ptr_.second();}
2778 _LIBCPP_INLINE_VISIBILITY
2779 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2780 {return __ptr_.first() != nullptr;}
2782 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2784 pointer __t = __ptr_.first();
2785 __ptr_.first() = pointer();
2789 template <class _Pp>
2790 _LIBCPP_INLINE_VISIBILITY
2791 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2792 reset(_Pp __p) _NOEXCEPT
2794 pointer __tmp = __ptr_.first();
2795 __ptr_.first() = __p;
2797 __ptr_.second()(__tmp);
2799 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
2801 pointer __tmp = __ptr_.first();
2802 __ptr_.first() = nullptr;
2804 __ptr_.second()(__tmp);
2807 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2810 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2811 template <class _Up>
2812 explicit unique_ptr(_Up);
2813 template <class _Up>
2815 typename conditional<
2816 is_reference<deleter_type>::value,
2818 typename add_lvalue_reference<const deleter_type>::type>::type,
2821 is_convertible<_Up, pointer>::value,
2824 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2827 template <class _Tp, class _Dp>
2828 inline _LIBCPP_INLINE_VISIBILITY
2830 __is_swappable<_Dp>::value,
2833 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2835 template <class _T1, class _D1, class _T2, class _D2>
2836 inline _LIBCPP_INLINE_VISIBILITY
2838 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2840 template <class _T1, class _D1, class _T2, class _D2>
2841 inline _LIBCPP_INLINE_VISIBILITY
2843 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2845 template <class _T1, class _D1, class _T2, class _D2>
2846 inline _LIBCPP_INLINE_VISIBILITY
2848 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2850 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2851 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2852 typedef typename common_type<_P1, _P2>::type _Vp;
2853 return less<_Vp>()(__x.get(), __y.get());
2856 template <class _T1, class _D1, class _T2, class _D2>
2857 inline _LIBCPP_INLINE_VISIBILITY
2859 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2861 template <class _T1, class _D1, class _T2, class _D2>
2862 inline _LIBCPP_INLINE_VISIBILITY
2864 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2866 template <class _T1, class _D1, class _T2, class _D2>
2867 inline _LIBCPP_INLINE_VISIBILITY
2869 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2871 template <class _T1, class _D1>
2872 inline _LIBCPP_INLINE_VISIBILITY
2874 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2879 template <class _T1, class _D1>
2880 inline _LIBCPP_INLINE_VISIBILITY
2882 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2887 template <class _T1, class _D1>
2888 inline _LIBCPP_INLINE_VISIBILITY
2890 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2892 return static_cast<bool>(__x);
2895 template <class _T1, class _D1>
2896 inline _LIBCPP_INLINE_VISIBILITY
2898 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2900 return static_cast<bool>(__x);
2903 template <class _T1, class _D1>
2904 inline _LIBCPP_INLINE_VISIBILITY
2906 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2908 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2909 return less<_P1>()(__x.get(), nullptr);
2912 template <class _T1, class _D1>
2913 inline _LIBCPP_INLINE_VISIBILITY
2915 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2917 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2918 return less<_P1>()(nullptr, __x.get());
2921 template <class _T1, class _D1>
2922 inline _LIBCPP_INLINE_VISIBILITY
2924 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2926 return nullptr < __x;
2929 template <class _T1, class _D1>
2930 inline _LIBCPP_INLINE_VISIBILITY
2932 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2934 return __x < nullptr;
2937 template <class _T1, class _D1>
2938 inline _LIBCPP_INLINE_VISIBILITY
2940 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2942 return !(nullptr < __x);
2945 template <class _T1, class _D1>
2946 inline _LIBCPP_INLINE_VISIBILITY
2948 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2950 return !(__x < nullptr);
2953 template <class _T1, class _D1>
2954 inline _LIBCPP_INLINE_VISIBILITY
2956 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2958 return !(__x < nullptr);
2961 template <class _T1, class _D1>
2962 inline _LIBCPP_INLINE_VISIBILITY
2964 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2966 return !(nullptr < __x);
2969 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2971 template <class _Tp, class _Dp>
2972 inline _LIBCPP_INLINE_VISIBILITY
2973 unique_ptr<_Tp, _Dp>
2974 move(unique_ptr<_Tp, _Dp>& __t)
2976 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
2981 #if _LIBCPP_STD_VER > 11
2986 typedef unique_ptr<_Tp> __unique_single;
2990 struct __unique_if<_Tp[]>
2992 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
2995 template<class _Tp, size_t _Np>
2996 struct __unique_if<_Tp[_Np]>
2998 typedef void __unique_array_known_bound;
3001 template<class _Tp, class... _Args>
3002 inline _LIBCPP_INLINE_VISIBILITY
3003 typename __unique_if<_Tp>::__unique_single
3004 make_unique(_Args&&... __args)
3006 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3010 inline _LIBCPP_INLINE_VISIBILITY
3011 typename __unique_if<_Tp>::__unique_array_unknown_bound
3012 make_unique(size_t __n)
3014 typedef typename remove_extent<_Tp>::type _Up;
3015 return unique_ptr<_Tp>(new _Up[__n]());
3018 template<class _Tp, class... _Args>
3019 typename __unique_if<_Tp>::__unique_array_known_bound
3020 make_unique(_Args&&...) = delete;
3022 #endif // _LIBCPP_STD_VER > 11
3024 template <class _Size>
3025 inline _LIBCPP_INLINE_VISIBILITY
3027 __loadword(const void* __p)
3030 std::memcpy(&__r, __p, sizeof(__r));
3034 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3035 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3036 // multiplication, which can be very slow on 32-bit systems.
3037 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3038 struct __murmur2_or_cityhash;
3040 template <class _Size>
3041 struct __murmur2_or_cityhash<_Size, 32>
3043 _Size operator()(const void* __key, _Size __len);
3047 template <class _Size>
3049 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
3051 const _Size __m = 0x5bd1e995;
3052 const _Size __r = 24;
3054 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3055 for (; __len >= 4; __data += 4, __len -= 4)
3057 _Size __k = __loadword<_Size>(__data);
3067 __h ^= __data[2] << 16;
3069 __h ^= __data[1] << 8;
3080 template <class _Size>
3081 struct __murmur2_or_cityhash<_Size, 64>
3083 _Size operator()(const void* __key, _Size __len);
3086 // Some primes between 2^63 and 2^64.
3087 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3088 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3089 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3090 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3092 static _Size __rotate(_Size __val, int __shift) {
3093 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3096 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3097 return (__val >> __shift) | (__val << (64 - __shift));
3100 static _Size __shift_mix(_Size __val) {
3101 return __val ^ (__val >> 47);
3104 static _Size __hash_len_16(_Size __u, _Size __v) {
3105 const _Size __mul = 0x9ddfea08eb382d69ULL;
3106 _Size __a = (__u ^ __v) * __mul;
3108 _Size __b = (__v ^ __a) * __mul;
3114 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3116 const _Size __a = __loadword<_Size>(__s);
3117 const _Size __b = __loadword<_Size>(__s + __len - 8);
3118 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3121 const uint32_t __a = __loadword<uint32_t>(__s);
3122 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3123 return __hash_len_16(__len + (__a << 3), __b);
3126 const unsigned char __a = __s[0];
3127 const unsigned char __b = __s[__len >> 1];
3128 const unsigned char __c = __s[__len - 1];
3129 const uint32_t __y = static_cast<uint32_t>(__a) +
3130 (static_cast<uint32_t>(__b) << 8);
3131 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3132 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3137 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3138 const _Size __a = __loadword<_Size>(__s) * __k1;
3139 const _Size __b = __loadword<_Size>(__s + 8);
3140 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3141 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3142 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3143 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3146 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3147 // Callers do best to use "random-looking" values for a and b.
3148 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3149 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3151 __b = __rotate(__b + __a + __z, 21);
3152 const _Size __c = __a;
3155 __b += __rotate(__a, 44);
3156 return pair<_Size, _Size>(__a + __z, __b + __c);
3159 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3160 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3161 const char* __s, _Size __a, _Size __b) {
3162 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3163 __loadword<_Size>(__s + 8),
3164 __loadword<_Size>(__s + 16),
3165 __loadword<_Size>(__s + 24),
3170 // Return an 8-byte hash for 33 to 64 bytes.
3171 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3172 _Size __z = __loadword<_Size>(__s + 24);
3173 _Size __a = __loadword<_Size>(__s) +
3174 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3175 _Size __b = __rotate(__a + __z, 52);
3176 _Size __c = __rotate(__a, 37);
3177 __a += __loadword<_Size>(__s + 8);
3178 __c += __rotate(__a, 7);
3179 __a += __loadword<_Size>(__s + 16);
3180 _Size __vf = __a + __z;
3181 _Size __vs = __b + __rotate(__a, 31) + __c;
3182 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3183 __z += __loadword<_Size>(__s + __len - 8);
3184 __b = __rotate(__a + __z, 52);
3185 __c = __rotate(__a, 37);
3186 __a += __loadword<_Size>(__s + __len - 24);
3187 __c += __rotate(__a, 7);
3188 __a += __loadword<_Size>(__s + __len - 16);
3189 _Size __wf = __a + __z;
3190 _Size __ws = __b + __rotate(__a, 31) + __c;
3191 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3192 return __shift_mix(__r * __k0 + __vs) * __k2;
3197 template <class _Size>
3199 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
3201 const char* __s = static_cast<const char*>(__key);
3204 return __hash_len_0_to_16(__s, __len);
3206 return __hash_len_17_to_32(__s, __len);
3208 } else if (__len <= 64) {
3209 return __hash_len_33_to_64(__s, __len);
3212 // For strings over 64 bytes we hash the end first, and then as we
3213 // loop we keep 56 bytes of state: v, w, x, y, and z.
3214 _Size __x = __loadword<_Size>(__s + __len - 40);
3215 _Size __y = __loadword<_Size>(__s + __len - 16) +
3216 __loadword<_Size>(__s + __len - 56);
3217 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3218 __loadword<_Size>(__s + __len - 24));
3219 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3220 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3221 __x = __x * __k1 + __loadword<_Size>(__s);
3223 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3224 __len = (__len - 1) & ~static_cast<_Size>(63);
3226 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3227 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3229 __y += __v.first + __loadword<_Size>(__s + 40);
3230 __z = __rotate(__z + __w.first, 33) * __k1;
3231 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3232 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3233 __y + __loadword<_Size>(__s + 16));
3234 std::swap(__z, __x);
3237 } while (__len != 0);
3238 return __hash_len_16(
3239 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3240 __hash_len_16(__v.second, __w.second) + __x);
3243 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3244 struct __scalar_hash;
3246 template <class _Tp>
3247 struct __scalar_hash<_Tp, 0>
3248 : public unary_function<_Tp, size_t>
3250 _LIBCPP_INLINE_VISIBILITY
3251 size_t operator()(_Tp __v) const _NOEXCEPT
3264 template <class _Tp>
3265 struct __scalar_hash<_Tp, 1>
3266 : public unary_function<_Tp, size_t>
3268 _LIBCPP_INLINE_VISIBILITY
3269 size_t operator()(_Tp __v) const _NOEXCEPT
3281 template <class _Tp>
3282 struct __scalar_hash<_Tp, 2>
3283 : public unary_function<_Tp, size_t>
3285 _LIBCPP_INLINE_VISIBILITY
3286 size_t operator()(_Tp __v) const _NOEXCEPT
3298 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3302 template <class _Tp>
3303 struct __scalar_hash<_Tp, 3>
3304 : public unary_function<_Tp, size_t>
3306 _LIBCPP_INLINE_VISIBILITY
3307 size_t operator()(_Tp __v) const _NOEXCEPT
3320 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3324 template <class _Tp>
3325 struct __scalar_hash<_Tp, 4>
3326 : public unary_function<_Tp, size_t>
3328 _LIBCPP_INLINE_VISIBILITY
3329 size_t operator()(_Tp __v) const _NOEXCEPT
3343 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3352 _LIBCPP_INLINE_VISIBILITY
3353 inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
3354 typedef __scalar_hash<_PairT> _HashT;
3355 const _PairT __p = {__lhs, __rhs};
3356 return _HashT()(__p);
3360 struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
3361 : public unary_function<_Tp*, size_t>
3363 _LIBCPP_INLINE_VISIBILITY
3364 size_t operator()(_Tp* __v) const _NOEXCEPT
3372 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3376 template <class _Tp, class _Dp>
3377 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3379 typedef unique_ptr<_Tp, _Dp> argument_type;
3380 typedef size_t result_type;
3381 _LIBCPP_INLINE_VISIBILITY
3382 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3384 typedef typename argument_type::pointer pointer;
3385 return hash<pointer>()(__ptr.get());
3394 template <class _Tp>
3395 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3396 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3398 template <class _Tp>
3399 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3402 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3404 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3407 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3409 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3412 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3415 template <class _Tp>
3416 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3417 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3419 template <class _Tp>
3420 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3421 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3423 template <class _Tp>
3424 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3425 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3428 template <class _Alloc>
3429 class __allocator_destructor
3431 typedef allocator_traits<_Alloc> __alloc_traits;
3433 typedef typename __alloc_traits::pointer pointer;
3434 typedef typename __alloc_traits::size_type size_type;
3439 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3441 : __alloc_(__a), __s_(__s) {}
3442 _LIBCPP_INLINE_VISIBILITY
3443 void operator()(pointer __p) _NOEXCEPT
3444 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3447 template <class _InputIterator, class _ForwardIterator>
3449 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3451 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3452 #ifndef _LIBCPP_NO_EXCEPTIONS
3453 _ForwardIterator __s = __r;
3457 for (; __f != __l; ++__f, (void) ++__r)
3458 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3459 #ifndef _LIBCPP_NO_EXCEPTIONS
3463 for (; __s != __r; ++__s)
3471 template <class _InputIterator, class _Size, class _ForwardIterator>
3473 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3475 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3476 #ifndef _LIBCPP_NO_EXCEPTIONS
3477 _ForwardIterator __s = __r;
3481 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3482 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3483 #ifndef _LIBCPP_NO_EXCEPTIONS
3487 for (; __s != __r; ++__s)
3495 template <class _ForwardIterator, class _Tp>
3497 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3499 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3500 #ifndef _LIBCPP_NO_EXCEPTIONS
3501 _ForwardIterator __s = __f;
3505 for (; __f != __l; ++__f)
3506 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3507 #ifndef _LIBCPP_NO_EXCEPTIONS
3511 for (; __s != __f; ++__s)
3518 template <class _ForwardIterator, class _Size, class _Tp>
3520 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3522 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3523 #ifndef _LIBCPP_NO_EXCEPTIONS
3524 _ForwardIterator __s = __f;
3528 for (; __n > 0; ++__f, (void) --__n)
3529 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3530 #ifndef _LIBCPP_NO_EXCEPTIONS
3534 for (; __s != __f; ++__s)
3542 #if _LIBCPP_STD_VER > 14
3544 template <class _Tp>
3545 inline _LIBCPP_INLINE_VISIBILITY
3546 void destroy_at(_Tp* __loc) {
3547 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3551 template <class _ForwardIterator>
3552 inline _LIBCPP_INLINE_VISIBILITY
3553 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3554 for (; __first != __last; ++__first)
3555 _VSTD::destroy_at(_VSTD::addressof(*__first));
3558 template <class _ForwardIterator, class _Size>
3559 inline _LIBCPP_INLINE_VISIBILITY
3560 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3561 for (; __n > 0; (void)++__first, --__n)
3562 _VSTD::destroy_at(_VSTD::addressof(*__first));
3566 template <class _ForwardIterator>
3567 inline _LIBCPP_INLINE_VISIBILITY
3568 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3569 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3570 auto __idx = __first;
3571 #ifndef _LIBCPP_NO_EXCEPTIONS
3574 for (; __idx != __last; ++__idx)
3575 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3576 #ifndef _LIBCPP_NO_EXCEPTIONS
3578 _VSTD::destroy(__first, __idx);
3584 template <class _ForwardIterator, class _Size>
3585 inline _LIBCPP_INLINE_VISIBILITY
3586 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3587 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3588 auto __idx = __first;
3589 #ifndef _LIBCPP_NO_EXCEPTIONS
3592 for (; __n > 0; (void)++__idx, --__n)
3593 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3595 #ifndef _LIBCPP_NO_EXCEPTIONS
3597 _VSTD::destroy(__first, __idx);
3604 template <class _ForwardIterator>
3605 inline _LIBCPP_INLINE_VISIBILITY
3606 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3607 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3608 auto __idx = __first;
3609 #ifndef _LIBCPP_NO_EXCEPTIONS
3612 for (; __idx != __last; ++__idx)
3613 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3614 #ifndef _LIBCPP_NO_EXCEPTIONS
3616 _VSTD::destroy(__first, __idx);
3622 template <class _ForwardIterator, class _Size>
3623 inline _LIBCPP_INLINE_VISIBILITY
3624 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3625 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3626 auto __idx = __first;
3627 #ifndef _LIBCPP_NO_EXCEPTIONS
3630 for (; __n > 0; (void)++__idx, --__n)
3631 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3633 #ifndef _LIBCPP_NO_EXCEPTIONS
3635 _VSTD::destroy(__first, __idx);
3642 template <class _InputIt, class _ForwardIt>
3643 inline _LIBCPP_INLINE_VISIBILITY
3644 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3645 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3646 auto __idx = __first_res;
3647 #ifndef _LIBCPP_NO_EXCEPTIONS
3650 for (; __first != __last; (void)++__idx, ++__first)
3651 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3653 #ifndef _LIBCPP_NO_EXCEPTIONS
3655 _VSTD::destroy(__first_res, __idx);
3661 template <class _InputIt, class _Size, class _ForwardIt>
3662 inline _LIBCPP_INLINE_VISIBILITY
3663 pair<_InputIt, _ForwardIt>
3664 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3665 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3666 auto __idx = __first_res;
3667 #ifndef _LIBCPP_NO_EXCEPTIONS
3670 for (; __n > 0; ++__idx, (void)++__first, --__n)
3671 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3672 return {__first, __idx};
3673 #ifndef _LIBCPP_NO_EXCEPTIONS
3675 _VSTD::destroy(__first_res, __idx);
3682 #endif // _LIBCPP_STD_VER > 14
3684 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3685 : public std::exception
3688 virtual ~bad_weak_ptr() _NOEXCEPT;
3689 virtual const char* what() const _NOEXCEPT;
3692 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3693 void __throw_bad_weak_ptr()
3695 #ifndef _LIBCPP_NO_EXCEPTIONS
3696 throw bad_weak_ptr();
3702 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3704 class _LIBCPP_TYPE_VIS __shared_count
3706 __shared_count(const __shared_count&);
3707 __shared_count& operator=(const __shared_count&);
3710 long __shared_owners_;
3711 virtual ~__shared_count();
3713 virtual void __on_zero_shared() _NOEXCEPT = 0;
3716 _LIBCPP_INLINE_VISIBILITY
3717 explicit __shared_count(long __refs = 0) _NOEXCEPT
3718 : __shared_owners_(__refs) {}
3720 void __add_shared() _NOEXCEPT;
3721 bool __release_shared() _NOEXCEPT;
3722 _LIBCPP_INLINE_VISIBILITY
3723 long use_count() const _NOEXCEPT {
3724 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3728 class _LIBCPP_TYPE_VIS __shared_weak_count
3729 : private __shared_count
3731 long __shared_weak_owners_;
3734 _LIBCPP_INLINE_VISIBILITY
3735 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3736 : __shared_count(__refs),
3737 __shared_weak_owners_(__refs) {}
3739 virtual ~__shared_weak_count();
3742 void __add_shared() _NOEXCEPT;
3743 void __add_weak() _NOEXCEPT;
3744 void __release_shared() _NOEXCEPT;
3745 void __release_weak() _NOEXCEPT;
3746 _LIBCPP_INLINE_VISIBILITY
3747 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3748 __shared_weak_count* lock() _NOEXCEPT;
3750 // Define the function out only if we build static libc++ without RTTI.
3751 // Otherwise we may break clients who need to compile their projects with
3752 // -fno-rtti and yet link against a libc++.dylib compiled
3753 // without -fno-rtti.
3754 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3755 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3758 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3761 template <class _Tp, class _Dp, class _Alloc>
3762 class __shared_ptr_pointer
3763 : public __shared_weak_count
3765 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3767 _LIBCPP_INLINE_VISIBILITY
3768 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3769 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3771 #ifndef _LIBCPP_NO_RTTI
3772 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3776 virtual void __on_zero_shared() _NOEXCEPT;
3777 virtual void __on_zero_shared_weak() _NOEXCEPT;
3780 #ifndef _LIBCPP_NO_RTTI
3782 template <class _Tp, class _Dp, class _Alloc>
3784 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3786 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
3789 #endif // _LIBCPP_NO_RTTI
3791 template <class _Tp, class _Dp, class _Alloc>
3793 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3795 __data_.first().second()(__data_.first().first());
3796 __data_.first().second().~_Dp();
3799 template <class _Tp, class _Dp, class _Alloc>
3801 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3803 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3804 typedef allocator_traits<_Al> _ATraits;
3805 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3807 _Al __a(__data_.second());
3808 __data_.second().~_Alloc();
3809 __a.deallocate(_PTraits::pointer_to(*this), 1);
3812 template <class _Tp, class _Alloc>
3813 class __shared_ptr_emplace
3814 : public __shared_weak_count
3816 __compressed_pair<_Alloc, _Tp> __data_;
3818 #ifndef _LIBCPP_HAS_NO_VARIADICS
3820 _LIBCPP_INLINE_VISIBILITY
3821 __shared_ptr_emplace(_Alloc __a)
3822 : __data_(_VSTD::move(__a)) {}
3824 template <class ..._Args>
3825 _LIBCPP_INLINE_VISIBILITY
3826 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3827 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3828 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3830 #else // _LIBCPP_HAS_NO_VARIADICS
3832 _LIBCPP_INLINE_VISIBILITY
3833 __shared_ptr_emplace(_Alloc __a)
3836 template <class _A0>
3837 _LIBCPP_INLINE_VISIBILITY
3838 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3839 : __data_(__a, _Tp(__a0)) {}
3841 template <class _A0, class _A1>
3842 _LIBCPP_INLINE_VISIBILITY
3843 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3844 : __data_(__a, _Tp(__a0, __a1)) {}
3846 template <class _A0, class _A1, class _A2>
3847 _LIBCPP_INLINE_VISIBILITY
3848 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3849 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3851 #endif // _LIBCPP_HAS_NO_VARIADICS
3854 virtual void __on_zero_shared() _NOEXCEPT;
3855 virtual void __on_zero_shared_weak() _NOEXCEPT;
3857 _LIBCPP_INLINE_VISIBILITY
3858 _Tp* get() _NOEXCEPT {return &__data_.second();}
3861 template <class _Tp, class _Alloc>
3863 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3865 __data_.second().~_Tp();
3868 template <class _Tp, class _Alloc>
3870 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3872 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3873 typedef allocator_traits<_Al> _ATraits;
3874 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3875 _Al __a(__data_.first());
3876 __data_.first().~_Alloc();
3877 __a.deallocate(_PTraits::pointer_to(*this), 1);
3880 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3883 class _LIBCPP_TEMPLATE_VIS shared_ptr
3886 typedef _Tp element_type;
3888 #if _LIBCPP_STD_VER > 14
3889 typedef weak_ptr<_Tp> weak_type;
3892 element_type* __ptr_;
3893 __shared_weak_count* __cntrl_;
3895 struct __nat {int __for_bool_;};
3897 _LIBCPP_INLINE_VISIBILITY
3898 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3899 _LIBCPP_INLINE_VISIBILITY
3900 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3902 explicit shared_ptr(_Yp* __p,
3903 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3904 template<class _Yp, class _Dp>
3905 shared_ptr(_Yp* __p, _Dp __d,
3906 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3907 template<class _Yp, class _Dp, class _Alloc>
3908 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3909 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3910 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3911 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3912 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3913 _LIBCPP_INLINE_VISIBILITY
3914 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3916 _LIBCPP_INLINE_VISIBILITY
3917 shared_ptr(const shared_ptr<_Yp>& __r,
3918 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3920 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3921 _LIBCPP_INLINE_VISIBILITY
3922 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3923 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3924 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3926 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3927 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3928 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3929 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3931 shared_ptr(auto_ptr<_Yp>&& __r,
3932 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3935 shared_ptr(auto_ptr<_Yp> __r,
3936 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3938 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3939 template <class _Yp, class _Dp>
3940 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3943 !is_lvalue_reference<_Dp>::value &&
3944 !is_array<_Yp>::value &&
3945 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3948 template <class _Yp, class _Dp>
3949 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3952 is_lvalue_reference<_Dp>::value &&
3953 !is_array<_Yp>::value &&
3954 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3957 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3958 template <class _Yp, class _Dp>
3959 shared_ptr(unique_ptr<_Yp, _Dp>,
3962 !is_lvalue_reference<_Dp>::value &&
3963 !is_array<_Yp>::value &&
3964 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3967 template <class _Yp, class _Dp>
3968 shared_ptr(unique_ptr<_Yp, _Dp>,
3971 is_lvalue_reference<_Dp>::value &&
3972 !is_array<_Yp>::value &&
3973 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3976 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3980 _LIBCPP_INLINE_VISIBILITY
3981 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3985 is_convertible<_Yp*, element_type*>::value,
3988 _LIBCPP_INLINE_VISIBILITY
3989 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3990 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3991 _LIBCPP_INLINE_VISIBILITY
3992 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3996 is_convertible<_Yp*, element_type*>::value,
3999 _LIBCPP_INLINE_VISIBILITY
4000 operator=(shared_ptr<_Yp>&& __r);
4002 _LIBCPP_INLINE_VISIBILITY
4005 !is_array<_Yp>::value &&
4006 is_convertible<_Yp*, element_type*>::value,
4009 operator=(auto_ptr<_Yp>&& __r);
4010 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4012 _LIBCPP_INLINE_VISIBILITY
4015 !is_array<_Yp>::value &&
4016 is_convertible<_Yp*, element_type*>::value,
4019 operator=(auto_ptr<_Yp> __r);
4021 template <class _Yp, class _Dp>
4024 !is_array<_Yp>::value &&
4025 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4028 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4029 _LIBCPP_INLINE_VISIBILITY
4030 operator=(unique_ptr<_Yp, _Dp>&& __r);
4031 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4032 _LIBCPP_INLINE_VISIBILITY
4033 operator=(unique_ptr<_Yp, _Dp> __r);
4036 _LIBCPP_INLINE_VISIBILITY
4037 void swap(shared_ptr& __r) _NOEXCEPT;
4038 _LIBCPP_INLINE_VISIBILITY
4039 void reset() _NOEXCEPT;
4043 is_convertible<_Yp*, element_type*>::value,
4046 _LIBCPP_INLINE_VISIBILITY
4048 template<class _Yp, class _Dp>
4051 is_convertible<_Yp*, element_type*>::value,
4054 _LIBCPP_INLINE_VISIBILITY
4055 reset(_Yp* __p, _Dp __d);
4056 template<class _Yp, class _Dp, class _Alloc>
4059 is_convertible<_Yp*, element_type*>::value,
4062 _LIBCPP_INLINE_VISIBILITY
4063 reset(_Yp* __p, _Dp __d, _Alloc __a);
4065 _LIBCPP_INLINE_VISIBILITY
4066 element_type* get() const _NOEXCEPT {return __ptr_;}
4067 _LIBCPP_INLINE_VISIBILITY
4068 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4070 _LIBCPP_INLINE_VISIBILITY
4071 element_type* operator->() const _NOEXCEPT {return __ptr_;}
4072 _LIBCPP_INLINE_VISIBILITY
4073 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4074 _LIBCPP_INLINE_VISIBILITY
4075 bool unique() const _NOEXCEPT {return use_count() == 1;}
4076 _LIBCPP_INLINE_VISIBILITY
4077 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4078 template <class _Up>
4079 _LIBCPP_INLINE_VISIBILITY
4080 bool owner_before(shared_ptr<_Up> const& __p) const
4081 {return __cntrl_ < __p.__cntrl_;}
4082 template <class _Up>
4083 _LIBCPP_INLINE_VISIBILITY
4084 bool owner_before(weak_ptr<_Up> const& __p) const
4085 {return __cntrl_ < __p.__cntrl_;}
4086 _LIBCPP_INLINE_VISIBILITY
4088 __owner_equivalent(const shared_ptr& __p) const
4089 {return __cntrl_ == __p.__cntrl_;}
4091 #ifndef _LIBCPP_NO_RTTI
4092 template <class _Dp>
4093 _LIBCPP_INLINE_VISIBILITY
4094 _Dp* __get_deleter() const _NOEXCEPT
4095 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4096 #endif // _LIBCPP_NO_RTTI
4098 #ifndef _LIBCPP_HAS_NO_VARIADICS
4100 template<class ..._Args>
4103 make_shared(_Args&& ...__args);
4105 template<class _Alloc, class ..._Args>
4108 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4110 #else // _LIBCPP_HAS_NO_VARIADICS
4112 static shared_ptr<_Tp> make_shared();
4115 static shared_ptr<_Tp> make_shared(_A0&);
4117 template<class _A0, class _A1>
4118 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4120 template<class _A0, class _A1, class _A2>
4121 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4123 template<class _Alloc>
4124 static shared_ptr<_Tp>
4125 allocate_shared(const _Alloc& __a);
4127 template<class _Alloc, class _A0>
4128 static shared_ptr<_Tp>
4129 allocate_shared(const _Alloc& __a, _A0& __a0);
4131 template<class _Alloc, class _A0, class _A1>
4132 static shared_ptr<_Tp>
4133 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4135 template<class _Alloc, class _A0, class _A1, class _A2>
4136 static shared_ptr<_Tp>
4137 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4139 #endif // _LIBCPP_HAS_NO_VARIADICS
4143 template <class _Yp, class _OrigPtr>
4144 _LIBCPP_INLINE_VISIBILITY
4146 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4147 _OrigPtr* __ptr) _NOEXCEPT
4149 typedef typename remove_cv<_Yp>::type _RawYp;
4150 if (__e && __e->__weak_this_.expired())
4152 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4153 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
4157 _LIBCPP_INLINE_VISIBILITY
4158 void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {}
4160 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4161 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4167 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4176 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4184 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4185 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4188 unique_ptr<_Yp> __hold(__p);
4189 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4190 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4192 __enable_weak_this(__p, __p);
4196 template<class _Yp, class _Dp>
4197 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4198 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4201 #ifndef _LIBCPP_NO_EXCEPTIONS
4204 #endif // _LIBCPP_NO_EXCEPTIONS
4205 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4206 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4207 __enable_weak_this(__p, __p);
4208 #ifndef _LIBCPP_NO_EXCEPTIONS
4215 #endif // _LIBCPP_NO_EXCEPTIONS
4220 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4223 #ifndef _LIBCPP_NO_EXCEPTIONS
4226 #endif // _LIBCPP_NO_EXCEPTIONS
4227 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4228 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4229 #ifndef _LIBCPP_NO_EXCEPTIONS
4236 #endif // _LIBCPP_NO_EXCEPTIONS
4240 template<class _Yp, class _Dp, class _Alloc>
4241 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4242 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4245 #ifndef _LIBCPP_NO_EXCEPTIONS
4248 #endif // _LIBCPP_NO_EXCEPTIONS
4249 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4250 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4251 typedef __allocator_destructor<_A2> _D2;
4253 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4254 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4255 _CntrlBlk(__p, __d, __a);
4256 __cntrl_ = _VSTD::addressof(*__hold2.release());
4257 __enable_weak_this(__p, __p);
4258 #ifndef _LIBCPP_NO_EXCEPTIONS
4265 #endif // _LIBCPP_NO_EXCEPTIONS
4269 template<class _Dp, class _Alloc>
4270 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4273 #ifndef _LIBCPP_NO_EXCEPTIONS
4276 #endif // _LIBCPP_NO_EXCEPTIONS
4277 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4278 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4279 typedef __allocator_destructor<_A2> _D2;
4281 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4282 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4283 _CntrlBlk(__p, __d, __a);
4284 __cntrl_ = _VSTD::addressof(*__hold2.release());
4285 #ifndef _LIBCPP_NO_EXCEPTIONS
4292 #endif // _LIBCPP_NO_EXCEPTIONS
4298 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4300 __cntrl_(__r.__cntrl_)
4303 __cntrl_->__add_shared();
4308 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4309 : __ptr_(__r.__ptr_),
4310 __cntrl_(__r.__cntrl_)
4313 __cntrl_->__add_shared();
4319 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4320 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4322 : __ptr_(__r.__ptr_),
4323 __cntrl_(__r.__cntrl_)
4326 __cntrl_->__add_shared();
4329 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4333 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4334 : __ptr_(__r.__ptr_),
4335 __cntrl_(__r.__cntrl_)
4344 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4345 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4347 : __ptr_(__r.__ptr_),
4348 __cntrl_(__r.__cntrl_)
4354 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4358 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4359 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4361 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4363 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4366 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4367 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4368 __enable_weak_this(__r.get(), __r.get());
4373 template <class _Yp, class _Dp>
4374 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4375 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4377 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4381 !is_lvalue_reference<_Dp>::value &&
4382 !is_array<_Yp>::value &&
4383 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4388 #if _LIBCPP_STD_VER > 11
4389 if (__ptr_ == nullptr)
4394 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4395 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4396 __enable_weak_this(__r.get(), __r.get());
4402 template <class _Yp, class _Dp>
4403 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4404 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4406 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4410 is_lvalue_reference<_Dp>::value &&
4411 !is_array<_Yp>::value &&
4412 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4417 #if _LIBCPP_STD_VER > 11
4418 if (__ptr_ == nullptr)
4423 typedef __shared_ptr_pointer<_Yp*,
4424 reference_wrapper<typename remove_reference<_Dp>::type>,
4425 allocator<_Yp> > _CntrlBlk;
4426 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4427 __enable_weak_this(__r.get(), __r.get());
4432 #ifndef _LIBCPP_HAS_NO_VARIADICS
4435 template<class ..._Args>
4437 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4439 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4440 typedef allocator<_CntrlBlk> _A2;
4441 typedef __allocator_destructor<_A2> _D2;
4443 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4444 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4445 shared_ptr<_Tp> __r;
4446 __r.__ptr_ = __hold2.get()->get();
4447 __r.__cntrl_ = __hold2.release();
4448 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4453 template<class _Alloc, class ..._Args>
4455 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4457 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4458 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4459 typedef __allocator_destructor<_A2> _D2;
4461 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4462 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4463 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4464 shared_ptr<_Tp> __r;
4465 __r.__ptr_ = __hold2.get()->get();
4466 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4467 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4471 #else // _LIBCPP_HAS_NO_VARIADICS
4475 shared_ptr<_Tp>::make_shared()
4477 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4478 typedef allocator<_CntrlBlk> _Alloc2;
4479 typedef __allocator_destructor<_Alloc2> _D2;
4481 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4482 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4483 shared_ptr<_Tp> __r;
4484 __r.__ptr_ = __hold2.get()->get();
4485 __r.__cntrl_ = __hold2.release();
4486 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4493 shared_ptr<_Tp>::make_shared(_A0& __a0)
4495 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4496 typedef allocator<_CntrlBlk> _Alloc2;
4497 typedef __allocator_destructor<_Alloc2> _D2;
4499 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4500 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4501 shared_ptr<_Tp> __r;
4502 __r.__ptr_ = __hold2.get()->get();
4503 __r.__cntrl_ = __hold2.release();
4504 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4509 template<class _A0, class _A1>
4511 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4513 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4514 typedef allocator<_CntrlBlk> _Alloc2;
4515 typedef __allocator_destructor<_Alloc2> _D2;
4517 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4518 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4519 shared_ptr<_Tp> __r;
4520 __r.__ptr_ = __hold2.get()->get();
4521 __r.__cntrl_ = __hold2.release();
4522 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4527 template<class _A0, class _A1, class _A2>
4529 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4531 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4532 typedef allocator<_CntrlBlk> _Alloc2;
4533 typedef __allocator_destructor<_Alloc2> _D2;
4535 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4536 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4537 shared_ptr<_Tp> __r;
4538 __r.__ptr_ = __hold2.get()->get();
4539 __r.__cntrl_ = __hold2.release();
4540 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4545 template<class _Alloc>
4547 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4549 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4550 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4551 typedef __allocator_destructor<_Alloc2> _D2;
4552 _Alloc2 __alloc2(__a);
4553 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4554 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4556 shared_ptr<_Tp> __r;
4557 __r.__ptr_ = __hold2.get()->get();
4558 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4559 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4564 template<class _Alloc, class _A0>
4566 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4568 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4569 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4570 typedef __allocator_destructor<_Alloc2> _D2;
4571 _Alloc2 __alloc2(__a);
4572 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4573 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4574 _CntrlBlk(__a, __a0);
4575 shared_ptr<_Tp> __r;
4576 __r.__ptr_ = __hold2.get()->get();
4577 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4578 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4583 template<class _Alloc, class _A0, class _A1>
4585 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4587 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4588 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4589 typedef __allocator_destructor<_Alloc2> _D2;
4590 _Alloc2 __alloc2(__a);
4591 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4592 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4593 _CntrlBlk(__a, __a0, __a1);
4594 shared_ptr<_Tp> __r;
4595 __r.__ptr_ = __hold2.get()->get();
4596 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4597 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4602 template<class _Alloc, class _A0, class _A1, class _A2>
4604 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4606 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4607 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4608 typedef __allocator_destructor<_Alloc2> _D2;
4609 _Alloc2 __alloc2(__a);
4610 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4611 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4612 _CntrlBlk(__a, __a0, __a1, __a2);
4613 shared_ptr<_Tp> __r;
4614 __r.__ptr_ = __hold2.get()->get();
4615 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4616 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4620 #endif // _LIBCPP_HAS_NO_VARIADICS
4623 shared_ptr<_Tp>::~shared_ptr()
4626 __cntrl_->__release_shared();
4632 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4634 shared_ptr(__r).swap(*this);
4643 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4646 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4648 shared_ptr(__r).swap(*this);
4652 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4657 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4659 shared_ptr(_VSTD::move(__r)).swap(*this);
4668 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4671 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4673 shared_ptr(_VSTD::move(__r)).swap(*this);
4682 !is_array<_Yp>::value &&
4683 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4686 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4688 shared_ptr(_VSTD::move(__r)).swap(*this);
4693 template <class _Yp, class _Dp>
4697 !is_array<_Yp>::value &&
4698 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4699 typename shared_ptr<_Tp>::element_type*>::value,
4702 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4704 shared_ptr(_VSTD::move(__r)).swap(*this);
4708 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4712 inline _LIBCPP_INLINE_VISIBILITY
4715 !is_array<_Yp>::value &&
4716 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4719 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4721 shared_ptr(__r).swap(*this);
4726 template <class _Yp, class _Dp>
4727 inline _LIBCPP_INLINE_VISIBILITY
4730 !is_array<_Yp>::value &&
4731 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4732 typename shared_ptr<_Tp>::element_type*>::value,
4735 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4737 shared_ptr(_VSTD::move(__r)).swap(*this);
4741 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4746 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4748 _VSTD::swap(__ptr_, __r.__ptr_);
4749 _VSTD::swap(__cntrl_, __r.__cntrl_);
4755 shared_ptr<_Tp>::reset() _NOEXCEPT
4757 shared_ptr().swap(*this);
4765 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4768 shared_ptr<_Tp>::reset(_Yp* __p)
4770 shared_ptr(__p).swap(*this);
4774 template<class _Yp, class _Dp>
4778 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4781 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4783 shared_ptr(__p, __d).swap(*this);
4787 template<class _Yp, class _Dp, class _Alloc>
4791 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4794 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4796 shared_ptr(__p, __d, __a).swap(*this);
4799 #ifndef _LIBCPP_HAS_NO_VARIADICS
4801 template<class _Tp, class ..._Args>
4802 inline _LIBCPP_INLINE_VISIBILITY
4805 !is_array<_Tp>::value,
4808 make_shared(_Args&& ...__args)
4810 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4813 template<class _Tp, class _Alloc, class ..._Args>
4814 inline _LIBCPP_INLINE_VISIBILITY
4817 !is_array<_Tp>::value,
4820 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4822 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4825 #else // _LIBCPP_HAS_NO_VARIADICS
4828 inline _LIBCPP_INLINE_VISIBILITY
4832 return shared_ptr<_Tp>::make_shared();
4835 template<class _Tp, class _A0>
4836 inline _LIBCPP_INLINE_VISIBILITY
4838 make_shared(_A0& __a0)
4840 return shared_ptr<_Tp>::make_shared(__a0);
4843 template<class _Tp, class _A0, class _A1>
4844 inline _LIBCPP_INLINE_VISIBILITY
4846 make_shared(_A0& __a0, _A1& __a1)
4848 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4851 template<class _Tp, class _A0, class _A1, class _A2>
4852 inline _LIBCPP_INLINE_VISIBILITY
4854 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4856 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4859 template<class _Tp, class _Alloc>
4860 inline _LIBCPP_INLINE_VISIBILITY
4862 allocate_shared(const _Alloc& __a)
4864 return shared_ptr<_Tp>::allocate_shared(__a);
4867 template<class _Tp, class _Alloc, class _A0>
4868 inline _LIBCPP_INLINE_VISIBILITY
4870 allocate_shared(const _Alloc& __a, _A0& __a0)
4872 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4875 template<class _Tp, class _Alloc, class _A0, class _A1>
4876 inline _LIBCPP_INLINE_VISIBILITY
4878 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4880 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4883 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4884 inline _LIBCPP_INLINE_VISIBILITY
4886 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4888 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4891 #endif // _LIBCPP_HAS_NO_VARIADICS
4893 template<class _Tp, class _Up>
4894 inline _LIBCPP_INLINE_VISIBILITY
4896 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4898 return __x.get() == __y.get();
4901 template<class _Tp, class _Up>
4902 inline _LIBCPP_INLINE_VISIBILITY
4904 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4906 return !(__x == __y);
4909 template<class _Tp, class _Up>
4910 inline _LIBCPP_INLINE_VISIBILITY
4912 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4914 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4915 return less<_Vp>()(__x.get(), __y.get());
4918 template<class _Tp, class _Up>
4919 inline _LIBCPP_INLINE_VISIBILITY
4921 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4926 template<class _Tp, class _Up>
4927 inline _LIBCPP_INLINE_VISIBILITY
4929 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4931 return !(__y < __x);
4934 template<class _Tp, class _Up>
4935 inline _LIBCPP_INLINE_VISIBILITY
4937 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4939 return !(__x < __y);
4943 inline _LIBCPP_INLINE_VISIBILITY
4945 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4951 inline _LIBCPP_INLINE_VISIBILITY
4953 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4959 inline _LIBCPP_INLINE_VISIBILITY
4961 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4963 return static_cast<bool>(__x);
4967 inline _LIBCPP_INLINE_VISIBILITY
4969 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4971 return static_cast<bool>(__x);
4975 inline _LIBCPP_INLINE_VISIBILITY
4977 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4979 return less<_Tp*>()(__x.get(), nullptr);
4983 inline _LIBCPP_INLINE_VISIBILITY
4985 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4987 return less<_Tp*>()(nullptr, __x.get());
4991 inline _LIBCPP_INLINE_VISIBILITY
4993 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4995 return nullptr < __x;
4999 inline _LIBCPP_INLINE_VISIBILITY
5001 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5003 return __x < nullptr;
5007 inline _LIBCPP_INLINE_VISIBILITY
5009 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5011 return !(nullptr < __x);
5015 inline _LIBCPP_INLINE_VISIBILITY
5017 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5019 return !(__x < nullptr);
5023 inline _LIBCPP_INLINE_VISIBILITY
5025 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5027 return !(__x < nullptr);
5031 inline _LIBCPP_INLINE_VISIBILITY
5033 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5035 return !(nullptr < __x);
5039 inline _LIBCPP_INLINE_VISIBILITY
5041 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
5046 template<class _Tp, class _Up>
5047 inline _LIBCPP_INLINE_VISIBILITY
5050 !is_array<_Tp>::value && !is_array<_Up>::value,
5053 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5055 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
5058 template<class _Tp, class _Up>
5059 inline _LIBCPP_INLINE_VISIBILITY
5062 !is_array<_Tp>::value && !is_array<_Up>::value,
5065 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5067 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5068 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5071 template<class _Tp, class _Up>
5074 is_array<_Tp>::value == is_array<_Up>::value,
5077 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5079 typedef typename remove_extent<_Tp>::type _RTp;
5080 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
5083 #ifndef _LIBCPP_NO_RTTI
5085 template<class _Dp, class _Tp>
5086 inline _LIBCPP_INLINE_VISIBILITY
5088 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
5090 return __p.template __get_deleter<_Dp>();
5093 #endif // _LIBCPP_NO_RTTI
5096 class _LIBCPP_TEMPLATE_VIS weak_ptr
5099 typedef _Tp element_type;
5101 element_type* __ptr_;
5102 __shared_weak_count* __cntrl_;
5105 _LIBCPP_INLINE_VISIBILITY
5106 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
5107 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
5108 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5110 _LIBCPP_INLINE_VISIBILITY
5111 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
5112 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
5113 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5116 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5117 _LIBCPP_INLINE_VISIBILITY
5118 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5119 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
5120 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5122 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5125 _LIBCPP_INLINE_VISIBILITY
5126 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5130 is_convertible<_Yp*, element_type*>::value,
5133 _LIBCPP_INLINE_VISIBILITY
5134 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5136 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5138 _LIBCPP_INLINE_VISIBILITY
5139 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5143 is_convertible<_Yp*, element_type*>::value,
5146 _LIBCPP_INLINE_VISIBILITY
5147 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5149 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5154 is_convertible<_Yp*, element_type*>::value,
5157 _LIBCPP_INLINE_VISIBILITY
5158 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5160 _LIBCPP_INLINE_VISIBILITY
5161 void swap(weak_ptr& __r) _NOEXCEPT;
5162 _LIBCPP_INLINE_VISIBILITY
5163 void reset() _NOEXCEPT;
5165 _LIBCPP_INLINE_VISIBILITY
5166 long use_count() const _NOEXCEPT
5167 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5168 _LIBCPP_INLINE_VISIBILITY
5169 bool expired() const _NOEXCEPT
5170 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5171 shared_ptr<_Tp> lock() const _NOEXCEPT;
5173 _LIBCPP_INLINE_VISIBILITY
5174 bool owner_before(const shared_ptr<_Up>& __r) const
5175 {return __cntrl_ < __r.__cntrl_;}
5177 _LIBCPP_INLINE_VISIBILITY
5178 bool owner_before(const weak_ptr<_Up>& __r) const
5179 {return __cntrl_ < __r.__cntrl_;}
5181 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5182 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
5188 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5196 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5197 : __ptr_(__r.__ptr_),
5198 __cntrl_(__r.__cntrl_)
5201 __cntrl_->__add_weak();
5207 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5208 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5210 : __ptr_(__r.__ptr_),
5211 __cntrl_(__r.__cntrl_)
5214 __cntrl_->__add_weak();
5220 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5221 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5223 : __ptr_(__r.__ptr_),
5224 __cntrl_(__r.__cntrl_)
5227 __cntrl_->__add_weak();
5230 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5234 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5235 : __ptr_(__r.__ptr_),
5236 __cntrl_(__r.__cntrl_)
5245 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5246 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5248 : __ptr_(__r.__ptr_),
5249 __cntrl_(__r.__cntrl_)
5255 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5258 weak_ptr<_Tp>::~weak_ptr()
5261 __cntrl_->__release_weak();
5267 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5269 weak_ptr(__r).swap(*this);
5278 is_convertible<_Yp*, _Tp*>::value,
5281 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5283 weak_ptr(__r).swap(*this);
5287 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5292 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5294 weak_ptr(_VSTD::move(__r)).swap(*this);
5303 is_convertible<_Yp*, _Tp*>::value,
5306 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5308 weak_ptr(_VSTD::move(__r)).swap(*this);
5312 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5319 is_convertible<_Yp*, _Tp*>::value,
5322 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5324 weak_ptr(__r).swap(*this);
5331 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5333 _VSTD::swap(__ptr_, __r.__ptr_);
5334 _VSTD::swap(__cntrl_, __r.__cntrl_);
5338 inline _LIBCPP_INLINE_VISIBILITY
5340 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5348 weak_ptr<_Tp>::reset() _NOEXCEPT
5350 weak_ptr().swap(*this);
5355 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5356 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5357 : __ptr_(__r.__ptr_),
5358 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5361 __throw_bad_weak_ptr();
5366 weak_ptr<_Tp>::lock() const _NOEXCEPT
5368 shared_ptr<_Tp> __r;
5369 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5371 __r.__ptr_ = __ptr_;
5375 #if _LIBCPP_STD_VER > 14
5376 template <class _Tp = void> struct owner_less;
5378 template <class _Tp> struct owner_less;
5381 template <class _Tp>
5382 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5383 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5385 typedef bool result_type;
5386 _LIBCPP_INLINE_VISIBILITY
5387 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5388 {return __x.owner_before(__y);}
5389 _LIBCPP_INLINE_VISIBILITY
5390 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5391 {return __x.owner_before(__y);}
5392 _LIBCPP_INLINE_VISIBILITY
5393 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5394 {return __x.owner_before(__y);}
5397 template <class _Tp>
5398 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5399 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5401 typedef bool result_type;
5402 _LIBCPP_INLINE_VISIBILITY
5403 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5404 {return __x.owner_before(__y);}
5405 _LIBCPP_INLINE_VISIBILITY
5406 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5407 {return __x.owner_before(__y);}
5408 _LIBCPP_INLINE_VISIBILITY
5409 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5410 {return __x.owner_before(__y);}
5413 #if _LIBCPP_STD_VER > 14
5415 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5417 template <class _Tp, class _Up>
5418 _LIBCPP_INLINE_VISIBILITY
5419 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5420 {return __x.owner_before(__y);}
5421 template <class _Tp, class _Up>
5422 _LIBCPP_INLINE_VISIBILITY
5423 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5424 {return __x.owner_before(__y);}
5425 template <class _Tp, class _Up>
5426 _LIBCPP_INLINE_VISIBILITY
5427 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5428 {return __x.owner_before(__y);}
5429 template <class _Tp, class _Up>
5430 _LIBCPP_INLINE_VISIBILITY
5431 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5432 {return __x.owner_before(__y);}
5433 typedef void is_transparent;
5438 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5440 mutable weak_ptr<_Tp> __weak_this_;
5442 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5443 enable_shared_from_this() _NOEXCEPT {}
5444 _LIBCPP_INLINE_VISIBILITY
5445 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5446 _LIBCPP_INLINE_VISIBILITY
5447 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5449 _LIBCPP_INLINE_VISIBILITY
5450 ~enable_shared_from_this() {}
5452 _LIBCPP_INLINE_VISIBILITY
5453 shared_ptr<_Tp> shared_from_this()
5454 {return shared_ptr<_Tp>(__weak_this_);}
5455 _LIBCPP_INLINE_VISIBILITY
5456 shared_ptr<_Tp const> shared_from_this() const
5457 {return shared_ptr<const _Tp>(__weak_this_);}
5459 #if _LIBCPP_STD_VER > 14
5460 _LIBCPP_INLINE_VISIBILITY
5461 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5462 { return __weak_this_; }
5464 _LIBCPP_INLINE_VISIBILITY
5465 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5466 { return __weak_this_; }
5467 #endif // _LIBCPP_STD_VER > 14
5469 template <class _Up> friend class shared_ptr;
5472 template <class _Tp>
5473 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5475 typedef shared_ptr<_Tp> argument_type;
5476 typedef size_t result_type;
5477 _LIBCPP_INLINE_VISIBILITY
5478 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5480 return hash<_Tp*>()(__ptr.get());
5484 template<class _CharT, class _Traits, class _Yp>
5485 inline _LIBCPP_INLINE_VISIBILITY
5486 basic_ostream<_CharT, _Traits>&
5487 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5490 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5492 class _LIBCPP_TYPE_VIS __sp_mut
5496 void lock() _NOEXCEPT;
5497 void unlock() _NOEXCEPT;
5500 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5501 __sp_mut(const __sp_mut&);
5502 __sp_mut& operator=(const __sp_mut&);
5504 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5507 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5509 template <class _Tp>
5510 inline _LIBCPP_INLINE_VISIBILITY
5512 atomic_is_lock_free(const shared_ptr<_Tp>*)
5517 template <class _Tp>
5519 atomic_load(const shared_ptr<_Tp>* __p)
5521 __sp_mut& __m = __get_sp_mut(__p);
5523 shared_ptr<_Tp> __q = *__p;
5528 template <class _Tp>
5529 inline _LIBCPP_INLINE_VISIBILITY
5531 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5533 return atomic_load(__p);
5536 template <class _Tp>
5538 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5540 __sp_mut& __m = __get_sp_mut(__p);
5546 template <class _Tp>
5547 inline _LIBCPP_INLINE_VISIBILITY
5549 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5551 atomic_store(__p, __r);
5554 template <class _Tp>
5556 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5558 __sp_mut& __m = __get_sp_mut(__p);
5565 template <class _Tp>
5566 inline _LIBCPP_INLINE_VISIBILITY
5568 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5570 return atomic_exchange(__p, __r);
5573 template <class _Tp>
5575 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5577 shared_ptr<_Tp> __temp;
5578 __sp_mut& __m = __get_sp_mut(__p);
5580 if (__p->__owner_equivalent(*__v))
5582 _VSTD::swap(__temp, *__p);
5587 _VSTD::swap(__temp, *__v);
5593 template <class _Tp>
5594 inline _LIBCPP_INLINE_VISIBILITY
5596 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5598 return atomic_compare_exchange_strong(__p, __v, __w);
5601 template <class _Tp>
5602 inline _LIBCPP_INLINE_VISIBILITY
5604 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5605 shared_ptr<_Tp> __w, memory_order, memory_order)
5607 return atomic_compare_exchange_strong(__p, __v, __w);
5610 template <class _Tp>
5611 inline _LIBCPP_INLINE_VISIBILITY
5613 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5614 shared_ptr<_Tp> __w, memory_order, memory_order)
5616 return atomic_compare_exchange_weak(__p, __v, __w);
5619 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5622 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5623 # ifndef _LIBCPP_CXX03_LANG
5624 enum class pointer_safety : unsigned char {
5631 struct _LIBCPP_TYPE_VIS pointer_safety
5642 _LIBCPP_INLINE_VISIBILITY
5643 pointer_safety() : __v_() {}
5645 _LIBCPP_INLINE_VISIBILITY
5646 pointer_safety(__lx __v) : __v_(__v) {}
5647 _LIBCPP_INLINE_VISIBILITY
5648 operator int() const {return __v_;}
5652 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5653 defined(_LIBCPP_BUILDING_MEMORY)
5654 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5656 // This function is only offered in C++03 under ABI v1.
5657 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5658 inline _LIBCPP_INLINE_VISIBILITY
5659 pointer_safety get_pointer_safety() _NOEXCEPT {
5660 return pointer_safety::relaxed;
5666 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5667 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5668 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5669 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5671 template <class _Tp>
5672 inline _LIBCPP_INLINE_VISIBILITY
5674 undeclare_reachable(_Tp* __p)
5676 return static_cast<_Tp*>(__undeclare_reachable(__p));
5679 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5681 // --- Helper for container swap --
5682 template <typename _Alloc>
5683 inline _LIBCPP_INLINE_VISIBILITY
5684 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5685 #if _LIBCPP_STD_VER >= 14
5688 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5691 __swap_allocator(__a1, __a2,
5692 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5695 template <typename _Alloc>
5696 _LIBCPP_INLINE_VISIBILITY
5697 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5698 #if _LIBCPP_STD_VER >= 14
5701 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5708 template <typename _Alloc>
5709 inline _LIBCPP_INLINE_VISIBILITY
5710 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5712 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5713 struct __noexcept_move_assign_container : public integral_constant<bool,
5714 _Traits::propagate_on_container_move_assignment::value
5715 #if _LIBCPP_STD_VER > 14
5716 || _Traits::is_always_equal::value
5718 && is_nothrow_move_assignable<_Alloc>::value
5723 #ifndef _LIBCPP_HAS_NO_VARIADICS
5724 template <class _Tp, class _Alloc>
5725 struct __temp_value {
5726 typedef allocator_traits<_Alloc> _Traits;
5728 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5731 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5732 _Tp & get() { return *__addr(); }
5734 template<class... _Args>
5735 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5736 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5738 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5742 _LIBCPP_END_NAMESPACE_STD
5744 #endif // _LIBCPP_MEMORY