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;
168 template <class InputIterator, class ForwardIterator>
170 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
172 template <class InputIterator, class Size, class ForwardIterator>
174 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
176 template <class ForwardIterator, class T>
177 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
179 template <class ForwardIterator, class Size, class T>
181 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
183 template <class Y> struct auto_ptr_ref {};
189 typedef X element_type;
191 explicit auto_ptr(X* p =0) throw();
192 auto_ptr(auto_ptr&) throw();
193 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
194 auto_ptr& operator=(auto_ptr&) throw();
195 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
196 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
199 typename add_lvalue_reference<X>::type operator*() const throw();
200 X* operator->() const throw();
201 X* get() const throw();
202 X* release() throw();
203 void reset(X* p =0) throw();
205 auto_ptr(auto_ptr_ref<X>) throw();
206 template<class Y> operator auto_ptr_ref<Y>() throw();
207 template<class Y> operator auto_ptr<Y>() throw();
211 struct default_delete
213 constexpr default_delete() noexcept = default;
214 template <class U> default_delete(const default_delete<U>&) noexcept;
216 void operator()(T*) const noexcept;
220 struct default_delete<T[]>
222 constexpr default_delete() noexcept = default;
223 void operator()(T*) const noexcept;
224 template <class U> void operator()(U*) const = delete;
227 template <class T, class D = default_delete<T>>
231 typedef see below pointer;
232 typedef T element_type;
233 typedef D deleter_type;
236 constexpr unique_ptr() noexcept;
237 explicit unique_ptr(pointer p) noexcept;
238 unique_ptr(pointer p, see below d1) noexcept;
239 unique_ptr(pointer p, see below d2) noexcept;
240 unique_ptr(unique_ptr&& u) noexcept;
241 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
242 template <class U, class E>
243 unique_ptr(unique_ptr<U, E>&& u) noexcept;
245 unique_ptr(auto_ptr<U>&& u) noexcept;
251 unique_ptr& operator=(unique_ptr&& u) noexcept;
252 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
253 unique_ptr& operator=(nullptr_t) noexcept;
256 typename add_lvalue_reference<T>::type operator*() const;
257 pointer operator->() const noexcept;
258 pointer get() const noexcept;
259 deleter_type& get_deleter() noexcept;
260 const deleter_type& get_deleter() const noexcept;
261 explicit operator bool() const noexcept;
264 pointer release() noexcept;
265 void reset(pointer p = pointer()) noexcept;
266 void swap(unique_ptr& u) noexcept;
269 template <class T, class D>
270 class unique_ptr<T[], D>
273 typedef implementation-defined pointer;
274 typedef T element_type;
275 typedef D deleter_type;
278 constexpr unique_ptr() noexcept;
279 explicit unique_ptr(pointer p) noexcept;
280 unique_ptr(pointer p, see below d) noexcept;
281 unique_ptr(pointer p, see below d) noexcept;
282 unique_ptr(unique_ptr&& u) noexcept;
283 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
289 unique_ptr& operator=(unique_ptr&& u) noexcept;
290 unique_ptr& operator=(nullptr_t) noexcept;
293 T& operator[](size_t i) const;
294 pointer get() const noexcept;
295 deleter_type& get_deleter() noexcept;
296 const deleter_type& get_deleter() const noexcept;
297 explicit operator bool() const noexcept;
300 pointer release() noexcept;
301 void reset(pointer p = pointer()) noexcept;
302 void reset(nullptr_t) noexcept;
303 template <class U> void reset(U) = delete;
304 void swap(unique_ptr& u) noexcept;
307 template <class T, class D>
308 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
310 template <class T1, class D1, class T2, class D2>
311 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312 template <class T1, class D1, class T2, class D2>
313 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314 template <class T1, class D1, class T2, class D2>
315 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316 template <class T1, class D1, class T2, class D2>
317 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318 template <class T1, class D1, class T2, class D2>
319 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
320 template <class T1, class D1, class T2, class D2>
321 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
323 template <class T, class D>
324 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
325 template <class T, class D>
326 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
327 template <class T, class D>
328 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
329 template <class T, class D>
330 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
332 template <class T, class D>
333 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
334 template <class T, class D>
335 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
336 template <class T, class D>
337 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
338 template <class T, class D>
339 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
340 template <class T, class D>
341 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
342 template <class T, class D>
343 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
344 template <class T, class D>
345 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
346 template <class T, class D>
347 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
350 : public std::exception
352 bad_weak_ptr() noexcept;
355 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
356 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
357 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
363 typedef T element_type;
364 typedef weak_ptr<T> weak_type; // C++17
367 constexpr shared_ptr() noexcept;
368 template<class Y> explicit shared_ptr(Y* p);
369 template<class Y, class D> shared_ptr(Y* p, D d);
370 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
371 template <class D> shared_ptr(nullptr_t p, D d);
372 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
373 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
374 shared_ptr(const shared_ptr& r) noexcept;
375 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
376 shared_ptr(shared_ptr&& r) noexcept;
377 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
378 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
379 template<class Y> shared_ptr(auto_ptr<Y>&& r);
380 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
381 shared_ptr(nullptr_t) : shared_ptr() { }
387 shared_ptr& operator=(const shared_ptr& r) noexcept;
388 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
389 shared_ptr& operator=(shared_ptr&& r) noexcept;
390 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
391 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
392 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
395 void swap(shared_ptr& r) noexcept;
396 void reset() noexcept;
397 template<class Y> void reset(Y* p);
398 template<class Y, class D> void reset(Y* p, D d);
399 template<class Y, class D, class A> void reset(Y* p, D d, A a);
402 T* get() const noexcept;
403 T& operator*() const noexcept;
404 T* operator->() const noexcept;
405 long use_count() const noexcept;
406 bool unique() const noexcept;
407 explicit operator bool() const noexcept;
408 template<class U> bool owner_before(shared_ptr<U> const& b) const;
409 template<class U> bool owner_before(weak_ptr<U> const& b) const;
412 // shared_ptr comparisons:
413 template<class T, class U>
414 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
415 template<class T, class U>
416 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
417 template<class T, class U>
418 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
419 template<class T, class U>
420 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
421 template<class T, class U>
422 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
423 template<class T, class U>
424 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
427 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
429 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
431 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
433 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
435 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
437 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
439 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
441 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
443 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
445 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
447 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
449 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
451 // shared_ptr specialized algorithms:
452 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
455 template<class T, class U>
456 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
457 template<class T, class U>
458 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
459 template<class T, class U>
460 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
463 template<class E, class T, class Y>
464 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
466 // shared_ptr get_deleter:
467 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
469 template<class T, class... Args>
470 shared_ptr<T> make_shared(Args&&... args);
471 template<class T, class A, class... Args>
472 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
478 typedef T element_type;
481 constexpr weak_ptr() noexcept;
482 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
483 weak_ptr(weak_ptr const& r) noexcept;
484 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
485 weak_ptr(weak_ptr&& r) noexcept; // C++14
486 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
492 weak_ptr& operator=(weak_ptr const& r) noexcept;
493 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
494 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
495 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
496 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
499 void swap(weak_ptr& r) noexcept;
500 void reset() noexcept;
503 long use_count() const noexcept;
504 bool expired() const noexcept;
505 shared_ptr<T> lock() const noexcept;
506 template<class U> bool owner_before(shared_ptr<U> const& b) const;
507 template<class U> bool owner_before(weak_ptr<U> const& b) const;
510 // weak_ptr specialized algorithms:
511 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
514 template<class T> struct owner_less;
517 struct owner_less<shared_ptr<T>>
518 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
520 typedef bool result_type;
521 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
522 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
523 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
527 struct owner_less<weak_ptr<T>>
528 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
530 typedef bool result_type;
531 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
532 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
533 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
537 class enable_shared_from_this
540 constexpr enable_shared_from_this() noexcept;
541 enable_shared_from_this(enable_shared_from_this const&) noexcept;
542 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
543 ~enable_shared_from_this();
545 shared_ptr<T> shared_from_this();
546 shared_ptr<T const> shared_from_this() const;
550 bool atomic_is_lock_free(const shared_ptr<T>* p);
552 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
554 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
556 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
558 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
560 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
563 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
566 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
569 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
572 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
573 shared_ptr<T> w, memory_order success,
574 memory_order failure);
577 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
578 shared_ptr<T> w, memory_order success,
579 memory_order failure);
581 template <class T> struct hash;
582 template <class T, class D> struct hash<unique_ptr<T, D> >;
583 template <class T> struct hash<shared_ptr<T> >;
586 enum class pointer_safety { relaxed, preferred, strict };
587 void declare_reachable(void *p);
588 template <class T> T *undeclare_reachable(T *p);
589 void declare_no_pointers(char *p, size_t n);
590 void undeclare_no_pointers(char *p, size_t n);
591 pointer_safety get_pointer_safety() noexcept;
593 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
600 #include <type_traits>
608 #include <__functional_base>
613 #if defined(_LIBCPP_NO_EXCEPTIONS)
617 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
621 #include <__undef_min_max>
622 #include <__undef___deallocate>
624 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
625 #pragma GCC system_header
628 _LIBCPP_BEGIN_NAMESPACE_STD
630 template <class _ValueType>
631 inline _LIBCPP_ALWAYS_INLINE
632 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
633 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
634 defined(__ATOMIC_RELAXED) && \
635 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
636 return __atomic_load_n(__value, __ATOMIC_RELAXED);
642 // addressof moved to <__functional_base>
644 template <class _Tp> class allocator;
647 class _LIBCPP_TYPE_VIS_ONLY allocator<void>
650 typedef void* pointer;
651 typedef const void* const_pointer;
652 typedef void value_type;
654 template <class _Up> struct rebind {typedef allocator<_Up> other;};
658 class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
661 typedef const void* pointer;
662 typedef const void* const_pointer;
663 typedef const void value_type;
665 template <class _Up> struct rebind {typedef allocator<_Up> other;};
671 struct __has_element_type
674 struct __two {char __lx; char __lxx;};
675 template <class _Up> static __two __test(...);
676 template <class _Up> static char __test(typename _Up::element_type* = 0);
678 static const bool value = sizeof(__test<_Tp>(0)) == 1;
681 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
682 struct __pointer_traits_element_type;
684 template <class _Ptr>
685 struct __pointer_traits_element_type<_Ptr, true>
687 typedef typename _Ptr::element_type type;
690 #ifndef _LIBCPP_HAS_NO_VARIADICS
692 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
693 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
695 typedef typename _Sp<_Tp, _Args...>::element_type type;
698 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
699 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
704 #else // _LIBCPP_HAS_NO_VARIADICS
706 template <template <class> class _Sp, class _Tp>
707 struct __pointer_traits_element_type<_Sp<_Tp>, true>
709 typedef typename _Sp<_Tp>::element_type type;
712 template <template <class> class _Sp, class _Tp>
713 struct __pointer_traits_element_type<_Sp<_Tp>, false>
718 template <template <class, class> class _Sp, class _Tp, class _A0>
719 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
721 typedef typename _Sp<_Tp, _A0>::element_type type;
724 template <template <class, class> class _Sp, class _Tp, class _A0>
725 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
730 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
731 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
733 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
736 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
737 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
742 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
743 class _A1, class _A2>
744 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
746 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
749 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
750 class _A1, class _A2>
751 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
756 #endif // _LIBCPP_HAS_NO_VARIADICS
759 struct __has_difference_type
762 struct __two {char __lx; char __lxx;};
763 template <class _Up> static __two __test(...);
764 template <class _Up> static char __test(typename _Up::difference_type* = 0);
766 static const bool value = sizeof(__test<_Tp>(0)) == 1;
769 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
770 struct __pointer_traits_difference_type
772 typedef ptrdiff_t type;
775 template <class _Ptr>
776 struct __pointer_traits_difference_type<_Ptr, true>
778 typedef typename _Ptr::difference_type type;
781 template <class _Tp, class _Up>
785 struct __two {char __lx; char __lxx;};
786 template <class _Xp> static __two __test(...);
787 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
789 static const bool value = sizeof(__test<_Tp>(0)) == 1;
792 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
793 struct __pointer_traits_rebind
795 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
796 typedef typename _Tp::template rebind<_Up> type;
798 typedef typename _Tp::template rebind<_Up>::other type;
802 #ifndef _LIBCPP_HAS_NO_VARIADICS
804 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
805 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
807 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
808 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
810 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
814 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
815 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
817 typedef _Sp<_Up, _Args...> type;
820 #else // _LIBCPP_HAS_NO_VARIADICS
822 template <template <class> class _Sp, class _Tp, class _Up>
823 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
825 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
826 typedef typename _Sp<_Tp>::template rebind<_Up> type;
828 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
832 template <template <class> class _Sp, class _Tp, class _Up>
833 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
835 typedef _Sp<_Up> type;
838 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
839 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
841 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
842 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
844 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
848 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
849 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
851 typedef _Sp<_Up, _A0> type;
854 template <template <class, class, class> class _Sp, class _Tp, class _A0,
855 class _A1, class _Up>
856 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
858 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
859 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
861 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
865 template <template <class, class, class> class _Sp, class _Tp, class _A0,
866 class _A1, class _Up>
867 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
869 typedef _Sp<_Up, _A0, _A1> type;
872 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
873 class _A1, class _A2, class _Up>
874 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
876 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
877 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
879 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
883 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
884 class _A1, class _A2, class _Up>
885 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
887 typedef _Sp<_Up, _A0, _A1, _A2> type;
890 #endif // _LIBCPP_HAS_NO_VARIADICS
892 template <class _Ptr>
893 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
895 typedef _Ptr pointer;
896 typedef typename __pointer_traits_element_type<pointer>::type element_type;
897 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
899 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
900 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
902 template <class _Up> struct rebind
903 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
904 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
909 _LIBCPP_INLINE_VISIBILITY
910 static pointer pointer_to(typename conditional<is_void<element_type>::value,
911 __nat, element_type>::type& __r)
912 {return pointer::pointer_to(__r);}
916 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
918 typedef _Tp* pointer;
919 typedef _Tp element_type;
920 typedef ptrdiff_t difference_type;
922 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
923 template <class _Up> using rebind = _Up*;
925 template <class _Up> struct rebind {typedef _Up* other;};
931 _LIBCPP_INLINE_VISIBILITY
932 static pointer pointer_to(typename conditional<is_void<element_type>::value,
933 __nat, element_type>::type& __r) _NOEXCEPT
934 {return _VSTD::addressof(__r);}
937 template <class _From, class _To>
938 struct __rebind_pointer {
939 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
940 typedef typename pointer_traits<_From>::template rebind<_To> type;
942 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
948 namespace __has_pointer_type_imp
950 template <class _Up> static __two __test(...);
951 template <class _Up> static char __test(typename _Up::pointer* = 0);
955 struct __has_pointer_type
956 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
960 namespace __pointer_type_imp
963 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
964 struct __pointer_type
966 typedef typename _Dp::pointer type;
969 template <class _Tp, class _Dp>
970 struct __pointer_type<_Tp, _Dp, false>
975 } // __pointer_type_imp
977 template <class _Tp, class _Dp>
978 struct __pointer_type
980 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
984 struct __has_const_pointer
987 struct __two {char __lx; char __lxx;};
988 template <class _Up> static __two __test(...);
989 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
991 static const bool value = sizeof(__test<_Tp>(0)) == 1;
994 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
995 struct __const_pointer
997 typedef typename _Alloc::const_pointer type;
1000 template <class _Tp, class _Ptr, class _Alloc>
1001 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1003 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1004 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1006 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1010 template <class _Tp>
1011 struct __has_void_pointer
1014 struct __two {char __lx; char __lxx;};
1015 template <class _Up> static __two __test(...);
1016 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1018 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1021 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1022 struct __void_pointer
1024 typedef typename _Alloc::void_pointer type;
1027 template <class _Ptr, class _Alloc>
1028 struct __void_pointer<_Ptr, _Alloc, false>
1030 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1031 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1033 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1037 template <class _Tp>
1038 struct __has_const_void_pointer
1041 struct __two {char __lx; char __lxx;};
1042 template <class _Up> static __two __test(...);
1043 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1045 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1048 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1049 struct __const_void_pointer
1051 typedef typename _Alloc::const_void_pointer type;
1054 template <class _Ptr, class _Alloc>
1055 struct __const_void_pointer<_Ptr, _Alloc, false>
1057 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1058 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1060 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1064 template <class _Tp>
1065 inline _LIBCPP_INLINE_VISIBILITY
1067 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1072 template <class _Pointer>
1073 inline _LIBCPP_INLINE_VISIBILITY
1074 typename pointer_traits<_Pointer>::element_type*
1075 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1077 return _VSTD::__to_raw_pointer(__p.operator->());
1080 template <class _Tp>
1081 struct __has_size_type
1084 struct __two {char __lx; char __lxx;};
1085 template <class _Up> static __two __test(...);
1086 template <class _Up> static char __test(typename _Up::size_type* = 0);
1088 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1091 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1094 typedef typename make_unsigned<_DiffType>::type type;
1097 template <class _Alloc, class _DiffType>
1098 struct __size_type<_Alloc, _DiffType, true>
1100 typedef typename _Alloc::size_type type;
1103 template <class _Tp>
1104 struct __has_propagate_on_container_copy_assignment
1107 struct __two {char __lx; char __lxx;};
1108 template <class _Up> static __two __test(...);
1109 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1111 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1114 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1115 struct __propagate_on_container_copy_assignment
1117 typedef false_type type;
1120 template <class _Alloc>
1121 struct __propagate_on_container_copy_assignment<_Alloc, true>
1123 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1126 template <class _Tp>
1127 struct __has_propagate_on_container_move_assignment
1130 struct __two {char __lx; char __lxx;};
1131 template <class _Up> static __two __test(...);
1132 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1134 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1137 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1138 struct __propagate_on_container_move_assignment
1140 typedef false_type type;
1143 template <class _Alloc>
1144 struct __propagate_on_container_move_assignment<_Alloc, true>
1146 typedef typename _Alloc::propagate_on_container_move_assignment type;
1149 template <class _Tp>
1150 struct __has_propagate_on_container_swap
1153 struct __two {char __lx; char __lxx;};
1154 template <class _Up> static __two __test(...);
1155 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1157 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1160 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1161 struct __propagate_on_container_swap
1163 typedef false_type type;
1166 template <class _Alloc>
1167 struct __propagate_on_container_swap<_Alloc, true>
1169 typedef typename _Alloc::propagate_on_container_swap type;
1172 template <class _Tp>
1173 struct __has_is_always_equal
1176 struct __two {char __lx; char __lxx;};
1177 template <class _Up> static __two __test(...);
1178 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1180 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1183 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1184 struct __is_always_equal
1186 typedef typename _VSTD::is_empty<_Alloc>::type type;
1189 template <class _Alloc>
1190 struct __is_always_equal<_Alloc, true>
1192 typedef typename _Alloc::is_always_equal type;
1195 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1196 struct __has_rebind_other
1199 struct __two {char __lx; char __lxx;};
1200 template <class _Xp> static __two __test(...);
1201 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1203 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1206 template <class _Tp, class _Up>
1207 struct __has_rebind_other<_Tp, _Up, false>
1209 static const bool value = false;
1212 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1213 struct __allocator_traits_rebind
1215 typedef typename _Tp::template rebind<_Up>::other type;
1218 #ifndef _LIBCPP_HAS_NO_VARIADICS
1220 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1221 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1223 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1226 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1227 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1229 typedef _Alloc<_Up, _Args...> type;
1232 #else // _LIBCPP_HAS_NO_VARIADICS
1234 template <template <class> class _Alloc, class _Tp, class _Up>
1235 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1237 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1240 template <template <class> class _Alloc, class _Tp, class _Up>
1241 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1243 typedef _Alloc<_Up> type;
1246 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1247 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1249 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1252 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1253 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1255 typedef _Alloc<_Up, _A0> type;
1258 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1259 class _A1, class _Up>
1260 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1262 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1265 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1266 class _A1, class _Up>
1267 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1269 typedef _Alloc<_Up, _A0, _A1> type;
1272 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1273 class _A1, class _A2, class _Up>
1274 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1276 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1279 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1280 class _A1, class _A2, class _Up>
1281 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1283 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1286 #endif // _LIBCPP_HAS_NO_VARIADICS
1288 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1290 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1292 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1293 -> decltype(__a.allocate(__sz, __p), true_type());
1295 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1297 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1300 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1301 struct __has_allocate_hint
1302 : integral_constant<bool,
1304 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1305 declval<_SizeType>(),
1306 declval<_ConstVoidPtr>())),
1311 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1313 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1314 struct __has_allocate_hint
1319 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1321 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1323 template <class _Alloc, class _Tp, class ..._Args>
1324 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1325 _VSTD::declval<_Args>()...),
1327 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1329 template <class _Alloc, class _Pointer, class ..._Args>
1331 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1333 template <class _Alloc, class _Pointer, class ..._Args>
1334 struct __has_construct
1335 : integral_constant<bool,
1337 decltype(__has_construct_test(declval<_Alloc>(),
1338 declval<_Pointer>(),
1339 declval<_Args>()...)),
1344 template <class _Alloc, class _Pointer>
1346 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1347 -> decltype(__a.destroy(__p), true_type());
1349 template <class _Alloc, class _Pointer>
1351 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1354 template <class _Alloc, class _Pointer>
1355 struct __has_destroy
1356 : integral_constant<bool,
1358 decltype(__has_destroy_test(declval<_Alloc>(),
1359 declval<_Pointer>())),
1364 template <class _Alloc>
1366 __has_max_size_test(_Alloc&& __a)
1367 -> decltype(__a.max_size(), true_type());
1369 template <class _Alloc>
1371 __has_max_size_test(const volatile _Alloc& __a)
1374 template <class _Alloc>
1375 struct __has_max_size
1376 : integral_constant<bool,
1378 decltype(__has_max_size_test(declval<_Alloc&>())),
1383 template <class _Alloc>
1385 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1386 -> decltype(__a.select_on_container_copy_construction(), true_type());
1388 template <class _Alloc>
1390 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1393 template <class _Alloc>
1394 struct __has_select_on_container_copy_construction
1395 : integral_constant<bool,
1397 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1402 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1404 #ifndef _LIBCPP_HAS_NO_VARIADICS
1406 template <class _Alloc, class _Pointer, class ..._Args>
1407 struct __has_construct
1412 #else // _LIBCPP_HAS_NO_VARIADICS
1414 template <class _Alloc, class _Pointer, class _Args>
1415 struct __has_construct
1420 #endif // _LIBCPP_HAS_NO_VARIADICS
1422 template <class _Alloc, class _Pointer>
1423 struct __has_destroy
1428 template <class _Alloc>
1429 struct __has_max_size
1434 template <class _Alloc>
1435 struct __has_select_on_container_copy_construction
1440 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1442 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1443 struct __alloc_traits_difference_type
1445 typedef typename pointer_traits<_Ptr>::difference_type type;
1448 template <class _Alloc, class _Ptr>
1449 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1451 typedef typename _Alloc::difference_type type;
1454 template <class _Alloc>
1455 struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
1457 typedef _Alloc allocator_type;
1458 typedef typename allocator_type::value_type value_type;
1460 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1461 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1462 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1463 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1465 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1466 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1468 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1469 propagate_on_container_copy_assignment;
1470 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1471 propagate_on_container_move_assignment;
1472 typedef typename __propagate_on_container_swap<allocator_type>::type
1473 propagate_on_container_swap;
1474 typedef typename __is_always_equal<allocator_type>::type
1477 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1478 template <class _Tp> using rebind_alloc =
1479 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1480 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1481 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1482 template <class _Tp> struct rebind_alloc
1483 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1484 template <class _Tp> struct rebind_traits
1485 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1486 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1488 _LIBCPP_INLINE_VISIBILITY
1489 static pointer allocate(allocator_type& __a, size_type __n)
1490 {return __a.allocate(__n);}
1491 _LIBCPP_INLINE_VISIBILITY
1492 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1493 {return allocate(__a, __n, __hint,
1494 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1496 _LIBCPP_INLINE_VISIBILITY
1497 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1498 {__a.deallocate(__p, __n);}
1500 #ifndef _LIBCPP_HAS_NO_VARIADICS
1501 template <class _Tp, class... _Args>
1502 _LIBCPP_INLINE_VISIBILITY
1503 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1504 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1505 __a, __p, _VSTD::forward<_Args>(__args)...);}
1506 #else // _LIBCPP_HAS_NO_VARIADICS
1507 template <class _Tp>
1508 _LIBCPP_INLINE_VISIBILITY
1509 static void construct(allocator_type& __a, _Tp* __p)
1511 ::new ((void*)__p) _Tp();
1513 template <class _Tp, class _A0>
1514 _LIBCPP_INLINE_VISIBILITY
1515 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1517 ::new ((void*)__p) _Tp(__a0);
1519 template <class _Tp, class _A0, class _A1>
1520 _LIBCPP_INLINE_VISIBILITY
1521 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1524 ::new ((void*)__p) _Tp(__a0, __a1);
1526 template <class _Tp, class _A0, class _A1, class _A2>
1527 _LIBCPP_INLINE_VISIBILITY
1528 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1529 const _A1& __a1, const _A2& __a2)
1531 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1533 #endif // _LIBCPP_HAS_NO_VARIADICS
1535 template <class _Tp>
1536 _LIBCPP_INLINE_VISIBILITY
1537 static void destroy(allocator_type& __a, _Tp* __p)
1538 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1540 _LIBCPP_INLINE_VISIBILITY
1541 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1542 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1544 _LIBCPP_INLINE_VISIBILITY
1545 static allocator_type
1546 select_on_container_copy_construction(const allocator_type& __a)
1547 {return select_on_container_copy_construction(
1548 __has_select_on_container_copy_construction<const allocator_type>(),
1551 template <class _Ptr>
1552 _LIBCPP_INLINE_VISIBILITY
1555 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1557 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1558 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1561 template <class _Tp>
1562 _LIBCPP_INLINE_VISIBILITY
1566 (is_same<allocator_type, allocator<_Tp> >::value
1567 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1568 is_trivially_move_constructible<_Tp>::value,
1571 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1573 ptrdiff_t _Np = __end1 - __begin1;
1576 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1581 template <class _Iter, class _Ptr>
1582 _LIBCPP_INLINE_VISIBILITY
1585 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1587 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1588 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1591 template <class _Tp>
1592 _LIBCPP_INLINE_VISIBILITY
1596 (is_same<allocator_type, allocator<_Tp> >::value
1597 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1598 is_trivially_move_constructible<_Tp>::value,
1601 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1603 typedef typename remove_const<_Tp>::type _Vp;
1604 ptrdiff_t _Np = __end1 - __begin1;
1607 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1612 template <class _Ptr>
1613 _LIBCPP_INLINE_VISIBILITY
1616 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1618 while (__end1 != __begin1)
1620 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1625 template <class _Tp>
1626 _LIBCPP_INLINE_VISIBILITY
1630 (is_same<allocator_type, allocator<_Tp> >::value
1631 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1632 is_trivially_move_constructible<_Tp>::value,
1635 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1637 ptrdiff_t _Np = __end1 - __begin1;
1640 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1645 _LIBCPP_INLINE_VISIBILITY
1646 static pointer allocate(allocator_type& __a, size_type __n,
1647 const_void_pointer __hint, true_type)
1648 {return __a.allocate(__n, __hint);}
1649 _LIBCPP_INLINE_VISIBILITY
1650 static pointer allocate(allocator_type& __a, size_type __n,
1651 const_void_pointer, false_type)
1652 {return __a.allocate(__n);}
1654 #ifndef _LIBCPP_HAS_NO_VARIADICS
1655 template <class _Tp, class... _Args>
1656 _LIBCPP_INLINE_VISIBILITY
1657 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1658 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1659 template <class _Tp, class... _Args>
1660 _LIBCPP_INLINE_VISIBILITY
1661 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1663 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1665 #endif // _LIBCPP_HAS_NO_VARIADICS
1667 template <class _Tp>
1668 _LIBCPP_INLINE_VISIBILITY
1669 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1671 template <class _Tp>
1672 _LIBCPP_INLINE_VISIBILITY
1673 static void __destroy(false_type, allocator_type&, _Tp* __p)
1678 _LIBCPP_INLINE_VISIBILITY
1679 static size_type __max_size(true_type, const allocator_type& __a)
1680 {return __a.max_size();}
1681 _LIBCPP_INLINE_VISIBILITY
1682 static size_type __max_size(false_type, const allocator_type&)
1683 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1685 _LIBCPP_INLINE_VISIBILITY
1686 static allocator_type
1687 select_on_container_copy_construction(true_type, const allocator_type& __a)
1688 {return __a.select_on_container_copy_construction();}
1689 _LIBCPP_INLINE_VISIBILITY
1690 static allocator_type
1691 select_on_container_copy_construction(false_type, const allocator_type& __a)
1695 template <class _Traits, class _Tp>
1696 struct __rebind_alloc_helper
1698 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1699 typedef typename _Traits::template rebind_alloc<_Tp> type;
1701 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1707 template <class _Tp>
1708 class _LIBCPP_TYPE_VIS_ONLY allocator
1711 typedef size_t size_type;
1712 typedef ptrdiff_t difference_type;
1713 typedef _Tp* pointer;
1714 typedef const _Tp* const_pointer;
1715 typedef _Tp& reference;
1716 typedef const _Tp& const_reference;
1717 typedef _Tp value_type;
1719 typedef true_type propagate_on_container_move_assignment;
1720 typedef true_type is_always_equal;
1722 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1724 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1725 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1726 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1727 {return _VSTD::addressof(__x);}
1728 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1729 {return _VSTD::addressof(__x);}
1730 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1732 if (__n > max_size())
1733 __libcpp_throw(length_error("allocator<T>::allocate(size_t n)"
1734 " 'n' exceeds maximum supported size"));
1735 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1737 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1738 {_VSTD::__deallocate((void*)__p);}
1739 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1740 {return size_type(~0) / sizeof(_Tp);}
1741 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1742 template <class _Up, class... _Args>
1743 _LIBCPP_INLINE_VISIBILITY
1745 construct(_Up* __p, _Args&&... __args)
1747 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1749 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1750 _LIBCPP_INLINE_VISIBILITY
1752 construct(pointer __p)
1754 ::new((void*)__p) _Tp();
1756 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1758 template <class _A0>
1759 _LIBCPP_INLINE_VISIBILITY
1761 construct(pointer __p, _A0& __a0)
1763 ::new((void*)__p) _Tp(__a0);
1765 template <class _A0>
1766 _LIBCPP_INLINE_VISIBILITY
1768 construct(pointer __p, const _A0& __a0)
1770 ::new((void*)__p) _Tp(__a0);
1772 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1773 template <class _A0, class _A1>
1774 _LIBCPP_INLINE_VISIBILITY
1776 construct(pointer __p, _A0& __a0, _A1& __a1)
1778 ::new((void*)__p) _Tp(__a0, __a1);
1780 template <class _A0, class _A1>
1781 _LIBCPP_INLINE_VISIBILITY
1783 construct(pointer __p, const _A0& __a0, _A1& __a1)
1785 ::new((void*)__p) _Tp(__a0, __a1);
1787 template <class _A0, class _A1>
1788 _LIBCPP_INLINE_VISIBILITY
1790 construct(pointer __p, _A0& __a0, const _A1& __a1)
1792 ::new((void*)__p) _Tp(__a0, __a1);
1794 template <class _A0, class _A1>
1795 _LIBCPP_INLINE_VISIBILITY
1797 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1799 ::new((void*)__p) _Tp(__a0, __a1);
1801 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1802 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1805 template <class _Tp>
1806 class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1809 typedef size_t size_type;
1810 typedef ptrdiff_t difference_type;
1811 typedef const _Tp* pointer;
1812 typedef const _Tp* const_pointer;
1813 typedef const _Tp& reference;
1814 typedef const _Tp& const_reference;
1815 typedef const _Tp value_type;
1817 typedef true_type propagate_on_container_move_assignment;
1818 typedef true_type is_always_equal;
1820 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1822 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1823 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1824 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1825 {return _VSTD::addressof(__x);}
1826 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1828 if (__n > max_size())
1829 __libcpp_throw(length_error("allocator<const T>::allocate(size_t n)"
1830 " 'n' exceeds maximum supported size"));
1831 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1833 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1834 {_VSTD::__deallocate((void*)__p);}
1835 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1836 {return size_type(~0) / sizeof(_Tp);}
1837 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1838 template <class _Up, class... _Args>
1839 _LIBCPP_INLINE_VISIBILITY
1841 construct(_Up* __p, _Args&&... __args)
1843 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1845 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1846 _LIBCPP_INLINE_VISIBILITY
1848 construct(pointer __p)
1850 ::new((void*)__p) _Tp();
1852 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1854 template <class _A0>
1855 _LIBCPP_INLINE_VISIBILITY
1857 construct(pointer __p, _A0& __a0)
1859 ::new((void*)__p) _Tp(__a0);
1861 template <class _A0>
1862 _LIBCPP_INLINE_VISIBILITY
1864 construct(pointer __p, const _A0& __a0)
1866 ::new((void*)__p) _Tp(__a0);
1868 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1869 template <class _A0, class _A1>
1870 _LIBCPP_INLINE_VISIBILITY
1872 construct(pointer __p, _A0& __a0, _A1& __a1)
1874 ::new((void*)__p) _Tp(__a0, __a1);
1876 template <class _A0, class _A1>
1877 _LIBCPP_INLINE_VISIBILITY
1879 construct(pointer __p, const _A0& __a0, _A1& __a1)
1881 ::new((void*)__p) _Tp(__a0, __a1);
1883 template <class _A0, class _A1>
1884 _LIBCPP_INLINE_VISIBILITY
1886 construct(pointer __p, _A0& __a0, const _A1& __a1)
1888 ::new((void*)__p) _Tp(__a0, __a1);
1890 template <class _A0, class _A1>
1891 _LIBCPP_INLINE_VISIBILITY
1893 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1895 ::new((void*)__p) _Tp(__a0, __a1);
1897 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1898 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1901 template <class _Tp, class _Up>
1902 inline _LIBCPP_INLINE_VISIBILITY
1903 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1905 template <class _Tp, class _Up>
1906 inline _LIBCPP_INLINE_VISIBILITY
1907 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1909 template <class _OutputIterator, class _Tp>
1910 class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
1911 : public iterator<output_iterator_tag,
1912 _Tp, // purposefully not C++03
1913 ptrdiff_t, // purposefully not C++03
1914 _Tp*, // purposefully not C++03
1915 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1918 _OutputIterator __x_;
1920 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1921 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1922 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1923 {::new(&*__x_) _Tp(__element); return *this;}
1924 #if _LIBCPP_STD_VER >= 14
1925 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1926 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1928 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1929 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1930 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1931 #if _LIBCPP_STD_VER >= 14
1932 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1936 template <class _Tp>
1937 pair<_Tp*, ptrdiff_t>
1938 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1940 pair<_Tp*, ptrdiff_t> __r(0, 0);
1941 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1942 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1948 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1959 template <class _Tp>
1960 inline _LIBCPP_INLINE_VISIBILITY
1961 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1963 template <class _Tp>
1970 class _LIBCPP_TYPE_VIS_ONLY auto_ptr
1975 typedef _Tp element_type;
1977 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1978 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1979 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1980 : __ptr_(__p.release()) {}
1981 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1982 {reset(__p.release()); return *this;}
1983 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1984 {reset(__p.release()); return *this;}
1985 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1986 {reset(__p.__ptr_); return *this;}
1987 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1989 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1991 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1992 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1993 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1999 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2006 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2007 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2008 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2009 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2010 {return auto_ptr<_Up>(release());}
2014 class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
2017 typedef void element_type;
2020 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
2021 typename remove_cv<_T2>::type>::value,
2022 bool = is_empty<_T1>::value
2023 && !__libcpp_is_final<_T1>::value,
2024 bool = is_empty<_T2>::value
2025 && !__libcpp_is_final<_T2>::value
2027 struct __libcpp_compressed_pair_switch;
2029 template <class _T1, class _T2, bool IsSame>
2030 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2032 template <class _T1, class _T2, bool IsSame>
2033 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2035 template <class _T1, class _T2, bool IsSame>
2036 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2038 template <class _T1, class _T2>
2039 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2041 template <class _T1, class _T2>
2042 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2044 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2045 class __libcpp_compressed_pair_imp;
2047 template <class _T1, class _T2>
2048 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2054 typedef _T1 _T1_param;
2055 typedef _T2 _T2_param;
2057 typedef typename remove_reference<_T1>::type& _T1_reference;
2058 typedef typename remove_reference<_T2>::type& _T2_reference;
2060 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2061 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2063 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
2064 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2065 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2066 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2067 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2068 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2069 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2071 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2073 _LIBCPP_INLINE_VISIBILITY
2074 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2075 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2076 is_nothrow_copy_constructible<_T2>::value)
2077 : __first_(__p.first()),
2078 __second_(__p.second()) {}
2080 _LIBCPP_INLINE_VISIBILITY
2081 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2082 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2083 is_nothrow_copy_assignable<_T2>::value)
2085 __first_ = __p.first();
2086 __second_ = __p.second();
2090 _LIBCPP_INLINE_VISIBILITY
2091 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2092 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2093 is_nothrow_move_constructible<_T2>::value)
2094 : __first_(_VSTD::forward<_T1>(__p.first())),
2095 __second_(_VSTD::forward<_T2>(__p.second())) {}
2097 _LIBCPP_INLINE_VISIBILITY
2098 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2099 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2100 is_nothrow_move_assignable<_T2>::value)
2102 __first_ = _VSTD::forward<_T1>(__p.first());
2103 __second_ = _VSTD::forward<_T2>(__p.second());
2107 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2109 #ifndef _LIBCPP_HAS_NO_VARIADICS
2111 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2112 _LIBCPP_INLINE_VISIBILITY
2113 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2114 tuple<_Args1...> __first_args,
2115 tuple<_Args2...> __second_args,
2116 __tuple_indices<_I1...>,
2117 __tuple_indices<_I2...>)
2118 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2119 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2122 #endif // _LIBCPP_HAS_NO_VARIADICS
2124 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2125 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2127 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2128 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2130 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2131 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2132 __is_nothrow_swappable<_T2>::value)
2135 swap(__first_, __x.__first_);
2136 swap(__second_, __x.__second_);
2140 template <class _T1, class _T2>
2141 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2147 typedef _T1 _T1_param;
2148 typedef _T2 _T2_param;
2150 typedef _T1& _T1_reference;
2151 typedef typename remove_reference<_T2>::type& _T2_reference;
2153 typedef const _T1& _T1_const_reference;
2154 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2156 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
2157 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2158 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2159 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2160 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2161 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2162 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2164 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2166 _LIBCPP_INLINE_VISIBILITY
2167 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2168 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2169 is_nothrow_copy_constructible<_T2>::value)
2170 : _T1(__p.first()), __second_(__p.second()) {}
2172 _LIBCPP_INLINE_VISIBILITY
2173 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2174 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2175 is_nothrow_copy_assignable<_T2>::value)
2177 _T1::operator=(__p.first());
2178 __second_ = __p.second();
2182 _LIBCPP_INLINE_VISIBILITY
2183 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2184 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2185 is_nothrow_move_constructible<_T2>::value)
2186 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2188 _LIBCPP_INLINE_VISIBILITY
2189 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2190 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2191 is_nothrow_move_assignable<_T2>::value)
2193 _T1::operator=(_VSTD::move(__p.first()));
2194 __second_ = _VSTD::forward<_T2>(__p.second());
2198 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2200 #ifndef _LIBCPP_HAS_NO_VARIADICS
2202 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2203 _LIBCPP_INLINE_VISIBILITY
2204 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2205 tuple<_Args1...> __first_args,
2206 tuple<_Args2...> __second_args,
2207 __tuple_indices<_I1...>,
2208 __tuple_indices<_I2...>)
2209 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2210 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2213 #endif // _LIBCPP_HAS_NO_VARIADICS
2215 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2216 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2218 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2219 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2221 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2222 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2223 __is_nothrow_swappable<_T2>::value)
2226 swap(__second_, __x.__second_);
2230 template <class _T1, class _T2>
2231 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2237 typedef _T1 _T1_param;
2238 typedef _T2 _T2_param;
2240 typedef typename remove_reference<_T1>::type& _T1_reference;
2241 typedef _T2& _T2_reference;
2243 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2244 typedef const _T2& _T2_const_reference;
2246 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
2247 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2248 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2249 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2250 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
2251 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2252 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2253 is_nothrow_move_constructible<_T2>::value)
2254 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2256 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2258 _LIBCPP_INLINE_VISIBILITY
2259 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2260 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2261 is_nothrow_copy_constructible<_T2>::value)
2262 : _T2(__p.second()), __first_(__p.first()) {}
2264 _LIBCPP_INLINE_VISIBILITY
2265 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2266 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2267 is_nothrow_copy_assignable<_T2>::value)
2269 _T2::operator=(__p.second());
2270 __first_ = __p.first();
2274 _LIBCPP_INLINE_VISIBILITY
2275 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2276 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2277 is_nothrow_move_constructible<_T2>::value)
2278 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2280 _LIBCPP_INLINE_VISIBILITY
2281 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2282 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2283 is_nothrow_move_assignable<_T2>::value)
2285 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2286 __first_ = _VSTD::move(__p.first());
2290 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2292 #ifndef _LIBCPP_HAS_NO_VARIADICS
2294 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2295 _LIBCPP_INLINE_VISIBILITY
2296 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2297 tuple<_Args1...> __first_args,
2298 tuple<_Args2...> __second_args,
2299 __tuple_indices<_I1...>,
2300 __tuple_indices<_I2...>)
2301 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2302 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2306 #endif // _LIBCPP_HAS_NO_VARIADICS
2308 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2309 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2311 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2312 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2314 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2315 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2316 __is_nothrow_swappable<_T2>::value)
2319 swap(__first_, __x.__first_);
2323 template <class _T1, class _T2>
2324 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2329 typedef _T1 _T1_param;
2330 typedef _T2 _T2_param;
2332 typedef _T1& _T1_reference;
2333 typedef _T2& _T2_reference;
2335 typedef const _T1& _T1_const_reference;
2336 typedef const _T2& _T2_const_reference;
2338 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2339 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2340 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2341 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2342 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2343 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2344 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2346 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2348 _LIBCPP_INLINE_VISIBILITY
2349 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2350 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2351 is_nothrow_copy_constructible<_T2>::value)
2352 : _T1(__p.first()), _T2(__p.second()) {}
2354 _LIBCPP_INLINE_VISIBILITY
2355 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2356 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2357 is_nothrow_copy_assignable<_T2>::value)
2359 _T1::operator=(__p.first());
2360 _T2::operator=(__p.second());
2364 _LIBCPP_INLINE_VISIBILITY
2365 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2366 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2367 is_nothrow_move_constructible<_T2>::value)
2368 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2370 _LIBCPP_INLINE_VISIBILITY
2371 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2372 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2373 is_nothrow_move_assignable<_T2>::value)
2375 _T1::operator=(_VSTD::move(__p.first()));
2376 _T2::operator=(_VSTD::move(__p.second()));
2380 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2382 #ifndef _LIBCPP_HAS_NO_VARIADICS
2384 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2385 _LIBCPP_INLINE_VISIBILITY
2386 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2387 tuple<_Args1...> __first_args,
2388 tuple<_Args2...> __second_args,
2389 __tuple_indices<_I1...>,
2390 __tuple_indices<_I2...>)
2391 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2392 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2395 #endif // _LIBCPP_HAS_NO_VARIADICS
2397 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2398 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2400 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2401 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2403 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2404 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2405 __is_nothrow_swappable<_T2>::value)
2410 template <class _T1, class _T2>
2411 class __compressed_pair
2412 : private __libcpp_compressed_pair_imp<_T1, _T2>
2414 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2416 typedef typename base::_T1_param _T1_param;
2417 typedef typename base::_T2_param _T2_param;
2419 typedef typename base::_T1_reference _T1_reference;
2420 typedef typename base::_T2_reference _T2_reference;
2422 typedef typename base::_T1_const_reference _T1_const_reference;
2423 typedef typename base::_T2_const_reference _T2_const_reference;
2425 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2426 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2427 : base(_VSTD::forward<_T1_param>(__t1)) {}
2428 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2429 : base(_VSTD::forward<_T2_param>(__t2)) {}
2430 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2431 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2433 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2435 _LIBCPP_INLINE_VISIBILITY
2436 __compressed_pair(const __compressed_pair& __p)
2437 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2438 is_nothrow_copy_constructible<_T2>::value)
2441 _LIBCPP_INLINE_VISIBILITY
2442 __compressed_pair& operator=(const __compressed_pair& __p)
2443 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2444 is_nothrow_copy_assignable<_T2>::value)
2446 base::operator=(__p);
2450 _LIBCPP_INLINE_VISIBILITY
2451 __compressed_pair(__compressed_pair&& __p)
2452 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2453 is_nothrow_move_constructible<_T2>::value)
2454 : base(_VSTD::move(__p)) {}
2456 _LIBCPP_INLINE_VISIBILITY
2457 __compressed_pair& operator=(__compressed_pair&& __p)
2458 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2459 is_nothrow_move_assignable<_T2>::value)
2461 base::operator=(_VSTD::move(__p));
2465 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2467 #ifndef _LIBCPP_HAS_NO_VARIADICS
2469 template <class... _Args1, class... _Args2>
2470 _LIBCPP_INLINE_VISIBILITY
2471 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2472 tuple<_Args2...> __second_args)
2473 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2474 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2475 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2478 #endif // _LIBCPP_HAS_NO_VARIADICS
2480 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2481 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2483 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2484 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2486 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2487 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2488 __is_nothrow_swappable<_T2>::value)
2492 template <class _T1, class _T2>
2493 inline _LIBCPP_INLINE_VISIBILITY
2495 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2496 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2497 __is_nothrow_swappable<_T2>::value)
2500 // __same_or_less_cv_qualified
2502 template <class _Ptr1, class _Ptr2,
2503 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2504 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2507 struct __same_or_less_cv_qualified_imp
2508 : is_convertible<_Ptr1, _Ptr2> {};
2510 template <class _Ptr1, class _Ptr2>
2511 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2514 template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2515 is_same<_Ptr1, _Ptr2>::value ||
2516 __has_element_type<_Ptr1>::value>
2517 struct __same_or_less_cv_qualified
2518 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2520 template <class _Ptr1, class _Ptr2>
2521 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2526 template <class _Tp>
2527 struct _LIBCPP_TYPE_VIS_ONLY default_delete
2529 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2530 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2532 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2534 template <class _Up>
2535 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2536 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2537 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2539 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2540 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2545 template <class _Tp>
2546 struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2549 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2550 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2552 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2554 template <class _Up>
2555 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2556 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2557 template <class _Up>
2558 _LIBCPP_INLINE_VISIBILITY
2559 void operator() (_Up* __ptr,
2560 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2562 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2563 static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
2568 template <class _Tp, class _Dp = default_delete<_Tp> >
2569 class _LIBCPP_TYPE_VIS_ONLY unique_ptr
2572 typedef _Tp element_type;
2573 typedef _Dp deleter_type;
2574 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2576 __compressed_pair<pointer, deleter_type> __ptr_;
2578 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2579 unique_ptr(unique_ptr&);
2580 template <class _Up, class _Ep>
2581 unique_ptr(unique_ptr<_Up, _Ep>&);
2582 unique_ptr& operator=(unique_ptr&);
2583 template <class _Up, class _Ep>
2584 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2585 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2587 struct __nat {int __for_bool_;};
2589 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2590 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2592 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2595 static_assert(!is_pointer<deleter_type>::value,
2596 "unique_ptr constructed with null function pointer deleter");
2598 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2601 static_assert(!is_pointer<deleter_type>::value,
2602 "unique_ptr constructed with null function pointer deleter");
2604 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2605 : __ptr_(_VSTD::move(__p))
2607 static_assert(!is_pointer<deleter_type>::value,
2608 "unique_ptr constructed with null function pointer deleter");
2611 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2612 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2613 is_reference<deleter_type>::value,
2615 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2617 : __ptr_(__p, __d) {}
2619 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2621 : __ptr_(__p, _VSTD::move(__d))
2623 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2625 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2626 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2627 template <class _Up, class _Ep>
2628 _LIBCPP_INLINE_VISIBILITY
2629 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2632 !is_array<_Up>::value &&
2633 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2634 is_convertible<_Ep, deleter_type>::value &&
2636 !is_reference<deleter_type>::value ||
2637 is_same<deleter_type, _Ep>::value
2640 >::type = __nat()) _NOEXCEPT
2641 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2643 template <class _Up>
2644 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2646 is_convertible<_Up*, _Tp*>::value &&
2647 is_same<_Dp, default_delete<_Tp> >::value,
2649 >::type = __nat()) _NOEXCEPT
2650 : __ptr_(__p.release())
2654 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2656 reset(__u.release());
2657 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2661 template <class _Up, class _Ep>
2662 _LIBCPP_INLINE_VISIBILITY
2665 !is_array<_Up>::value &&
2666 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2667 is_assignable<deleter_type&, _Ep&&>::value,
2670 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2672 reset(__u.release());
2673 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2676 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2678 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2680 return __rv<unique_ptr>(*this);
2683 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2684 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2686 template <class _Up, class _Ep>
2687 _LIBCPP_INLINE_VISIBILITY
2689 !is_array<_Up>::value &&
2690 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2691 is_assignable<deleter_type&, _Ep&>::value,
2694 operator=(unique_ptr<_Up, _Ep> __u)
2696 reset(__u.release());
2697 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2701 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2702 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2704 template <class _Up>
2705 _LIBCPP_INLINE_VISIBILITY
2707 is_convertible<_Up*, _Tp*>::value &&
2708 is_same<_Dp, default_delete<_Tp> >::value,
2711 operator=(auto_ptr<_Up> __p)
2712 {reset(__p.release()); return *this;}
2714 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2715 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2717 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2723 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2724 {return *__ptr_.first();}
2725 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2726 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2727 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2728 {return __ptr_.second();}
2729 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2730 {return __ptr_.second();}
2731 _LIBCPP_INLINE_VISIBILITY
2732 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2733 {return __ptr_.first() != nullptr;}
2735 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2737 pointer __t = __ptr_.first();
2738 __ptr_.first() = pointer();
2742 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2744 pointer __tmp = __ptr_.first();
2745 __ptr_.first() = __p;
2747 __ptr_.second()(__tmp);
2750 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2751 {__ptr_.swap(__u.__ptr_);}
2754 template <class _Tp, class _Dp>
2755 class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
2758 typedef _Tp element_type;
2759 typedef _Dp deleter_type;
2760 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2762 __compressed_pair<pointer, deleter_type> __ptr_;
2764 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2765 unique_ptr(unique_ptr&);
2766 template <class _Up>
2767 unique_ptr(unique_ptr<_Up>&);
2768 unique_ptr& operator=(unique_ptr&);
2769 template <class _Up>
2770 unique_ptr& operator=(unique_ptr<_Up>&);
2771 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2773 struct __nat {int __for_bool_;};
2775 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2776 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2778 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2781 static_assert(!is_pointer<deleter_type>::value,
2782 "unique_ptr constructed with null function pointer deleter");
2784 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2787 static_assert(!is_pointer<deleter_type>::value,
2788 "unique_ptr constructed with null function pointer deleter");
2790 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2791 template <class _Pp>
2792 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2793 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
2796 static_assert(!is_pointer<deleter_type>::value,
2797 "unique_ptr constructed with null function pointer deleter");
2800 template <class _Pp>
2801 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2802 is_reference<deleter_type>::value,
2804 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2805 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2807 : __ptr_(__p, __d) {}
2809 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2810 is_reference<deleter_type>::value,
2812 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2814 : __ptr_(pointer(), __d) {}
2816 template <class _Pp>
2817 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2818 typename remove_reference<deleter_type>::type&& __d,
2819 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2821 : __ptr_(__p, _VSTD::move(__d))
2823 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2826 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2828 : __ptr_(pointer(), _VSTD::move(__d))
2830 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2833 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2834 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2836 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2838 reset(__u.release());
2839 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2843 template <class _Up, class _Ep>
2844 _LIBCPP_INLINE_VISIBILITY
2845 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2848 is_array<_Up>::value &&
2849 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2850 && is_convertible<_Ep, deleter_type>::value &&
2852 !is_reference<deleter_type>::value ||
2853 is_same<deleter_type, _Ep>::value
2858 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2861 template <class _Up, class _Ep>
2862 _LIBCPP_INLINE_VISIBILITY
2865 is_array<_Up>::value &&
2866 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2867 is_assignable<deleter_type&, _Ep&&>::value,
2870 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2872 reset(__u.release());
2873 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2876 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2878 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2881 static_assert(!is_pointer<deleter_type>::value,
2882 "unique_ptr constructed with null function pointer deleter");
2885 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2886 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2888 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2889 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2891 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2893 return __rv<unique_ptr>(*this);
2896 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2897 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2899 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2901 reset(__u->release());
2902 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2906 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2907 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2909 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2915 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2916 {return __ptr_.first()[__i];}
2917 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2918 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2919 {return __ptr_.second();}
2920 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2921 {return __ptr_.second();}
2922 _LIBCPP_INLINE_VISIBILITY
2923 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2924 {return __ptr_.first() != nullptr;}
2926 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2928 pointer __t = __ptr_.first();
2929 __ptr_.first() = pointer();
2933 template <class _Pp>
2934 _LIBCPP_INLINE_VISIBILITY
2935 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2936 reset(_Pp __p) _NOEXCEPT
2938 pointer __tmp = __ptr_.first();
2939 __ptr_.first() = __p;
2941 __ptr_.second()(__tmp);
2943 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
2945 pointer __tmp = __ptr_.first();
2946 __ptr_.first() = nullptr;
2948 __ptr_.second()(__tmp);
2951 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2954 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2955 template <class _Up>
2956 explicit unique_ptr(_Up);
2957 template <class _Up>
2959 typename conditional<
2960 is_reference<deleter_type>::value,
2962 typename add_lvalue_reference<const deleter_type>::type>::type,
2965 is_convertible<_Up, pointer>::value,
2968 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2971 template <class _Tp, class _Dp>
2972 inline _LIBCPP_INLINE_VISIBILITY
2974 __is_swappable<_Dp>::value,
2977 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2979 template <class _T1, class _D1, class _T2, class _D2>
2980 inline _LIBCPP_INLINE_VISIBILITY
2982 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2984 template <class _T1, class _D1, class _T2, class _D2>
2985 inline _LIBCPP_INLINE_VISIBILITY
2987 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2989 template <class _T1, class _D1, class _T2, class _D2>
2990 inline _LIBCPP_INLINE_VISIBILITY
2992 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2994 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2995 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2996 typedef typename common_type<_P1, _P2>::type _Vp;
2997 return less<_Vp>()(__x.get(), __y.get());
3000 template <class _T1, class _D1, class _T2, class _D2>
3001 inline _LIBCPP_INLINE_VISIBILITY
3003 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
3005 template <class _T1, class _D1, class _T2, class _D2>
3006 inline _LIBCPP_INLINE_VISIBILITY
3008 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
3010 template <class _T1, class _D1, class _T2, class _D2>
3011 inline _LIBCPP_INLINE_VISIBILITY
3013 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
3015 template <class _T1, class _D1>
3016 inline _LIBCPP_INLINE_VISIBILITY
3018 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3023 template <class _T1, class _D1>
3024 inline _LIBCPP_INLINE_VISIBILITY
3026 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3031 template <class _T1, class _D1>
3032 inline _LIBCPP_INLINE_VISIBILITY
3034 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3036 return static_cast<bool>(__x);
3039 template <class _T1, class _D1>
3040 inline _LIBCPP_INLINE_VISIBILITY
3042 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3044 return static_cast<bool>(__x);
3047 template <class _T1, class _D1>
3048 inline _LIBCPP_INLINE_VISIBILITY
3050 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3052 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3053 return less<_P1>()(__x.get(), nullptr);
3056 template <class _T1, class _D1>
3057 inline _LIBCPP_INLINE_VISIBILITY
3059 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3061 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3062 return less<_P1>()(nullptr, __x.get());
3065 template <class _T1, class _D1>
3066 inline _LIBCPP_INLINE_VISIBILITY
3068 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3070 return nullptr < __x;
3073 template <class _T1, class _D1>
3074 inline _LIBCPP_INLINE_VISIBILITY
3076 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3078 return __x < nullptr;
3081 template <class _T1, class _D1>
3082 inline _LIBCPP_INLINE_VISIBILITY
3084 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3086 return !(nullptr < __x);
3089 template <class _T1, class _D1>
3090 inline _LIBCPP_INLINE_VISIBILITY
3092 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3094 return !(__x < nullptr);
3097 template <class _T1, class _D1>
3098 inline _LIBCPP_INLINE_VISIBILITY
3100 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3102 return !(__x < nullptr);
3105 template <class _T1, class _D1>
3106 inline _LIBCPP_INLINE_VISIBILITY
3108 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3110 return !(nullptr < __x);
3113 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3115 template <class _Tp, class _Dp>
3116 inline _LIBCPP_INLINE_VISIBILITY
3117 unique_ptr<_Tp, _Dp>
3118 move(unique_ptr<_Tp, _Dp>& __t)
3120 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3125 #if _LIBCPP_STD_VER > 11
3130 typedef unique_ptr<_Tp> __unique_single;
3134 struct __unique_if<_Tp[]>
3136 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3139 template<class _Tp, size_t _Np>
3140 struct __unique_if<_Tp[_Np]>
3142 typedef void __unique_array_known_bound;
3145 template<class _Tp, class... _Args>
3146 inline _LIBCPP_INLINE_VISIBILITY
3147 typename __unique_if<_Tp>::__unique_single
3148 make_unique(_Args&&... __args)
3150 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3154 inline _LIBCPP_INLINE_VISIBILITY
3155 typename __unique_if<_Tp>::__unique_array_unknown_bound
3156 make_unique(size_t __n)
3158 typedef typename remove_extent<_Tp>::type _Up;
3159 return unique_ptr<_Tp>(new _Up[__n]());
3162 template<class _Tp, class... _Args>
3163 typename __unique_if<_Tp>::__unique_array_known_bound
3164 make_unique(_Args&&...) = delete;
3166 #endif // _LIBCPP_STD_VER > 11
3168 template <class _Size>
3169 inline _LIBCPP_INLINE_VISIBILITY
3171 __loadword(const void* __p)
3174 std::memcpy(&__r, __p, sizeof(__r));
3178 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3179 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3180 // multiplication, which can be very slow on 32-bit systems.
3181 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3182 struct __murmur2_or_cityhash;
3184 template <class _Size>
3185 struct __murmur2_or_cityhash<_Size, 32>
3187 _Size operator()(const void* __key, _Size __len);
3191 template <class _Size>
3193 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
3195 const _Size __m = 0x5bd1e995;
3196 const _Size __r = 24;
3198 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3199 for (; __len >= 4; __data += 4, __len -= 4)
3201 _Size __k = __loadword<_Size>(__data);
3211 __h ^= __data[2] << 16;
3213 __h ^= __data[1] << 8;
3224 template <class _Size>
3225 struct __murmur2_or_cityhash<_Size, 64>
3227 _Size operator()(const void* __key, _Size __len);
3230 // Some primes between 2^63 and 2^64.
3231 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3232 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3233 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3234 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3236 static _Size __rotate(_Size __val, int __shift) {
3237 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3240 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3241 return (__val >> __shift) | (__val << (64 - __shift));
3244 static _Size __shift_mix(_Size __val) {
3245 return __val ^ (__val >> 47);
3248 static _Size __hash_len_16(_Size __u, _Size __v) {
3249 const _Size __mul = 0x9ddfea08eb382d69ULL;
3250 _Size __a = (__u ^ __v) * __mul;
3252 _Size __b = (__v ^ __a) * __mul;
3258 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3260 const _Size __a = __loadword<_Size>(__s);
3261 const _Size __b = __loadword<_Size>(__s + __len - 8);
3262 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3265 const uint32_t __a = __loadword<uint32_t>(__s);
3266 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3267 return __hash_len_16(__len + (__a << 3), __b);
3270 const unsigned char __a = __s[0];
3271 const unsigned char __b = __s[__len >> 1];
3272 const unsigned char __c = __s[__len - 1];
3273 const uint32_t __y = static_cast<uint32_t>(__a) +
3274 (static_cast<uint32_t>(__b) << 8);
3275 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3276 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3281 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3282 const _Size __a = __loadword<_Size>(__s) * __k1;
3283 const _Size __b = __loadword<_Size>(__s + 8);
3284 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3285 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3286 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3287 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3290 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3291 // Callers do best to use "random-looking" values for a and b.
3292 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3293 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3295 __b = __rotate(__b + __a + __z, 21);
3296 const _Size __c = __a;
3299 __b += __rotate(__a, 44);
3300 return pair<_Size, _Size>(__a + __z, __b + __c);
3303 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3304 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3305 const char* __s, _Size __a, _Size __b) {
3306 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3307 __loadword<_Size>(__s + 8),
3308 __loadword<_Size>(__s + 16),
3309 __loadword<_Size>(__s + 24),
3314 // Return an 8-byte hash for 33 to 64 bytes.
3315 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3316 _Size __z = __loadword<_Size>(__s + 24);
3317 _Size __a = __loadword<_Size>(__s) +
3318 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3319 _Size __b = __rotate(__a + __z, 52);
3320 _Size __c = __rotate(__a, 37);
3321 __a += __loadword<_Size>(__s + 8);
3322 __c += __rotate(__a, 7);
3323 __a += __loadword<_Size>(__s + 16);
3324 _Size __vf = __a + __z;
3325 _Size __vs = __b + __rotate(__a, 31) + __c;
3326 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3327 __z += __loadword<_Size>(__s + __len - 8);
3328 __b = __rotate(__a + __z, 52);
3329 __c = __rotate(__a, 37);
3330 __a += __loadword<_Size>(__s + __len - 24);
3331 __c += __rotate(__a, 7);
3332 __a += __loadword<_Size>(__s + __len - 16);
3333 _Size __wf = __a + __z;
3334 _Size __ws = __b + __rotate(__a, 31) + __c;
3335 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3336 return __shift_mix(__r * __k0 + __vs) * __k2;
3341 template <class _Size>
3343 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
3345 const char* __s = static_cast<const char*>(__key);
3348 return __hash_len_0_to_16(__s, __len);
3350 return __hash_len_17_to_32(__s, __len);
3352 } else if (__len <= 64) {
3353 return __hash_len_33_to_64(__s, __len);
3356 // For strings over 64 bytes we hash the end first, and then as we
3357 // loop we keep 56 bytes of state: v, w, x, y, and z.
3358 _Size __x = __loadword<_Size>(__s + __len - 40);
3359 _Size __y = __loadword<_Size>(__s + __len - 16) +
3360 __loadword<_Size>(__s + __len - 56);
3361 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3362 __loadword<_Size>(__s + __len - 24));
3363 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3364 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3365 __x = __x * __k1 + __loadword<_Size>(__s);
3367 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3368 __len = (__len - 1) & ~static_cast<_Size>(63);
3370 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3371 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3373 __y += __v.first + __loadword<_Size>(__s + 40);
3374 __z = __rotate(__z + __w.first, 33) * __k1;
3375 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3376 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3377 __y + __loadword<_Size>(__s + 16));
3378 std::swap(__z, __x);
3381 } while (__len != 0);
3382 return __hash_len_16(
3383 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3384 __hash_len_16(__v.second, __w.second) + __x);
3387 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3388 struct __scalar_hash;
3390 template <class _Tp>
3391 struct __scalar_hash<_Tp, 0>
3392 : public unary_function<_Tp, size_t>
3394 _LIBCPP_INLINE_VISIBILITY
3395 size_t operator()(_Tp __v) const _NOEXCEPT
3408 template <class _Tp>
3409 struct __scalar_hash<_Tp, 1>
3410 : public unary_function<_Tp, size_t>
3412 _LIBCPP_INLINE_VISIBILITY
3413 size_t operator()(_Tp __v) const _NOEXCEPT
3425 template <class _Tp>
3426 struct __scalar_hash<_Tp, 2>
3427 : public unary_function<_Tp, size_t>
3429 _LIBCPP_INLINE_VISIBILITY
3430 size_t operator()(_Tp __v) const _NOEXCEPT
3442 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3446 template <class _Tp>
3447 struct __scalar_hash<_Tp, 3>
3448 : public unary_function<_Tp, size_t>
3450 _LIBCPP_INLINE_VISIBILITY
3451 size_t operator()(_Tp __v) const _NOEXCEPT
3464 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3468 template <class _Tp>
3469 struct __scalar_hash<_Tp, 4>
3470 : public unary_function<_Tp, size_t>
3472 _LIBCPP_INLINE_VISIBILITY
3473 size_t operator()(_Tp __v) const _NOEXCEPT
3487 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3492 struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3493 : public unary_function<_Tp*, size_t>
3495 _LIBCPP_INLINE_VISIBILITY
3496 size_t operator()(_Tp* __v) const _NOEXCEPT
3504 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3508 template <class _Tp, class _Dp>
3509 struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
3511 typedef unique_ptr<_Tp, _Dp> argument_type;
3512 typedef size_t result_type;
3513 _LIBCPP_INLINE_VISIBILITY
3514 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3516 typedef typename argument_type::pointer pointer;
3517 return hash<pointer>()(__ptr.get());
3526 template <class _Tp>
3527 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3528 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3530 template <class _Tp>
3531 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3534 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3536 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3539 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3541 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3544 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3547 template <class _Tp>
3548 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3549 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3551 template <class _Tp>
3552 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3553 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3555 template <class _Tp>
3556 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3557 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3560 template <class _Alloc>
3561 class __allocator_destructor
3563 typedef allocator_traits<_Alloc> __alloc_traits;
3565 typedef typename __alloc_traits::pointer pointer;
3566 typedef typename __alloc_traits::size_type size_type;
3571 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3573 : __alloc_(__a), __s_(__s) {}
3574 _LIBCPP_INLINE_VISIBILITY
3575 void operator()(pointer __p) _NOEXCEPT
3576 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3579 template <class _InputIterator, class _ForwardIterator>
3581 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3583 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3584 #ifndef _LIBCPP_NO_EXCEPTIONS
3585 _ForwardIterator __s = __r;
3589 for (; __f != __l; ++__f, (void) ++__r)
3590 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3591 #ifndef _LIBCPP_NO_EXCEPTIONS
3595 for (; __s != __r; ++__s)
3603 template <class _InputIterator, class _Size, class _ForwardIterator>
3605 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3607 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3608 #ifndef _LIBCPP_NO_EXCEPTIONS
3609 _ForwardIterator __s = __r;
3613 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3614 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3615 #ifndef _LIBCPP_NO_EXCEPTIONS
3619 for (; __s != __r; ++__s)
3627 template <class _ForwardIterator, class _Tp>
3629 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3631 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3632 #ifndef _LIBCPP_NO_EXCEPTIONS
3633 _ForwardIterator __s = __f;
3637 for (; __f != __l; ++__f)
3638 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3639 #ifndef _LIBCPP_NO_EXCEPTIONS
3643 for (; __s != __f; ++__s)
3650 template <class _ForwardIterator, class _Size, class _Tp>
3652 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3654 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3655 #ifndef _LIBCPP_NO_EXCEPTIONS
3656 _ForwardIterator __s = __f;
3660 for (; __n > 0; ++__f, (void) --__n)
3661 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3662 #ifndef _LIBCPP_NO_EXCEPTIONS
3666 for (; __s != __f; ++__s)
3674 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3675 : public std::exception
3678 virtual ~bad_weak_ptr() _NOEXCEPT;
3679 virtual const char* what() const _NOEXCEPT;
3682 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3684 class _LIBCPP_TYPE_VIS __shared_count
3686 __shared_count(const __shared_count&);
3687 __shared_count& operator=(const __shared_count&);
3690 long __shared_owners_;
3691 virtual ~__shared_count();
3693 virtual void __on_zero_shared() _NOEXCEPT = 0;
3696 _LIBCPP_INLINE_VISIBILITY
3697 explicit __shared_count(long __refs = 0) _NOEXCEPT
3698 : __shared_owners_(__refs) {}
3700 void __add_shared() _NOEXCEPT;
3701 bool __release_shared() _NOEXCEPT;
3702 _LIBCPP_INLINE_VISIBILITY
3703 long use_count() const _NOEXCEPT {
3704 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3708 class _LIBCPP_TYPE_VIS __shared_weak_count
3709 : private __shared_count
3711 long __shared_weak_owners_;
3714 _LIBCPP_INLINE_VISIBILITY
3715 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3716 : __shared_count(__refs),
3717 __shared_weak_owners_(__refs) {}
3719 virtual ~__shared_weak_count();
3722 void __add_shared() _NOEXCEPT;
3723 void __add_weak() _NOEXCEPT;
3724 void __release_shared() _NOEXCEPT;
3725 void __release_weak() _NOEXCEPT;
3726 _LIBCPP_INLINE_VISIBILITY
3727 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3728 __shared_weak_count* lock() _NOEXCEPT;
3730 // Define the function out only if we build static libc++ without RTTI.
3731 // Otherwise we may break clients who need to compile their projects with
3732 // -fno-rtti and yet link against a libc++.dylib compiled
3733 // without -fno-rtti.
3734 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3735 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3738 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3741 template <class _Tp, class _Dp, class _Alloc>
3742 class __shared_ptr_pointer
3743 : public __shared_weak_count
3745 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3747 _LIBCPP_INLINE_VISIBILITY
3748 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3749 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3751 #ifndef _LIBCPP_NO_RTTI
3752 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3756 virtual void __on_zero_shared() _NOEXCEPT;
3757 virtual void __on_zero_shared_weak() _NOEXCEPT;
3760 #ifndef _LIBCPP_NO_RTTI
3762 template <class _Tp, class _Dp, class _Alloc>
3764 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3766 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
3769 #endif // _LIBCPP_NO_RTTI
3771 template <class _Tp, class _Dp, class _Alloc>
3773 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3775 __data_.first().second()(__data_.first().first());
3776 __data_.first().second().~_Dp();
3779 template <class _Tp, class _Dp, class _Alloc>
3781 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3783 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3784 typedef allocator_traits<_Al> _ATraits;
3785 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3787 _Al __a(__data_.second());
3788 __data_.second().~_Alloc();
3789 __a.deallocate(_PTraits::pointer_to(*this), 1);
3792 template <class _Tp, class _Alloc>
3793 class __shared_ptr_emplace
3794 : public __shared_weak_count
3796 __compressed_pair<_Alloc, _Tp> __data_;
3798 #ifndef _LIBCPP_HAS_NO_VARIADICS
3800 _LIBCPP_INLINE_VISIBILITY
3801 __shared_ptr_emplace(_Alloc __a)
3802 : __data_(_VSTD::move(__a)) {}
3804 template <class ..._Args>
3805 _LIBCPP_INLINE_VISIBILITY
3806 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3807 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3808 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3810 #else // _LIBCPP_HAS_NO_VARIADICS
3812 _LIBCPP_INLINE_VISIBILITY
3813 __shared_ptr_emplace(_Alloc __a)
3816 template <class _A0>
3817 _LIBCPP_INLINE_VISIBILITY
3818 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3819 : __data_(__a, _Tp(__a0)) {}
3821 template <class _A0, class _A1>
3822 _LIBCPP_INLINE_VISIBILITY
3823 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3824 : __data_(__a, _Tp(__a0, __a1)) {}
3826 template <class _A0, class _A1, class _A2>
3827 _LIBCPP_INLINE_VISIBILITY
3828 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3829 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3831 #endif // _LIBCPP_HAS_NO_VARIADICS
3834 virtual void __on_zero_shared() _NOEXCEPT;
3835 virtual void __on_zero_shared_weak() _NOEXCEPT;
3837 _LIBCPP_INLINE_VISIBILITY
3838 _Tp* get() _NOEXCEPT {return &__data_.second();}
3841 template <class _Tp, class _Alloc>
3843 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3845 __data_.second().~_Tp();
3848 template <class _Tp, class _Alloc>
3850 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3852 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3853 typedef allocator_traits<_Al> _ATraits;
3854 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3855 _Al __a(__data_.first());
3856 __data_.first().~_Alloc();
3857 __a.deallocate(_PTraits::pointer_to(*this), 1);
3860 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3863 class _LIBCPP_TYPE_VIS_ONLY shared_ptr
3866 typedef _Tp element_type;
3867 #if _LIBCPP_STD_VER > 14
3868 typedef weak_ptr<_Tp> weak_type;
3871 element_type* __ptr_;
3872 __shared_weak_count* __cntrl_;
3874 struct __nat {int __for_bool_;};
3876 _LIBCPP_INLINE_VISIBILITY
3877 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3878 _LIBCPP_INLINE_VISIBILITY
3879 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3881 explicit shared_ptr(_Yp* __p,
3882 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3883 template<class _Yp, class _Dp>
3884 shared_ptr(_Yp* __p, _Dp __d,
3885 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3886 template<class _Yp, class _Dp, class _Alloc>
3887 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3888 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3889 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3890 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3891 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3892 _LIBCPP_INLINE_VISIBILITY
3893 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3895 _LIBCPP_INLINE_VISIBILITY
3896 shared_ptr(const shared_ptr<_Yp>& __r,
3897 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3899 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3900 _LIBCPP_INLINE_VISIBILITY
3901 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3902 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3903 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3905 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3906 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3907 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3908 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3910 shared_ptr(auto_ptr<_Yp>&& __r,
3911 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3914 shared_ptr(auto_ptr<_Yp> __r,
3915 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3917 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3918 template <class _Yp, class _Dp>
3919 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3922 !is_lvalue_reference<_Dp>::value &&
3923 !is_array<_Yp>::value &&
3924 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3927 template <class _Yp, class _Dp>
3928 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3931 is_lvalue_reference<_Dp>::value &&
3932 !is_array<_Yp>::value &&
3933 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3936 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3937 template <class _Yp, class _Dp>
3938 shared_ptr(unique_ptr<_Yp, _Dp>,
3941 !is_lvalue_reference<_Dp>::value &&
3942 !is_array<_Yp>::value &&
3943 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3946 template <class _Yp, class _Dp>
3947 shared_ptr(unique_ptr<_Yp, _Dp>,
3950 is_lvalue_reference<_Dp>::value &&
3951 !is_array<_Yp>::value &&
3952 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3955 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3959 _LIBCPP_INLINE_VISIBILITY
3960 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3964 is_convertible<_Yp*, element_type*>::value,
3967 _LIBCPP_INLINE_VISIBILITY
3968 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3969 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3970 _LIBCPP_INLINE_VISIBILITY
3971 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3975 is_convertible<_Yp*, element_type*>::value,
3978 _LIBCPP_INLINE_VISIBILITY
3979 operator=(shared_ptr<_Yp>&& __r);
3981 _LIBCPP_INLINE_VISIBILITY
3984 !is_array<_Yp>::value &&
3985 is_convertible<_Yp*, element_type*>::value,
3988 operator=(auto_ptr<_Yp>&& __r);
3989 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3991 _LIBCPP_INLINE_VISIBILITY
3994 !is_array<_Yp>::value &&
3995 is_convertible<_Yp*, element_type*>::value,
3998 operator=(auto_ptr<_Yp> __r);
4000 template <class _Yp, class _Dp>
4003 !is_array<_Yp>::value &&
4004 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4007 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4008 _LIBCPP_INLINE_VISIBILITY
4009 operator=(unique_ptr<_Yp, _Dp>&& __r);
4010 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4011 _LIBCPP_INLINE_VISIBILITY
4012 operator=(unique_ptr<_Yp, _Dp> __r);
4015 _LIBCPP_INLINE_VISIBILITY
4016 void swap(shared_ptr& __r) _NOEXCEPT;
4017 _LIBCPP_INLINE_VISIBILITY
4018 void reset() _NOEXCEPT;
4022 is_convertible<_Yp*, element_type*>::value,
4025 _LIBCPP_INLINE_VISIBILITY
4027 template<class _Yp, class _Dp>
4030 is_convertible<_Yp*, element_type*>::value,
4033 _LIBCPP_INLINE_VISIBILITY
4034 reset(_Yp* __p, _Dp __d);
4035 template<class _Yp, class _Dp, class _Alloc>
4038 is_convertible<_Yp*, element_type*>::value,
4041 _LIBCPP_INLINE_VISIBILITY
4042 reset(_Yp* __p, _Dp __d, _Alloc __a);
4044 _LIBCPP_INLINE_VISIBILITY
4045 element_type* get() const _NOEXCEPT {return __ptr_;}
4046 _LIBCPP_INLINE_VISIBILITY
4047 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4049 _LIBCPP_INLINE_VISIBILITY
4050 element_type* operator->() const _NOEXCEPT {return __ptr_;}
4051 _LIBCPP_INLINE_VISIBILITY
4052 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4053 _LIBCPP_INLINE_VISIBILITY
4054 bool unique() const _NOEXCEPT {return use_count() == 1;}
4055 _LIBCPP_INLINE_VISIBILITY
4056 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4057 template <class _Up>
4058 _LIBCPP_INLINE_VISIBILITY
4059 bool owner_before(shared_ptr<_Up> const& __p) const
4060 {return __cntrl_ < __p.__cntrl_;}
4061 template <class _Up>
4062 _LIBCPP_INLINE_VISIBILITY
4063 bool owner_before(weak_ptr<_Up> const& __p) const
4064 {return __cntrl_ < __p.__cntrl_;}
4065 _LIBCPP_INLINE_VISIBILITY
4067 __owner_equivalent(const shared_ptr& __p) const
4068 {return __cntrl_ == __p.__cntrl_;}
4070 #ifndef _LIBCPP_NO_RTTI
4071 template <class _Dp>
4072 _LIBCPP_INLINE_VISIBILITY
4073 _Dp* __get_deleter() const _NOEXCEPT
4074 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4075 #endif // _LIBCPP_NO_RTTI
4077 #ifndef _LIBCPP_HAS_NO_VARIADICS
4079 template<class ..._Args>
4082 make_shared(_Args&& ...__args);
4084 template<class _Alloc, class ..._Args>
4087 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4089 #else // _LIBCPP_HAS_NO_VARIADICS
4091 static shared_ptr<_Tp> make_shared();
4094 static shared_ptr<_Tp> make_shared(_A0&);
4096 template<class _A0, class _A1>
4097 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4099 template<class _A0, class _A1, class _A2>
4100 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4102 template<class _Alloc>
4103 static shared_ptr<_Tp>
4104 allocate_shared(const _Alloc& __a);
4106 template<class _Alloc, class _A0>
4107 static shared_ptr<_Tp>
4108 allocate_shared(const _Alloc& __a, _A0& __a0);
4110 template<class _Alloc, class _A0, class _A1>
4111 static shared_ptr<_Tp>
4112 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4114 template<class _Alloc, class _A0, class _A1, class _A2>
4115 static shared_ptr<_Tp>
4116 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4118 #endif // _LIBCPP_HAS_NO_VARIADICS
4122 template <class _Yp, class _OrigPtr>
4123 _LIBCPP_INLINE_VISIBILITY
4125 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4126 _OrigPtr* __ptr) _NOEXCEPT
4128 typedef typename remove_cv<_Yp>::type _RawYp;
4129 if (__e && __e->__weak_this_.expired())
4131 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4132 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
4136 _LIBCPP_INLINE_VISIBILITY
4137 void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {}
4139 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4140 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4146 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4155 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4163 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4164 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4167 unique_ptr<_Yp> __hold(__p);
4168 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4169 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4171 __enable_weak_this(__p, __p);
4175 template<class _Yp, class _Dp>
4176 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4177 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4180 #ifndef _LIBCPP_NO_EXCEPTIONS
4183 #endif // _LIBCPP_NO_EXCEPTIONS
4184 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4185 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4186 __enable_weak_this(__p, __p);
4187 #ifndef _LIBCPP_NO_EXCEPTIONS
4194 #endif // _LIBCPP_NO_EXCEPTIONS
4199 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4202 #ifndef _LIBCPP_NO_EXCEPTIONS
4205 #endif // _LIBCPP_NO_EXCEPTIONS
4206 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4207 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4208 #ifndef _LIBCPP_NO_EXCEPTIONS
4215 #endif // _LIBCPP_NO_EXCEPTIONS
4219 template<class _Yp, class _Dp, class _Alloc>
4220 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4221 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4224 #ifndef _LIBCPP_NO_EXCEPTIONS
4227 #endif // _LIBCPP_NO_EXCEPTIONS
4228 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4229 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4230 typedef __allocator_destructor<_A2> _D2;
4232 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4233 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4234 _CntrlBlk(__p, __d, __a);
4235 __cntrl_ = _VSTD::addressof(*__hold2.release());
4236 __enable_weak_this(__p, __p);
4237 #ifndef _LIBCPP_NO_EXCEPTIONS
4244 #endif // _LIBCPP_NO_EXCEPTIONS
4248 template<class _Dp, class _Alloc>
4249 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4252 #ifndef _LIBCPP_NO_EXCEPTIONS
4255 #endif // _LIBCPP_NO_EXCEPTIONS
4256 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4257 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4258 typedef __allocator_destructor<_A2> _D2;
4260 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4261 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4262 _CntrlBlk(__p, __d, __a);
4263 __cntrl_ = _VSTD::addressof(*__hold2.release());
4264 #ifndef _LIBCPP_NO_EXCEPTIONS
4271 #endif // _LIBCPP_NO_EXCEPTIONS
4277 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4279 __cntrl_(__r.__cntrl_)
4282 __cntrl_->__add_shared();
4287 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4288 : __ptr_(__r.__ptr_),
4289 __cntrl_(__r.__cntrl_)
4292 __cntrl_->__add_shared();
4298 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4299 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4301 : __ptr_(__r.__ptr_),
4302 __cntrl_(__r.__cntrl_)
4305 __cntrl_->__add_shared();
4308 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4312 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4313 : __ptr_(__r.__ptr_),
4314 __cntrl_(__r.__cntrl_)
4323 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4324 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4326 : __ptr_(__r.__ptr_),
4327 __cntrl_(__r.__cntrl_)
4333 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4337 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4338 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4340 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4342 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4345 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4346 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4347 __enable_weak_this(__r.get(), __r.get());
4352 template <class _Yp, class _Dp>
4353 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4354 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4356 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4360 !is_lvalue_reference<_Dp>::value &&
4361 !is_array<_Yp>::value &&
4362 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4367 #if _LIBCPP_STD_VER > 11
4368 if (__ptr_ == nullptr)
4373 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4374 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4375 __enable_weak_this(__r.get(), __r.get());
4381 template <class _Yp, class _Dp>
4382 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4383 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4385 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4389 is_lvalue_reference<_Dp>::value &&
4390 !is_array<_Yp>::value &&
4391 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4396 #if _LIBCPP_STD_VER > 11
4397 if (__ptr_ == nullptr)
4402 typedef __shared_ptr_pointer<_Yp*,
4403 reference_wrapper<typename remove_reference<_Dp>::type>,
4404 allocator<_Yp> > _CntrlBlk;
4405 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4406 __enable_weak_this(__r.get(), __r.get());
4411 #ifndef _LIBCPP_HAS_NO_VARIADICS
4414 template<class ..._Args>
4416 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4418 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4419 typedef allocator<_CntrlBlk> _A2;
4420 typedef __allocator_destructor<_A2> _D2;
4422 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4423 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4424 shared_ptr<_Tp> __r;
4425 __r.__ptr_ = __hold2.get()->get();
4426 __r.__cntrl_ = __hold2.release();
4427 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4432 template<class _Alloc, class ..._Args>
4434 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4436 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4437 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4438 typedef __allocator_destructor<_A2> _D2;
4440 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4441 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4442 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4443 shared_ptr<_Tp> __r;
4444 __r.__ptr_ = __hold2.get()->get();
4445 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4446 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4450 #else // _LIBCPP_HAS_NO_VARIADICS
4454 shared_ptr<_Tp>::make_shared()
4456 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4457 typedef allocator<_CntrlBlk> _Alloc2;
4458 typedef __allocator_destructor<_Alloc2> _D2;
4460 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4461 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4462 shared_ptr<_Tp> __r;
4463 __r.__ptr_ = __hold2.get()->get();
4464 __r.__cntrl_ = __hold2.release();
4465 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4472 shared_ptr<_Tp>::make_shared(_A0& __a0)
4474 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4475 typedef allocator<_CntrlBlk> _Alloc2;
4476 typedef __allocator_destructor<_Alloc2> _D2;
4478 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4479 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4480 shared_ptr<_Tp> __r;
4481 __r.__ptr_ = __hold2.get()->get();
4482 __r.__cntrl_ = __hold2.release();
4483 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4488 template<class _A0, class _A1>
4490 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4492 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4493 typedef allocator<_CntrlBlk> _Alloc2;
4494 typedef __allocator_destructor<_Alloc2> _D2;
4496 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4497 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4498 shared_ptr<_Tp> __r;
4499 __r.__ptr_ = __hold2.get()->get();
4500 __r.__cntrl_ = __hold2.release();
4501 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4506 template<class _A0, class _A1, class _A2>
4508 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4510 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4511 typedef allocator<_CntrlBlk> _Alloc2;
4512 typedef __allocator_destructor<_Alloc2> _D2;
4514 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4515 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4516 shared_ptr<_Tp> __r;
4517 __r.__ptr_ = __hold2.get()->get();
4518 __r.__cntrl_ = __hold2.release();
4519 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4524 template<class _Alloc>
4526 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4528 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4529 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4530 typedef __allocator_destructor<_Alloc2> _D2;
4531 _Alloc2 __alloc2(__a);
4532 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4533 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4535 shared_ptr<_Tp> __r;
4536 __r.__ptr_ = __hold2.get()->get();
4537 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4538 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4543 template<class _Alloc, class _A0>
4545 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4547 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4548 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4549 typedef __allocator_destructor<_Alloc2> _D2;
4550 _Alloc2 __alloc2(__a);
4551 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4552 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4553 _CntrlBlk(__a, __a0);
4554 shared_ptr<_Tp> __r;
4555 __r.__ptr_ = __hold2.get()->get();
4556 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4557 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4562 template<class _Alloc, class _A0, class _A1>
4564 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4566 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4567 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4568 typedef __allocator_destructor<_Alloc2> _D2;
4569 _Alloc2 __alloc2(__a);
4570 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4571 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4572 _CntrlBlk(__a, __a0, __a1);
4573 shared_ptr<_Tp> __r;
4574 __r.__ptr_ = __hold2.get()->get();
4575 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4576 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4581 template<class _Alloc, class _A0, class _A1, class _A2>
4583 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4585 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4586 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4587 typedef __allocator_destructor<_Alloc2> _D2;
4588 _Alloc2 __alloc2(__a);
4589 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4590 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4591 _CntrlBlk(__a, __a0, __a1, __a2);
4592 shared_ptr<_Tp> __r;
4593 __r.__ptr_ = __hold2.get()->get();
4594 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4595 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4599 #endif // _LIBCPP_HAS_NO_VARIADICS
4602 shared_ptr<_Tp>::~shared_ptr()
4605 __cntrl_->__release_shared();
4611 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4613 shared_ptr(__r).swap(*this);
4622 is_convertible<_Yp*, _Tp*>::value,
4625 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4627 shared_ptr(__r).swap(*this);
4631 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4636 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4638 shared_ptr(_VSTD::move(__r)).swap(*this);
4647 is_convertible<_Yp*, _Tp*>::value,
4650 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4652 shared_ptr(_VSTD::move(__r)).swap(*this);
4661 !is_array<_Yp>::value &&
4662 is_convertible<_Yp*, _Tp*>::value,
4665 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4667 shared_ptr(_VSTD::move(__r)).swap(*this);
4672 template <class _Yp, class _Dp>
4676 !is_array<_Yp>::value &&
4677 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4680 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4682 shared_ptr(_VSTD::move(__r)).swap(*this);
4686 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4690 inline _LIBCPP_INLINE_VISIBILITY
4693 !is_array<_Yp>::value &&
4694 is_convertible<_Yp*, _Tp*>::value,
4697 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4699 shared_ptr(__r).swap(*this);
4704 template <class _Yp, class _Dp>
4705 inline _LIBCPP_INLINE_VISIBILITY
4708 !is_array<_Yp>::value &&
4709 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4712 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4714 shared_ptr(_VSTD::move(__r)).swap(*this);
4718 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4723 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4725 _VSTD::swap(__ptr_, __r.__ptr_);
4726 _VSTD::swap(__cntrl_, __r.__cntrl_);
4732 shared_ptr<_Tp>::reset() _NOEXCEPT
4734 shared_ptr().swap(*this);
4742 is_convertible<_Yp*, _Tp*>::value,
4745 shared_ptr<_Tp>::reset(_Yp* __p)
4747 shared_ptr(__p).swap(*this);
4751 template<class _Yp, class _Dp>
4755 is_convertible<_Yp*, _Tp*>::value,
4758 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4760 shared_ptr(__p, __d).swap(*this);
4764 template<class _Yp, class _Dp, class _Alloc>
4768 is_convertible<_Yp*, _Tp*>::value,
4771 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4773 shared_ptr(__p, __d, __a).swap(*this);
4776 #ifndef _LIBCPP_HAS_NO_VARIADICS
4778 template<class _Tp, class ..._Args>
4779 inline _LIBCPP_INLINE_VISIBILITY
4782 !is_array<_Tp>::value,
4785 make_shared(_Args&& ...__args)
4787 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4790 template<class _Tp, class _Alloc, class ..._Args>
4791 inline _LIBCPP_INLINE_VISIBILITY
4794 !is_array<_Tp>::value,
4797 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4799 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4802 #else // _LIBCPP_HAS_NO_VARIADICS
4805 inline _LIBCPP_INLINE_VISIBILITY
4809 return shared_ptr<_Tp>::make_shared();
4812 template<class _Tp, class _A0>
4813 inline _LIBCPP_INLINE_VISIBILITY
4815 make_shared(_A0& __a0)
4817 return shared_ptr<_Tp>::make_shared(__a0);
4820 template<class _Tp, class _A0, class _A1>
4821 inline _LIBCPP_INLINE_VISIBILITY
4823 make_shared(_A0& __a0, _A1& __a1)
4825 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4828 template<class _Tp, class _A0, class _A1, class _A2>
4829 inline _LIBCPP_INLINE_VISIBILITY
4831 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4833 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4836 template<class _Tp, class _Alloc>
4837 inline _LIBCPP_INLINE_VISIBILITY
4839 allocate_shared(const _Alloc& __a)
4841 return shared_ptr<_Tp>::allocate_shared(__a);
4844 template<class _Tp, class _Alloc, class _A0>
4845 inline _LIBCPP_INLINE_VISIBILITY
4847 allocate_shared(const _Alloc& __a, _A0& __a0)
4849 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4852 template<class _Tp, class _Alloc, class _A0, class _A1>
4853 inline _LIBCPP_INLINE_VISIBILITY
4855 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4857 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4860 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4861 inline _LIBCPP_INLINE_VISIBILITY
4863 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4865 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4868 #endif // _LIBCPP_HAS_NO_VARIADICS
4870 template<class _Tp, class _Up>
4871 inline _LIBCPP_INLINE_VISIBILITY
4873 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4875 return __x.get() == __y.get();
4878 template<class _Tp, class _Up>
4879 inline _LIBCPP_INLINE_VISIBILITY
4881 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4883 return !(__x == __y);
4886 template<class _Tp, class _Up>
4887 inline _LIBCPP_INLINE_VISIBILITY
4889 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4891 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4892 return less<_Vp>()(__x.get(), __y.get());
4895 template<class _Tp, class _Up>
4896 inline _LIBCPP_INLINE_VISIBILITY
4898 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4903 template<class _Tp, class _Up>
4904 inline _LIBCPP_INLINE_VISIBILITY
4906 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4908 return !(__y < __x);
4911 template<class _Tp, class _Up>
4912 inline _LIBCPP_INLINE_VISIBILITY
4914 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4916 return !(__x < __y);
4920 inline _LIBCPP_INLINE_VISIBILITY
4922 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4928 inline _LIBCPP_INLINE_VISIBILITY
4930 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4936 inline _LIBCPP_INLINE_VISIBILITY
4938 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4940 return static_cast<bool>(__x);
4944 inline _LIBCPP_INLINE_VISIBILITY
4946 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4948 return static_cast<bool>(__x);
4952 inline _LIBCPP_INLINE_VISIBILITY
4954 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4956 return less<_Tp*>()(__x.get(), nullptr);
4960 inline _LIBCPP_INLINE_VISIBILITY
4962 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4964 return less<_Tp*>()(nullptr, __x.get());
4968 inline _LIBCPP_INLINE_VISIBILITY
4970 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4972 return nullptr < __x;
4976 inline _LIBCPP_INLINE_VISIBILITY
4978 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4980 return __x < nullptr;
4984 inline _LIBCPP_INLINE_VISIBILITY
4986 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4988 return !(nullptr < __x);
4992 inline _LIBCPP_INLINE_VISIBILITY
4994 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4996 return !(__x < nullptr);
5000 inline _LIBCPP_INLINE_VISIBILITY
5002 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5004 return !(__x < nullptr);
5008 inline _LIBCPP_INLINE_VISIBILITY
5010 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5012 return !(nullptr < __x);
5016 inline _LIBCPP_INLINE_VISIBILITY
5018 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
5023 template<class _Tp, class _Up>
5024 inline _LIBCPP_INLINE_VISIBILITY
5027 !is_array<_Tp>::value && !is_array<_Up>::value,
5030 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5032 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
5035 template<class _Tp, class _Up>
5036 inline _LIBCPP_INLINE_VISIBILITY
5039 !is_array<_Tp>::value && !is_array<_Up>::value,
5042 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5044 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5045 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5048 template<class _Tp, class _Up>
5051 is_array<_Tp>::value == is_array<_Up>::value,
5054 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5056 typedef typename remove_extent<_Tp>::type _RTp;
5057 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
5060 #ifndef _LIBCPP_NO_RTTI
5062 template<class _Dp, class _Tp>
5063 inline _LIBCPP_INLINE_VISIBILITY
5065 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
5067 return __p.template __get_deleter<_Dp>();
5070 #endif // _LIBCPP_NO_RTTI
5073 class _LIBCPP_TYPE_VIS_ONLY weak_ptr
5076 typedef _Tp element_type;
5078 element_type* __ptr_;
5079 __shared_weak_count* __cntrl_;
5082 _LIBCPP_INLINE_VISIBILITY
5083 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
5084 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
5085 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5087 _LIBCPP_INLINE_VISIBILITY
5088 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
5089 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
5090 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5093 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5094 _LIBCPP_INLINE_VISIBILITY
5095 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5096 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
5097 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5099 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5102 _LIBCPP_INLINE_VISIBILITY
5103 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5107 is_convertible<_Yp*, element_type*>::value,
5110 _LIBCPP_INLINE_VISIBILITY
5111 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5113 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5115 _LIBCPP_INLINE_VISIBILITY
5116 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5120 is_convertible<_Yp*, element_type*>::value,
5123 _LIBCPP_INLINE_VISIBILITY
5124 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5126 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5131 is_convertible<_Yp*, element_type*>::value,
5134 _LIBCPP_INLINE_VISIBILITY
5135 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5137 _LIBCPP_INLINE_VISIBILITY
5138 void swap(weak_ptr& __r) _NOEXCEPT;
5139 _LIBCPP_INLINE_VISIBILITY
5140 void reset() _NOEXCEPT;
5142 _LIBCPP_INLINE_VISIBILITY
5143 long use_count() const _NOEXCEPT
5144 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5145 _LIBCPP_INLINE_VISIBILITY
5146 bool expired() const _NOEXCEPT
5147 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5148 shared_ptr<_Tp> lock() const _NOEXCEPT;
5150 _LIBCPP_INLINE_VISIBILITY
5151 bool owner_before(const shared_ptr<_Up>& __r) const
5152 {return __cntrl_ < __r.__cntrl_;}
5154 _LIBCPP_INLINE_VISIBILITY
5155 bool owner_before(const weak_ptr<_Up>& __r) const
5156 {return __cntrl_ < __r.__cntrl_;}
5158 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5159 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
5165 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5173 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5174 : __ptr_(__r.__ptr_),
5175 __cntrl_(__r.__cntrl_)
5178 __cntrl_->__add_weak();
5184 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5185 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5187 : __ptr_(__r.__ptr_),
5188 __cntrl_(__r.__cntrl_)
5191 __cntrl_->__add_weak();
5197 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5198 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5200 : __ptr_(__r.__ptr_),
5201 __cntrl_(__r.__cntrl_)
5204 __cntrl_->__add_weak();
5207 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5211 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5212 : __ptr_(__r.__ptr_),
5213 __cntrl_(__r.__cntrl_)
5222 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5223 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5225 : __ptr_(__r.__ptr_),
5226 __cntrl_(__r.__cntrl_)
5232 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5235 weak_ptr<_Tp>::~weak_ptr()
5238 __cntrl_->__release_weak();
5244 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5246 weak_ptr(__r).swap(*this);
5255 is_convertible<_Yp*, _Tp*>::value,
5258 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5260 weak_ptr(__r).swap(*this);
5264 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5269 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5271 weak_ptr(_VSTD::move(__r)).swap(*this);
5280 is_convertible<_Yp*, _Tp*>::value,
5283 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5285 weak_ptr(_VSTD::move(__r)).swap(*this);
5289 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5296 is_convertible<_Yp*, _Tp*>::value,
5299 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5301 weak_ptr(__r).swap(*this);
5308 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5310 _VSTD::swap(__ptr_, __r.__ptr_);
5311 _VSTD::swap(__cntrl_, __r.__cntrl_);
5315 inline _LIBCPP_INLINE_VISIBILITY
5317 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5325 weak_ptr<_Tp>::reset() _NOEXCEPT
5327 weak_ptr().swap(*this);
5332 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5333 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5334 : __ptr_(__r.__ptr_),
5335 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5338 #ifndef _LIBCPP_NO_EXCEPTIONS
5339 throw bad_weak_ptr();
5341 assert(!"bad_weak_ptr");
5347 weak_ptr<_Tp>::lock() const _NOEXCEPT
5349 shared_ptr<_Tp> __r;
5350 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5352 __r.__ptr_ = __ptr_;
5356 #if _LIBCPP_STD_VER > 14
5357 template <class _Tp = void> struct owner_less;
5359 template <class _Tp> struct owner_less;
5362 template <class _Tp>
5363 struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
5364 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5366 typedef bool result_type;
5367 _LIBCPP_INLINE_VISIBILITY
5368 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5369 {return __x.owner_before(__y);}
5370 _LIBCPP_INLINE_VISIBILITY
5371 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5372 {return __x.owner_before(__y);}
5373 _LIBCPP_INLINE_VISIBILITY
5374 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5375 {return __x.owner_before(__y);}
5378 template <class _Tp>
5379 struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
5380 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5382 typedef bool result_type;
5383 _LIBCPP_INLINE_VISIBILITY
5384 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5385 {return __x.owner_before(__y);}
5386 _LIBCPP_INLINE_VISIBILITY
5387 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5388 {return __x.owner_before(__y);}
5389 _LIBCPP_INLINE_VISIBILITY
5390 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5391 {return __x.owner_before(__y);}
5394 #if _LIBCPP_STD_VER > 14
5396 struct _LIBCPP_TYPE_VIS_ONLY owner_less<void>
5398 template <class _Tp, class _Up>
5399 _LIBCPP_INLINE_VISIBILITY
5400 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5401 {return __x.owner_before(__y);}
5402 template <class _Tp, class _Up>
5403 _LIBCPP_INLINE_VISIBILITY
5404 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5405 {return __x.owner_before(__y);}
5406 template <class _Tp, class _Up>
5407 _LIBCPP_INLINE_VISIBILITY
5408 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5409 {return __x.owner_before(__y);}
5410 template <class _Tp, class _Up>
5411 _LIBCPP_INLINE_VISIBILITY
5412 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5413 {return __x.owner_before(__y);}
5414 typedef void is_transparent;
5419 class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5421 mutable weak_ptr<_Tp> __weak_this_;
5423 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5424 enable_shared_from_this() _NOEXCEPT {}
5425 _LIBCPP_INLINE_VISIBILITY
5426 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5427 _LIBCPP_INLINE_VISIBILITY
5428 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5430 _LIBCPP_INLINE_VISIBILITY
5431 ~enable_shared_from_this() {}
5433 _LIBCPP_INLINE_VISIBILITY
5434 shared_ptr<_Tp> shared_from_this()
5435 {return shared_ptr<_Tp>(__weak_this_);}
5436 _LIBCPP_INLINE_VISIBILITY
5437 shared_ptr<_Tp const> shared_from_this() const
5438 {return shared_ptr<const _Tp>(__weak_this_);}
5440 #if _LIBCPP_STD_VER > 14
5441 _LIBCPP_INLINE_VISIBILITY
5442 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5443 { return __weak_this_; }
5445 _LIBCPP_INLINE_VISIBILITY
5446 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5447 { return __weak_this_; }
5448 #endif // _LIBCPP_STD_VER > 14
5450 template <class _Up> friend class shared_ptr;
5453 template <class _Tp>
5454 struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
5456 typedef shared_ptr<_Tp> argument_type;
5457 typedef size_t result_type;
5458 _LIBCPP_INLINE_VISIBILITY
5459 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5461 return hash<_Tp*>()(__ptr.get());
5465 template<class _CharT, class _Traits, class _Yp>
5466 inline _LIBCPP_INLINE_VISIBILITY
5467 basic_ostream<_CharT, _Traits>&
5468 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5471 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5473 class _LIBCPP_TYPE_VIS __sp_mut
5477 void lock() _NOEXCEPT;
5478 void unlock() _NOEXCEPT;
5481 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5482 __sp_mut(const __sp_mut&);
5483 __sp_mut& operator=(const __sp_mut&);
5485 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5488 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5490 template <class _Tp>
5491 inline _LIBCPP_INLINE_VISIBILITY
5493 atomic_is_lock_free(const shared_ptr<_Tp>*)
5498 template <class _Tp>
5500 atomic_load(const shared_ptr<_Tp>* __p)
5502 __sp_mut& __m = __get_sp_mut(__p);
5504 shared_ptr<_Tp> __q = *__p;
5509 template <class _Tp>
5510 inline _LIBCPP_INLINE_VISIBILITY
5512 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5514 return atomic_load(__p);
5517 template <class _Tp>
5519 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5521 __sp_mut& __m = __get_sp_mut(__p);
5527 template <class _Tp>
5528 inline _LIBCPP_INLINE_VISIBILITY
5530 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5532 atomic_store(__p, __r);
5535 template <class _Tp>
5537 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5539 __sp_mut& __m = __get_sp_mut(__p);
5546 template <class _Tp>
5547 inline _LIBCPP_INLINE_VISIBILITY
5549 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5551 return atomic_exchange(__p, __r);
5554 template <class _Tp>
5556 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5558 shared_ptr<_Tp> __temp;
5559 __sp_mut& __m = __get_sp_mut(__p);
5561 if (__p->__owner_equivalent(*__v))
5563 _VSTD::swap(__temp, *__p);
5568 _VSTD::swap(__temp, *__v);
5574 template <class _Tp>
5575 inline _LIBCPP_INLINE_VISIBILITY
5577 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5579 return atomic_compare_exchange_strong(__p, __v, __w);
5582 template <class _Tp>
5583 inline _LIBCPP_INLINE_VISIBILITY
5585 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5586 shared_ptr<_Tp> __w, memory_order, memory_order)
5588 return atomic_compare_exchange_strong(__p, __v, __w);
5591 template <class _Tp>
5592 inline _LIBCPP_INLINE_VISIBILITY
5594 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5595 shared_ptr<_Tp> __w, memory_order, memory_order)
5597 return atomic_compare_exchange_weak(__p, __v, __w);
5600 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5603 struct _LIBCPP_TYPE_VIS pointer_safety
5614 _LIBCPP_INLINE_VISIBILITY
5615 pointer_safety(__lx __v) : __v_(__v) {}
5616 _LIBCPP_INLINE_VISIBILITY
5617 operator int() const {return __v_;}
5620 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5621 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5622 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5623 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5624 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5626 template <class _Tp>
5627 inline _LIBCPP_INLINE_VISIBILITY
5629 undeclare_reachable(_Tp* __p)
5631 return static_cast<_Tp*>(__undeclare_reachable(__p));
5634 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5636 // --- Helper for container swap --
5637 template <typename _Alloc>
5638 inline _LIBCPP_INLINE_VISIBILITY
5639 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5640 #if _LIBCPP_STD_VER >= 14
5643 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5646 __swap_allocator(__a1, __a2,
5647 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5650 template <typename _Alloc>
5651 _LIBCPP_INLINE_VISIBILITY
5652 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5653 #if _LIBCPP_STD_VER >= 14
5656 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5663 template <typename _Alloc>
5664 inline _LIBCPP_INLINE_VISIBILITY
5665 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5667 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5668 struct __noexcept_move_assign_container : public integral_constant<bool,
5669 _Traits::propagate_on_container_move_assignment::value
5670 #if _LIBCPP_STD_VER > 14
5671 || _Traits::is_always_equal::value
5673 && is_nothrow_move_assignable<_Alloc>::value
5678 #ifndef _LIBCPP_HAS_NO_VARIADICS
5679 template <class _Tp, class _Alloc>
5680 struct __temp_value {
5681 typedef allocator_traits<_Alloc> _Traits;
5683 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5686 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5687 _Tp & get() { return *__addr(); }
5689 template<class... _Args>
5690 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5691 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5693 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5697 _LIBCPP_END_NAMESPACE_STD
5699 #endif // _LIBCPP_MEMORY