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;
366 constexpr shared_ptr() noexcept;
367 template<class Y> explicit shared_ptr(Y* p);
368 template<class Y, class D> shared_ptr(Y* p, D d);
369 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
370 template <class D> shared_ptr(nullptr_t p, D d);
371 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
372 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
373 shared_ptr(const shared_ptr& r) noexcept;
374 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
375 shared_ptr(shared_ptr&& r) noexcept;
376 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
377 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
378 template<class Y> shared_ptr(auto_ptr<Y>&& r);
379 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
380 shared_ptr(nullptr_t) : shared_ptr() { }
386 shared_ptr& operator=(const shared_ptr& r) noexcept;
387 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
388 shared_ptr& operator=(shared_ptr&& r) noexcept;
389 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
390 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
391 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
394 void swap(shared_ptr& r) noexcept;
395 void reset() noexcept;
396 template<class Y> void reset(Y* p);
397 template<class Y, class D> void reset(Y* p, D d);
398 template<class Y, class D, class A> void reset(Y* p, D d, A a);
401 T* get() const noexcept;
402 T& operator*() const noexcept;
403 T* operator->() const noexcept;
404 long use_count() const noexcept;
405 bool unique() const noexcept;
406 explicit operator bool() const noexcept;
407 template<class U> bool owner_before(shared_ptr<U> const& b) const;
408 template<class U> bool owner_before(weak_ptr<U> const& b) const;
411 // shared_ptr comparisons:
412 template<class T, class U>
413 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
414 template<class T, class U>
415 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
416 template<class T, class U>
417 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
418 template<class T, class U>
419 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
420 template<class T, class U>
421 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
422 template<class T, class U>
423 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
426 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
428 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
430 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
432 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
434 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
436 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
438 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
440 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
442 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
444 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
446 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
448 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
450 // shared_ptr specialized algorithms:
451 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
454 template<class T, class U>
455 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
456 template<class T, class U>
457 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
458 template<class T, class U>
459 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
462 template<class E, class T, class Y>
463 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
465 // shared_ptr get_deleter:
466 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
468 template<class T, class... Args>
469 shared_ptr<T> make_shared(Args&&... args);
470 template<class T, class A, class... Args>
471 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
477 typedef T element_type;
480 constexpr weak_ptr() noexcept;
481 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
482 weak_ptr(weak_ptr const& r) noexcept;
483 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
484 weak_ptr(weak_ptr&& r) noexcept; // C++14
485 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
491 weak_ptr& operator=(weak_ptr const& r) noexcept;
492 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
493 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
494 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
495 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
498 void swap(weak_ptr& r) noexcept;
499 void reset() noexcept;
502 long use_count() const noexcept;
503 bool expired() const noexcept;
504 shared_ptr<T> lock() const noexcept;
505 template<class U> bool owner_before(shared_ptr<U> const& b) const;
506 template<class U> bool owner_before(weak_ptr<U> const& b) const;
509 // weak_ptr specialized algorithms:
510 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
513 template<class T> struct owner_less;
516 struct owner_less<shared_ptr<T>>
517 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
519 typedef bool result_type;
520 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
521 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
522 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
526 struct owner_less<weak_ptr<T>>
527 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
529 typedef bool result_type;
530 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
531 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
532 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
536 class enable_shared_from_this
539 constexpr enable_shared_from_this() noexcept;
540 enable_shared_from_this(enable_shared_from_this const&) noexcept;
541 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
542 ~enable_shared_from_this();
544 shared_ptr<T> shared_from_this();
545 shared_ptr<T const> shared_from_this() const;
549 bool atomic_is_lock_free(const shared_ptr<T>* p);
551 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
553 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
555 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
557 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
559 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
562 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
565 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
568 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
571 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
572 shared_ptr<T> w, memory_order success,
573 memory_order failure);
576 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
577 shared_ptr<T> w, memory_order success,
578 memory_order failure);
580 template <class T> struct hash;
581 template <class T, class D> struct hash<unique_ptr<T, D> >;
582 template <class T> struct hash<shared_ptr<T> >;
585 enum class pointer_safety { relaxed, preferred, strict };
586 void declare_reachable(void *p);
587 template <class T> T *undeclare_reachable(T *p);
588 void declare_no_pointers(char *p, size_t n);
589 void undeclare_no_pointers(char *p, size_t n);
590 pointer_safety get_pointer_safety() noexcept;
592 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
599 #include <type_traits>
607 #include <__functional_base>
611 #if defined(_LIBCPP_NO_EXCEPTIONS)
615 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
619 #include <__undef_min_max>
620 #include <__undef___deallocate>
622 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
623 #pragma GCC system_header
626 _LIBCPP_BEGIN_NAMESPACE_STD
628 template <class _ValueType>
629 inline _LIBCPP_ALWAYS_INLINE
630 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
631 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
632 defined(__ATOMIC_RELAXED) && \
633 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
634 return __atomic_load_n(__value, __ATOMIC_RELAXED);
640 // addressof moved to <__functional_base>
642 template <class _Tp> class allocator;
645 class _LIBCPP_TYPE_VIS_ONLY allocator<void>
648 typedef void* pointer;
649 typedef const void* const_pointer;
650 typedef void value_type;
652 template <class _Up> struct rebind {typedef allocator<_Up> other;};
656 class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
659 typedef const void* pointer;
660 typedef const void* const_pointer;
661 typedef const void value_type;
663 template <class _Up> struct rebind {typedef allocator<_Up> other;};
669 struct __has_element_type
672 struct __two {char __lx; char __lxx;};
673 template <class _Up> static __two __test(...);
674 template <class _Up> static char __test(typename _Up::element_type* = 0);
676 static const bool value = sizeof(__test<_Tp>(0)) == 1;
679 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
680 struct __pointer_traits_element_type;
682 template <class _Ptr>
683 struct __pointer_traits_element_type<_Ptr, true>
685 typedef typename _Ptr::element_type type;
688 #ifndef _LIBCPP_HAS_NO_VARIADICS
690 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
691 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
693 typedef typename _Sp<_Tp, _Args...>::element_type type;
696 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
697 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
702 #else // _LIBCPP_HAS_NO_VARIADICS
704 template <template <class> class _Sp, class _Tp>
705 struct __pointer_traits_element_type<_Sp<_Tp>, true>
707 typedef typename _Sp<_Tp>::element_type type;
710 template <template <class> class _Sp, class _Tp>
711 struct __pointer_traits_element_type<_Sp<_Tp>, false>
716 template <template <class, class> class _Sp, class _Tp, class _A0>
717 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
719 typedef typename _Sp<_Tp, _A0>::element_type type;
722 template <template <class, class> class _Sp, class _Tp, class _A0>
723 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
728 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
729 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
731 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
734 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
735 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
740 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
741 class _A1, class _A2>
742 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
744 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
747 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
748 class _A1, class _A2>
749 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
754 #endif // _LIBCPP_HAS_NO_VARIADICS
757 struct __has_difference_type
760 struct __two {char __lx; char __lxx;};
761 template <class _Up> static __two __test(...);
762 template <class _Up> static char __test(typename _Up::difference_type* = 0);
764 static const bool value = sizeof(__test<_Tp>(0)) == 1;
767 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
768 struct __pointer_traits_difference_type
770 typedef ptrdiff_t type;
773 template <class _Ptr>
774 struct __pointer_traits_difference_type<_Ptr, true>
776 typedef typename _Ptr::difference_type type;
779 template <class _Tp, class _Up>
783 struct __two {char __lx; char __lxx;};
784 template <class _Xp> static __two __test(...);
785 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
787 static const bool value = sizeof(__test<_Tp>(0)) == 1;
790 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
791 struct __pointer_traits_rebind
793 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
794 typedef typename _Tp::template rebind<_Up> type;
796 typedef typename _Tp::template rebind<_Up>::other type;
800 #ifndef _LIBCPP_HAS_NO_VARIADICS
802 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
803 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
805 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
806 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
808 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
812 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
813 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
815 typedef _Sp<_Up, _Args...> type;
818 #else // _LIBCPP_HAS_NO_VARIADICS
820 template <template <class> class _Sp, class _Tp, class _Up>
821 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
823 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
824 typedef typename _Sp<_Tp>::template rebind<_Up> type;
826 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
830 template <template <class> class _Sp, class _Tp, class _Up>
831 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
833 typedef _Sp<_Up> type;
836 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
837 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
839 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
840 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
842 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
846 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
847 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
849 typedef _Sp<_Up, _A0> type;
852 template <template <class, class, class> class _Sp, class _Tp, class _A0,
853 class _A1, class _Up>
854 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
856 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
857 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
859 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
863 template <template <class, class, class> class _Sp, class _Tp, class _A0,
864 class _A1, class _Up>
865 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
867 typedef _Sp<_Up, _A0, _A1> type;
870 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
871 class _A1, class _A2, class _Up>
872 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
874 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
875 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
877 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
881 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
882 class _A1, class _A2, class _Up>
883 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
885 typedef _Sp<_Up, _A0, _A1, _A2> type;
888 #endif // _LIBCPP_HAS_NO_VARIADICS
890 template <class _Ptr>
891 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
893 typedef _Ptr pointer;
894 typedef typename __pointer_traits_element_type<pointer>::type element_type;
895 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
897 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
898 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
900 template <class _Up> struct rebind
901 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
902 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
907 _LIBCPP_INLINE_VISIBILITY
908 static pointer pointer_to(typename conditional<is_void<element_type>::value,
909 __nat, element_type>::type& __r)
910 {return pointer::pointer_to(__r);}
914 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
916 typedef _Tp* pointer;
917 typedef _Tp element_type;
918 typedef ptrdiff_t difference_type;
920 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
921 template <class _Up> using rebind = _Up*;
923 template <class _Up> struct rebind {typedef _Up* other;};
929 _LIBCPP_INLINE_VISIBILITY
930 static pointer pointer_to(typename conditional<is_void<element_type>::value,
931 __nat, element_type>::type& __r) _NOEXCEPT
932 {return _VSTD::addressof(__r);}
937 namespace __has_pointer_type_imp
939 template <class _Up> static __two __test(...);
940 template <class _Up> static char __test(typename _Up::pointer* = 0);
944 struct __has_pointer_type
945 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
949 namespace __pointer_type_imp
952 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
953 struct __pointer_type
955 typedef typename _Dp::pointer type;
958 template <class _Tp, class _Dp>
959 struct __pointer_type<_Tp, _Dp, false>
964 } // __pointer_type_imp
966 template <class _Tp, class _Dp>
967 struct __pointer_type
969 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
973 struct __has_const_pointer
976 struct __two {char __lx; char __lxx;};
977 template <class _Up> static __two __test(...);
978 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
980 static const bool value = sizeof(__test<_Tp>(0)) == 1;
983 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
984 struct __const_pointer
986 typedef typename _Alloc::const_pointer type;
989 template <class _Tp, class _Ptr, class _Alloc>
990 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
992 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
993 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
995 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1000 struct __has_void_pointer
1003 struct __two {char __lx; char __lxx;};
1004 template <class _Up> static __two __test(...);
1005 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1007 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1010 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1011 struct __void_pointer
1013 typedef typename _Alloc::void_pointer type;
1016 template <class _Ptr, class _Alloc>
1017 struct __void_pointer<_Ptr, _Alloc, false>
1019 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1020 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1022 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1026 template <class _Tp>
1027 struct __has_const_void_pointer
1030 struct __two {char __lx; char __lxx;};
1031 template <class _Up> static __two __test(...);
1032 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1034 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1037 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1038 struct __const_void_pointer
1040 typedef typename _Alloc::const_void_pointer type;
1043 template <class _Ptr, class _Alloc>
1044 struct __const_void_pointer<_Ptr, _Alloc, false>
1046 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1047 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1049 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1053 template <class _Tp>
1054 inline _LIBCPP_INLINE_VISIBILITY
1056 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1061 template <class _Pointer>
1062 inline _LIBCPP_INLINE_VISIBILITY
1063 typename pointer_traits<_Pointer>::element_type*
1064 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1066 return _VSTD::__to_raw_pointer(__p.operator->());
1069 template <class _Tp>
1070 struct __has_size_type
1073 struct __two {char __lx; char __lxx;};
1074 template <class _Up> static __two __test(...);
1075 template <class _Up> static char __test(typename _Up::size_type* = 0);
1077 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1080 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1083 typedef typename make_unsigned<_DiffType>::type type;
1086 template <class _Alloc, class _DiffType>
1087 struct __size_type<_Alloc, _DiffType, true>
1089 typedef typename _Alloc::size_type type;
1092 template <class _Tp>
1093 struct __has_propagate_on_container_copy_assignment
1096 struct __two {char __lx; char __lxx;};
1097 template <class _Up> static __two __test(...);
1098 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1100 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1103 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1104 struct __propagate_on_container_copy_assignment
1106 typedef false_type type;
1109 template <class _Alloc>
1110 struct __propagate_on_container_copy_assignment<_Alloc, true>
1112 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1115 template <class _Tp>
1116 struct __has_propagate_on_container_move_assignment
1119 struct __two {char __lx; char __lxx;};
1120 template <class _Up> static __two __test(...);
1121 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1123 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1126 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1127 struct __propagate_on_container_move_assignment
1129 typedef false_type type;
1132 template <class _Alloc>
1133 struct __propagate_on_container_move_assignment<_Alloc, true>
1135 typedef typename _Alloc::propagate_on_container_move_assignment type;
1138 template <class _Tp>
1139 struct __has_propagate_on_container_swap
1142 struct __two {char __lx; char __lxx;};
1143 template <class _Up> static __two __test(...);
1144 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1146 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1149 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1150 struct __propagate_on_container_swap
1152 typedef false_type type;
1155 template <class _Alloc>
1156 struct __propagate_on_container_swap<_Alloc, true>
1158 typedef typename _Alloc::propagate_on_container_swap type;
1161 template <class _Tp>
1162 struct __has_is_always_equal
1165 struct __two {char __lx; char __lxx;};
1166 template <class _Up> static __two __test(...);
1167 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1169 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1172 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1173 struct __is_always_equal
1175 typedef typename _VSTD::is_empty<_Alloc>::type type;
1178 template <class _Alloc>
1179 struct __is_always_equal<_Alloc, true>
1181 typedef typename _Alloc::is_always_equal type;
1184 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1185 struct __has_rebind_other
1188 struct __two {char __lx; char __lxx;};
1189 template <class _Xp> static __two __test(...);
1190 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1192 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1195 template <class _Tp, class _Up>
1196 struct __has_rebind_other<_Tp, _Up, false>
1198 static const bool value = false;
1201 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1202 struct __allocator_traits_rebind
1204 typedef typename _Tp::template rebind<_Up>::other type;
1207 #ifndef _LIBCPP_HAS_NO_VARIADICS
1209 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1210 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1212 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1215 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1216 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1218 typedef _Alloc<_Up, _Args...> type;
1221 #else // _LIBCPP_HAS_NO_VARIADICS
1223 template <template <class> class _Alloc, class _Tp, class _Up>
1224 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1226 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1229 template <template <class> class _Alloc, class _Tp, class _Up>
1230 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1232 typedef _Alloc<_Up> type;
1235 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1236 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1238 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1241 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1242 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1244 typedef _Alloc<_Up, _A0> type;
1247 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1248 class _A1, class _Up>
1249 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1251 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1254 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1255 class _A1, class _Up>
1256 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1258 typedef _Alloc<_Up, _A0, _A1> type;
1261 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1262 class _A1, class _A2, class _Up>
1263 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1265 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1268 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1269 class _A1, class _A2, class _Up>
1270 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1272 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1275 #endif // _LIBCPP_HAS_NO_VARIADICS
1277 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1279 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1281 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1282 -> decltype(__a.allocate(__sz, __p), true_type());
1284 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1286 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1289 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1290 struct __has_allocate_hint
1291 : integral_constant<bool,
1293 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1294 declval<_SizeType>(),
1295 declval<_ConstVoidPtr>())),
1300 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1302 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1303 struct __has_allocate_hint
1308 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1310 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1312 template <class _Alloc, class _Tp, class ..._Args>
1313 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1314 _VSTD::declval<_Args>()...),
1316 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1318 template <class _Alloc, class _Pointer, class ..._Args>
1320 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1322 template <class _Alloc, class _Pointer, class ..._Args>
1323 struct __has_construct
1324 : integral_constant<bool,
1326 decltype(__has_construct_test(declval<_Alloc>(),
1327 declval<_Pointer>(),
1328 declval<_Args>()...)),
1333 template <class _Alloc, class _Pointer>
1335 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1336 -> decltype(__a.destroy(__p), true_type());
1338 template <class _Alloc, class _Pointer>
1340 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1343 template <class _Alloc, class _Pointer>
1344 struct __has_destroy
1345 : integral_constant<bool,
1347 decltype(__has_destroy_test(declval<_Alloc>(),
1348 declval<_Pointer>())),
1353 template <class _Alloc>
1355 __has_max_size_test(_Alloc&& __a)
1356 -> decltype(__a.max_size(), true_type());
1358 template <class _Alloc>
1360 __has_max_size_test(const volatile _Alloc& __a)
1363 template <class _Alloc>
1364 struct __has_max_size
1365 : integral_constant<bool,
1367 decltype(__has_max_size_test(declval<_Alloc&>())),
1372 template <class _Alloc>
1374 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1375 -> decltype(__a.select_on_container_copy_construction(), true_type());
1377 template <class _Alloc>
1379 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1382 template <class _Alloc>
1383 struct __has_select_on_container_copy_construction
1384 : integral_constant<bool,
1386 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1391 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1393 #ifndef _LIBCPP_HAS_NO_VARIADICS
1395 template <class _Alloc, class _Pointer, class ..._Args>
1396 struct __has_construct
1401 #else // _LIBCPP_HAS_NO_VARIADICS
1403 template <class _Alloc, class _Pointer, class _Args>
1404 struct __has_construct
1409 #endif // _LIBCPP_HAS_NO_VARIADICS
1411 template <class _Alloc, class _Pointer>
1412 struct __has_destroy
1417 template <class _Alloc>
1418 struct __has_max_size
1423 template <class _Alloc>
1424 struct __has_select_on_container_copy_construction
1429 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1431 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1432 struct __alloc_traits_difference_type
1434 typedef typename pointer_traits<_Ptr>::difference_type type;
1437 template <class _Alloc, class _Ptr>
1438 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1440 typedef typename _Alloc::difference_type type;
1443 template <class _Alloc>
1444 struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
1446 typedef _Alloc allocator_type;
1447 typedef typename allocator_type::value_type value_type;
1449 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1450 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1451 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1452 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1454 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1455 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1457 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1458 propagate_on_container_copy_assignment;
1459 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1460 propagate_on_container_move_assignment;
1461 typedef typename __propagate_on_container_swap<allocator_type>::type
1462 propagate_on_container_swap;
1463 typedef typename __is_always_equal<allocator_type>::type
1466 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1467 template <class _Tp> using rebind_alloc =
1468 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1469 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1470 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1471 template <class _Tp> struct rebind_alloc
1472 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1473 template <class _Tp> struct rebind_traits
1474 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1475 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1477 _LIBCPP_INLINE_VISIBILITY
1478 static pointer allocate(allocator_type& __a, size_type __n)
1479 {return __a.allocate(__n);}
1480 _LIBCPP_INLINE_VISIBILITY
1481 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1482 {return allocate(__a, __n, __hint,
1483 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1485 _LIBCPP_INLINE_VISIBILITY
1486 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1487 {__a.deallocate(__p, __n);}
1489 #ifndef _LIBCPP_HAS_NO_VARIADICS
1490 template <class _Tp, class... _Args>
1491 _LIBCPP_INLINE_VISIBILITY
1492 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1493 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1494 __a, __p, _VSTD::forward<_Args>(__args)...);}
1495 #else // _LIBCPP_HAS_NO_VARIADICS
1496 template <class _Tp>
1497 _LIBCPP_INLINE_VISIBILITY
1498 static void construct(allocator_type& __a, _Tp* __p)
1500 ::new ((void*)__p) _Tp();
1502 template <class _Tp, class _A0>
1503 _LIBCPP_INLINE_VISIBILITY
1504 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1506 ::new ((void*)__p) _Tp(__a0);
1508 template <class _Tp, class _A0, class _A1>
1509 _LIBCPP_INLINE_VISIBILITY
1510 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1513 ::new ((void*)__p) _Tp(__a0, __a1);
1515 template <class _Tp, class _A0, class _A1, class _A2>
1516 _LIBCPP_INLINE_VISIBILITY
1517 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1518 const _A1& __a1, const _A2& __a2)
1520 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1522 #endif // _LIBCPP_HAS_NO_VARIADICS
1524 template <class _Tp>
1525 _LIBCPP_INLINE_VISIBILITY
1526 static void destroy(allocator_type& __a, _Tp* __p)
1527 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1529 _LIBCPP_INLINE_VISIBILITY
1530 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1531 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1533 _LIBCPP_INLINE_VISIBILITY
1534 static allocator_type
1535 select_on_container_copy_construction(const allocator_type& __a)
1536 {return select_on_container_copy_construction(
1537 __has_select_on_container_copy_construction<const allocator_type>(),
1540 template <class _Ptr>
1541 _LIBCPP_INLINE_VISIBILITY
1544 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1546 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1547 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1550 template <class _Tp>
1551 _LIBCPP_INLINE_VISIBILITY
1555 (is_same<allocator_type, allocator<_Tp> >::value
1556 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1557 is_trivially_move_constructible<_Tp>::value,
1560 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1562 ptrdiff_t _Np = __end1 - __begin1;
1565 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1570 template <class _Iter, class _Ptr>
1571 _LIBCPP_INLINE_VISIBILITY
1574 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1576 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1577 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1580 template <class _Tp>
1581 _LIBCPP_INLINE_VISIBILITY
1585 (is_same<allocator_type, allocator<_Tp> >::value
1586 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1587 is_trivially_move_constructible<_Tp>::value,
1590 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1592 typedef typename remove_const<_Tp>::type _Vp;
1593 ptrdiff_t _Np = __end1 - __begin1;
1596 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1601 template <class _Ptr>
1602 _LIBCPP_INLINE_VISIBILITY
1605 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1607 while (__end1 != __begin1)
1609 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1614 template <class _Tp>
1615 _LIBCPP_INLINE_VISIBILITY
1619 (is_same<allocator_type, allocator<_Tp> >::value
1620 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1621 is_trivially_move_constructible<_Tp>::value,
1624 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1626 ptrdiff_t _Np = __end1 - __begin1;
1629 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1634 _LIBCPP_INLINE_VISIBILITY
1635 static pointer allocate(allocator_type& __a, size_type __n,
1636 const_void_pointer __hint, true_type)
1637 {return __a.allocate(__n, __hint);}
1638 _LIBCPP_INLINE_VISIBILITY
1639 static pointer allocate(allocator_type& __a, size_type __n,
1640 const_void_pointer, false_type)
1641 {return __a.allocate(__n);}
1643 #ifndef _LIBCPP_HAS_NO_VARIADICS
1644 template <class _Tp, class... _Args>
1645 _LIBCPP_INLINE_VISIBILITY
1646 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1647 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1648 template <class _Tp, class... _Args>
1649 _LIBCPP_INLINE_VISIBILITY
1650 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1652 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1654 #endif // _LIBCPP_HAS_NO_VARIADICS
1656 template <class _Tp>
1657 _LIBCPP_INLINE_VISIBILITY
1658 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1660 template <class _Tp>
1661 _LIBCPP_INLINE_VISIBILITY
1662 static void __destroy(false_type, allocator_type&, _Tp* __p)
1667 _LIBCPP_INLINE_VISIBILITY
1668 static size_type __max_size(true_type, const allocator_type& __a)
1669 {return __a.max_size();}
1670 _LIBCPP_INLINE_VISIBILITY
1671 static size_type __max_size(false_type, const allocator_type&)
1672 {return numeric_limits<size_type>::max();}
1674 _LIBCPP_INLINE_VISIBILITY
1675 static allocator_type
1676 select_on_container_copy_construction(true_type, const allocator_type& __a)
1677 {return __a.select_on_container_copy_construction();}
1678 _LIBCPP_INLINE_VISIBILITY
1679 static allocator_type
1680 select_on_container_copy_construction(false_type, const allocator_type& __a)
1684 template <class _Traits, class _Tp>
1685 struct __rebind_alloc_helper
1687 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1688 typedef typename _Traits::template rebind_alloc<_Tp> type;
1690 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1696 template <class _Tp>
1697 class _LIBCPP_TYPE_VIS_ONLY allocator
1700 typedef size_t size_type;
1701 typedef ptrdiff_t difference_type;
1702 typedef _Tp* pointer;
1703 typedef const _Tp* const_pointer;
1704 typedef _Tp& reference;
1705 typedef const _Tp& const_reference;
1706 typedef _Tp value_type;
1708 typedef true_type propagate_on_container_move_assignment;
1709 typedef true_type is_always_equal;
1711 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1713 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1714 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1715 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1716 {return _VSTD::addressof(__x);}
1717 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1718 {return _VSTD::addressof(__x);}
1719 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1720 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1721 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1722 {_VSTD::__deallocate((void*)__p);}
1723 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1724 {return size_type(~0) / sizeof(_Tp);}
1725 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1726 template <class _Up, class... _Args>
1727 _LIBCPP_INLINE_VISIBILITY
1729 construct(_Up* __p, _Args&&... __args)
1731 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1733 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1734 _LIBCPP_INLINE_VISIBILITY
1736 construct(pointer __p)
1738 ::new((void*)__p) _Tp();
1740 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1742 template <class _A0>
1743 _LIBCPP_INLINE_VISIBILITY
1745 construct(pointer __p, _A0& __a0)
1747 ::new((void*)__p) _Tp(__a0);
1749 template <class _A0>
1750 _LIBCPP_INLINE_VISIBILITY
1752 construct(pointer __p, const _A0& __a0)
1754 ::new((void*)__p) _Tp(__a0);
1756 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1757 template <class _A0, class _A1>
1758 _LIBCPP_INLINE_VISIBILITY
1760 construct(pointer __p, _A0& __a0, _A1& __a1)
1762 ::new((void*)__p) _Tp(__a0, __a1);
1764 template <class _A0, class _A1>
1765 _LIBCPP_INLINE_VISIBILITY
1767 construct(pointer __p, const _A0& __a0, _A1& __a1)
1769 ::new((void*)__p) _Tp(__a0, __a1);
1771 template <class _A0, class _A1>
1772 _LIBCPP_INLINE_VISIBILITY
1774 construct(pointer __p, _A0& __a0, const _A1& __a1)
1776 ::new((void*)__p) _Tp(__a0, __a1);
1778 template <class _A0, class _A1>
1779 _LIBCPP_INLINE_VISIBILITY
1781 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1783 ::new((void*)__p) _Tp(__a0, __a1);
1785 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1786 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1789 template <class _Tp>
1790 class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1793 typedef size_t size_type;
1794 typedef ptrdiff_t difference_type;
1795 typedef const _Tp* pointer;
1796 typedef const _Tp* const_pointer;
1797 typedef const _Tp& reference;
1798 typedef const _Tp& const_reference;
1799 typedef const _Tp value_type;
1801 typedef true_type propagate_on_container_move_assignment;
1802 typedef true_type is_always_equal;
1804 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1806 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1807 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1808 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1809 {return _VSTD::addressof(__x);}
1810 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1811 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1812 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1813 {_VSTD::__deallocate((void*)__p);}
1814 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1815 {return size_type(~0) / sizeof(_Tp);}
1816 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1817 template <class _Up, class... _Args>
1818 _LIBCPP_INLINE_VISIBILITY
1820 construct(_Up* __p, _Args&&... __args)
1822 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1824 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1825 _LIBCPP_INLINE_VISIBILITY
1827 construct(pointer __p)
1829 ::new((void*)__p) _Tp();
1831 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1833 template <class _A0>
1834 _LIBCPP_INLINE_VISIBILITY
1836 construct(pointer __p, _A0& __a0)
1838 ::new((void*)__p) _Tp(__a0);
1840 template <class _A0>
1841 _LIBCPP_INLINE_VISIBILITY
1843 construct(pointer __p, const _A0& __a0)
1845 ::new((void*)__p) _Tp(__a0);
1847 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1848 template <class _A0, class _A1>
1849 _LIBCPP_INLINE_VISIBILITY
1851 construct(pointer __p, _A0& __a0, _A1& __a1)
1853 ::new((void*)__p) _Tp(__a0, __a1);
1855 template <class _A0, class _A1>
1856 _LIBCPP_INLINE_VISIBILITY
1858 construct(pointer __p, const _A0& __a0, _A1& __a1)
1860 ::new((void*)__p) _Tp(__a0, __a1);
1862 template <class _A0, class _A1>
1863 _LIBCPP_INLINE_VISIBILITY
1865 construct(pointer __p, _A0& __a0, const _A1& __a1)
1867 ::new((void*)__p) _Tp(__a0, __a1);
1869 template <class _A0, class _A1>
1870 _LIBCPP_INLINE_VISIBILITY
1872 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1874 ::new((void*)__p) _Tp(__a0, __a1);
1876 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1877 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1880 template <class _Tp, class _Up>
1881 inline _LIBCPP_INLINE_VISIBILITY
1882 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1884 template <class _Tp, class _Up>
1885 inline _LIBCPP_INLINE_VISIBILITY
1886 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1888 template <class _OutputIterator, class _Tp>
1889 class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
1890 : public iterator<output_iterator_tag,
1891 _Tp, // purposefully not C++03
1892 ptrdiff_t, // purposefully not C++03
1893 _Tp*, // purposefully not C++03
1894 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1897 _OutputIterator __x_;
1899 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1900 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1901 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1902 {::new(&*__x_) _Tp(__element); return *this;}
1903 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1904 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1905 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1906 #if _LIBCPP_STD_VER >= 14
1907 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1911 template <class _Tp>
1912 pair<_Tp*, ptrdiff_t>
1913 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1915 pair<_Tp*, ptrdiff_t> __r(0, 0);
1916 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1917 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1923 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1934 template <class _Tp>
1935 inline _LIBCPP_INLINE_VISIBILITY
1936 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1938 template <class _Tp>
1945 class _LIBCPP_TYPE_VIS_ONLY auto_ptr
1950 typedef _Tp element_type;
1952 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1953 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1954 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1955 : __ptr_(__p.release()) {}
1956 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1957 {reset(__p.release()); return *this;}
1958 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1959 {reset(__p.release()); return *this;}
1960 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1961 {reset(__p.__ptr_); return *this;}
1962 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1964 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1966 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1967 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1968 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1974 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1981 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1982 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1983 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1984 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1985 {return auto_ptr<_Up>(release());}
1989 class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
1992 typedef void element_type;
1995 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1996 typename remove_cv<_T2>::type>::value,
1997 bool = is_empty<_T1>::value
1998 && !__libcpp_is_final<_T1>::value,
1999 bool = is_empty<_T2>::value
2000 && !__libcpp_is_final<_T2>::value
2002 struct __libcpp_compressed_pair_switch;
2004 template <class _T1, class _T2, bool IsSame>
2005 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2007 template <class _T1, class _T2, bool IsSame>
2008 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2010 template <class _T1, class _T2, bool IsSame>
2011 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2013 template <class _T1, class _T2>
2014 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2016 template <class _T1, class _T2>
2017 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2019 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2020 class __libcpp_compressed_pair_imp;
2022 template <class _T1, class _T2>
2023 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2029 typedef _T1 _T1_param;
2030 typedef _T2 _T2_param;
2032 typedef typename remove_reference<_T1>::type& _T1_reference;
2033 typedef typename remove_reference<_T2>::type& _T2_reference;
2035 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2036 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2038 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
2039 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2040 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2041 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2042 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2043 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2044 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2046 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2048 _LIBCPP_INLINE_VISIBILITY
2049 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2050 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2051 is_nothrow_copy_constructible<_T2>::value)
2052 : __first_(__p.first()),
2053 __second_(__p.second()) {}
2055 _LIBCPP_INLINE_VISIBILITY
2056 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2057 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2058 is_nothrow_copy_assignable<_T2>::value)
2060 __first_ = __p.first();
2061 __second_ = __p.second();
2065 _LIBCPP_INLINE_VISIBILITY
2066 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2067 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2068 is_nothrow_move_constructible<_T2>::value)
2069 : __first_(_VSTD::forward<_T1>(__p.first())),
2070 __second_(_VSTD::forward<_T2>(__p.second())) {}
2072 _LIBCPP_INLINE_VISIBILITY
2073 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2074 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2075 is_nothrow_move_assignable<_T2>::value)
2077 __first_ = _VSTD::forward<_T1>(__p.first());
2078 __second_ = _VSTD::forward<_T2>(__p.second());
2082 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2084 #ifndef _LIBCPP_HAS_NO_VARIADICS
2086 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2087 _LIBCPP_INLINE_VISIBILITY
2088 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2089 tuple<_Args1...> __first_args,
2090 tuple<_Args2...> __second_args,
2091 __tuple_indices<_I1...>,
2092 __tuple_indices<_I2...>)
2093 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2094 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2097 #endif // _LIBCPP_HAS_NO_VARIADICS
2099 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2100 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2102 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2103 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2105 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2106 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2107 __is_nothrow_swappable<_T2>::value)
2110 swap(__first_, __x.__first_);
2111 swap(__second_, __x.__second_);
2115 template <class _T1, class _T2>
2116 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2122 typedef _T1 _T1_param;
2123 typedef _T2 _T2_param;
2125 typedef _T1& _T1_reference;
2126 typedef typename remove_reference<_T2>::type& _T2_reference;
2128 typedef const _T1& _T1_const_reference;
2129 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2131 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
2132 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2133 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2134 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2135 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2136 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2137 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2139 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2141 _LIBCPP_INLINE_VISIBILITY
2142 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2143 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2144 is_nothrow_copy_constructible<_T2>::value)
2145 : _T1(__p.first()), __second_(__p.second()) {}
2147 _LIBCPP_INLINE_VISIBILITY
2148 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2149 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2150 is_nothrow_copy_assignable<_T2>::value)
2152 _T1::operator=(__p.first());
2153 __second_ = __p.second();
2157 _LIBCPP_INLINE_VISIBILITY
2158 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2159 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2160 is_nothrow_move_constructible<_T2>::value)
2161 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2163 _LIBCPP_INLINE_VISIBILITY
2164 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2165 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2166 is_nothrow_move_assignable<_T2>::value)
2168 _T1::operator=(_VSTD::move(__p.first()));
2169 __second_ = _VSTD::forward<_T2>(__p.second());
2173 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2175 #ifndef _LIBCPP_HAS_NO_VARIADICS
2177 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2178 _LIBCPP_INLINE_VISIBILITY
2179 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2180 tuple<_Args1...> __first_args,
2181 tuple<_Args2...> __second_args,
2182 __tuple_indices<_I1...>,
2183 __tuple_indices<_I2...>)
2184 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2185 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2188 #endif // _LIBCPP_HAS_NO_VARIADICS
2190 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2191 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2193 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2194 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2196 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2197 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2198 __is_nothrow_swappable<_T2>::value)
2201 swap(__second_, __x.__second_);
2205 template <class _T1, class _T2>
2206 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2212 typedef _T1 _T1_param;
2213 typedef _T2 _T2_param;
2215 typedef typename remove_reference<_T1>::type& _T1_reference;
2216 typedef _T2& _T2_reference;
2218 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2219 typedef const _T2& _T2_const_reference;
2221 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
2222 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2223 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2224 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2225 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
2226 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2227 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2228 is_nothrow_move_constructible<_T2>::value)
2229 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2231 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2233 _LIBCPP_INLINE_VISIBILITY
2234 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2235 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2236 is_nothrow_copy_constructible<_T2>::value)
2237 : _T2(__p.second()), __first_(__p.first()) {}
2239 _LIBCPP_INLINE_VISIBILITY
2240 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2241 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2242 is_nothrow_copy_assignable<_T2>::value)
2244 _T2::operator=(__p.second());
2245 __first_ = __p.first();
2249 _LIBCPP_INLINE_VISIBILITY
2250 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2251 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2252 is_nothrow_move_constructible<_T2>::value)
2253 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2255 _LIBCPP_INLINE_VISIBILITY
2256 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2257 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2258 is_nothrow_move_assignable<_T2>::value)
2260 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2261 __first_ = _VSTD::move(__p.first());
2265 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2267 #ifndef _LIBCPP_HAS_NO_VARIADICS
2269 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2270 _LIBCPP_INLINE_VISIBILITY
2271 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2272 tuple<_Args1...> __first_args,
2273 tuple<_Args2...> __second_args,
2274 __tuple_indices<_I1...>,
2275 __tuple_indices<_I2...>)
2276 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2277 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2281 #endif // _LIBCPP_HAS_NO_VARIADICS
2283 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2284 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2286 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2287 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2289 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2290 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2291 __is_nothrow_swappable<_T2>::value)
2294 swap(__first_, __x.__first_);
2298 template <class _T1, class _T2>
2299 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2304 typedef _T1 _T1_param;
2305 typedef _T2 _T2_param;
2307 typedef _T1& _T1_reference;
2308 typedef _T2& _T2_reference;
2310 typedef const _T1& _T1_const_reference;
2311 typedef const _T2& _T2_const_reference;
2313 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2314 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2315 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2316 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2317 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2318 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2319 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2321 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2323 _LIBCPP_INLINE_VISIBILITY
2324 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2325 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2326 is_nothrow_copy_constructible<_T2>::value)
2327 : _T1(__p.first()), _T2(__p.second()) {}
2329 _LIBCPP_INLINE_VISIBILITY
2330 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2331 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2332 is_nothrow_copy_assignable<_T2>::value)
2334 _T1::operator=(__p.first());
2335 _T2::operator=(__p.second());
2339 _LIBCPP_INLINE_VISIBILITY
2340 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2341 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2342 is_nothrow_move_constructible<_T2>::value)
2343 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2345 _LIBCPP_INLINE_VISIBILITY
2346 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2347 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2348 is_nothrow_move_assignable<_T2>::value)
2350 _T1::operator=(_VSTD::move(__p.first()));
2351 _T2::operator=(_VSTD::move(__p.second()));
2355 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2357 #ifndef _LIBCPP_HAS_NO_VARIADICS
2359 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2360 _LIBCPP_INLINE_VISIBILITY
2361 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2362 tuple<_Args1...> __first_args,
2363 tuple<_Args2...> __second_args,
2364 __tuple_indices<_I1...>,
2365 __tuple_indices<_I2...>)
2366 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2367 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2370 #endif // _LIBCPP_HAS_NO_VARIADICS
2372 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2373 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2375 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2376 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2378 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2379 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2380 __is_nothrow_swappable<_T2>::value)
2385 template <class _T1, class _T2>
2386 class __compressed_pair
2387 : private __libcpp_compressed_pair_imp<_T1, _T2>
2389 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2391 typedef typename base::_T1_param _T1_param;
2392 typedef typename base::_T2_param _T2_param;
2394 typedef typename base::_T1_reference _T1_reference;
2395 typedef typename base::_T2_reference _T2_reference;
2397 typedef typename base::_T1_const_reference _T1_const_reference;
2398 typedef typename base::_T2_const_reference _T2_const_reference;
2400 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2401 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2402 : base(_VSTD::forward<_T1_param>(__t1)) {}
2403 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2404 : base(_VSTD::forward<_T2_param>(__t2)) {}
2405 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2406 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2408 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2410 _LIBCPP_INLINE_VISIBILITY
2411 __compressed_pair(const __compressed_pair& __p)
2412 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2413 is_nothrow_copy_constructible<_T2>::value)
2416 _LIBCPP_INLINE_VISIBILITY
2417 __compressed_pair& operator=(const __compressed_pair& __p)
2418 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2419 is_nothrow_copy_assignable<_T2>::value)
2421 base::operator=(__p);
2425 _LIBCPP_INLINE_VISIBILITY
2426 __compressed_pair(__compressed_pair&& __p)
2427 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2428 is_nothrow_move_constructible<_T2>::value)
2429 : base(_VSTD::move(__p)) {}
2431 _LIBCPP_INLINE_VISIBILITY
2432 __compressed_pair& operator=(__compressed_pair&& __p)
2433 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2434 is_nothrow_move_assignable<_T2>::value)
2436 base::operator=(_VSTD::move(__p));
2440 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2442 #ifndef _LIBCPP_HAS_NO_VARIADICS
2444 template <class... _Args1, class... _Args2>
2445 _LIBCPP_INLINE_VISIBILITY
2446 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2447 tuple<_Args2...> __second_args)
2448 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2449 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2450 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2453 #endif // _LIBCPP_HAS_NO_VARIADICS
2455 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2456 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2458 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2459 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2461 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2462 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2463 __is_nothrow_swappable<_T2>::value)
2467 template <class _T1, class _T2>
2468 inline _LIBCPP_INLINE_VISIBILITY
2470 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2471 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2472 __is_nothrow_swappable<_T2>::value)
2475 // __same_or_less_cv_qualified
2477 template <class _Ptr1, class _Ptr2,
2478 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2479 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2482 struct __same_or_less_cv_qualified_imp
2483 : is_convertible<_Ptr1, _Ptr2> {};
2485 template <class _Ptr1, class _Ptr2>
2486 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2489 template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2490 is_same<_Ptr1, _Ptr2>::value ||
2491 __has_element_type<_Ptr1>::value>
2492 struct __same_or_less_cv_qualified
2493 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2495 template <class _Ptr1, class _Ptr2>
2496 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2501 template <class _Tp>
2502 struct _LIBCPP_TYPE_VIS_ONLY default_delete
2504 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2505 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2507 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2509 template <class _Up>
2510 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2511 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2512 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2514 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2515 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2520 template <class _Tp>
2521 struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2524 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2525 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2527 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2529 template <class _Up>
2530 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2531 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2532 template <class _Up>
2533 _LIBCPP_INLINE_VISIBILITY
2534 void operator() (_Up* __ptr,
2535 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2537 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2538 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2543 template <class _Tp, class _Dp = default_delete<_Tp> >
2544 class _LIBCPP_TYPE_VIS_ONLY unique_ptr
2547 typedef _Tp element_type;
2548 typedef _Dp deleter_type;
2549 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2551 __compressed_pair<pointer, deleter_type> __ptr_;
2553 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2554 unique_ptr(unique_ptr&);
2555 template <class _Up, class _Ep>
2556 unique_ptr(unique_ptr<_Up, _Ep>&);
2557 unique_ptr& operator=(unique_ptr&);
2558 template <class _Up, class _Ep>
2559 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2560 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2562 struct __nat {int __for_bool_;};
2564 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2565 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2567 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2570 static_assert(!is_pointer<deleter_type>::value,
2571 "unique_ptr constructed with null function pointer deleter");
2573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2576 static_assert(!is_pointer<deleter_type>::value,
2577 "unique_ptr constructed with null function pointer deleter");
2579 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2580 : __ptr_(_VSTD::move(__p))
2582 static_assert(!is_pointer<deleter_type>::value,
2583 "unique_ptr constructed with null function pointer deleter");
2586 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2587 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2588 is_reference<deleter_type>::value,
2590 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2592 : __ptr_(__p, __d) {}
2594 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2596 : __ptr_(__p, _VSTD::move(__d))
2598 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2600 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2601 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2602 template <class _Up, class _Ep>
2603 _LIBCPP_INLINE_VISIBILITY
2604 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2607 !is_array<_Up>::value &&
2608 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2609 is_convertible<_Ep, deleter_type>::value &&
2611 !is_reference<deleter_type>::value ||
2612 is_same<deleter_type, _Ep>::value
2615 >::type = __nat()) _NOEXCEPT
2616 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2618 template <class _Up>
2619 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2621 is_convertible<_Up*, _Tp*>::value &&
2622 is_same<_Dp, default_delete<_Tp> >::value,
2624 >::type = __nat()) _NOEXCEPT
2625 : __ptr_(__p.release())
2629 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2631 reset(__u.release());
2632 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2636 template <class _Up, class _Ep>
2637 _LIBCPP_INLINE_VISIBILITY
2640 !is_array<_Up>::value &&
2641 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2642 is_assignable<deleter_type&, _Ep&&>::value,
2645 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2647 reset(__u.release());
2648 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2651 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2653 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2655 return __rv<unique_ptr>(*this);
2658 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2659 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2661 template <class _Up, class _Ep>
2662 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2664 reset(__u.release());
2665 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2669 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2670 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2672 template <class _Up>
2673 _LIBCPP_INLINE_VISIBILITY
2675 is_convertible<_Up*, _Tp*>::value &&
2676 is_same<_Dp, default_delete<_Tp> >::value,
2679 operator=(auto_ptr<_Up> __p)
2680 {reset(__p.release()); return *this;}
2682 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2683 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2685 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2691 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2692 {return *__ptr_.first();}
2693 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2694 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2695 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2696 {return __ptr_.second();}
2697 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2698 {return __ptr_.second();}
2699 _LIBCPP_INLINE_VISIBILITY
2700 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2701 {return __ptr_.first() != nullptr;}
2703 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2705 pointer __t = __ptr_.first();
2706 __ptr_.first() = pointer();
2710 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2712 pointer __tmp = __ptr_.first();
2713 __ptr_.first() = __p;
2715 __ptr_.second()(__tmp);
2718 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2719 {__ptr_.swap(__u.__ptr_);}
2722 template <class _Tp, class _Dp>
2723 class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
2726 typedef _Tp element_type;
2727 typedef _Dp deleter_type;
2728 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2730 __compressed_pair<pointer, deleter_type> __ptr_;
2732 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2733 unique_ptr(unique_ptr&);
2734 template <class _Up>
2735 unique_ptr(unique_ptr<_Up>&);
2736 unique_ptr& operator=(unique_ptr&);
2737 template <class _Up>
2738 unique_ptr& operator=(unique_ptr<_Up>&);
2739 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2741 struct __nat {int __for_bool_;};
2743 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2744 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2746 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2749 static_assert(!is_pointer<deleter_type>::value,
2750 "unique_ptr constructed with null function pointer deleter");
2752 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2755 static_assert(!is_pointer<deleter_type>::value,
2756 "unique_ptr constructed with null function pointer deleter");
2758 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2759 template <class _Pp>
2760 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2761 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
2764 static_assert(!is_pointer<deleter_type>::value,
2765 "unique_ptr constructed with null function pointer deleter");
2768 template <class _Pp>
2769 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2770 is_reference<deleter_type>::value,
2772 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2773 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2775 : __ptr_(__p, __d) {}
2777 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2778 is_reference<deleter_type>::value,
2780 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2782 : __ptr_(pointer(), __d) {}
2784 template <class _Pp>
2785 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2786 typename remove_reference<deleter_type>::type&& __d,
2787 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2789 : __ptr_(__p, _VSTD::move(__d))
2791 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2794 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2796 : __ptr_(pointer(), _VSTD::move(__d))
2798 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2801 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2802 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2804 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2806 reset(__u.release());
2807 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2811 template <class _Up, class _Ep>
2812 _LIBCPP_INLINE_VISIBILITY
2813 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2816 is_array<_Up>::value &&
2817 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2818 && is_convertible<_Ep, deleter_type>::value &&
2820 !is_reference<deleter_type>::value ||
2821 is_same<deleter_type, _Ep>::value
2826 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2829 template <class _Up, class _Ep>
2830 _LIBCPP_INLINE_VISIBILITY
2833 is_array<_Up>::value &&
2834 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2835 is_assignable<deleter_type&, _Ep&&>::value,
2838 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2840 reset(__u.release());
2841 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2844 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2846 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2849 static_assert(!is_pointer<deleter_type>::value,
2850 "unique_ptr constructed with null function pointer deleter");
2853 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2854 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2856 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2857 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2859 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2861 return __rv<unique_ptr>(*this);
2864 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2865 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2867 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2869 reset(__u->release());
2870 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2874 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2875 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2877 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2883 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2884 {return __ptr_.first()[__i];}
2885 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2886 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2887 {return __ptr_.second();}
2888 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2889 {return __ptr_.second();}
2890 _LIBCPP_INLINE_VISIBILITY
2891 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2892 {return __ptr_.first() != nullptr;}
2894 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2896 pointer __t = __ptr_.first();
2897 __ptr_.first() = pointer();
2901 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2902 template <class _Pp>
2903 _LIBCPP_INLINE_VISIBILITY
2904 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2905 reset(_Pp __p) _NOEXCEPT
2907 pointer __tmp = __ptr_.first();
2908 __ptr_.first() = __p;
2910 __ptr_.second()(__tmp);
2912 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2914 pointer __tmp = __ptr_.first();
2915 __ptr_.first() = nullptr;
2917 __ptr_.second()(__tmp);
2919 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2921 pointer __tmp = __ptr_.first();
2922 __ptr_.first() = nullptr;
2924 __ptr_.second()(__tmp);
2926 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2927 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2929 pointer __tmp = __ptr_.first();
2930 __ptr_.first() = __p;
2932 __ptr_.second()(__tmp);
2934 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2936 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2939 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2940 template <class _Up>
2941 explicit unique_ptr(_Up);
2942 template <class _Up>
2944 typename conditional<
2945 is_reference<deleter_type>::value,
2947 typename add_lvalue_reference<const deleter_type>::type>::type,
2950 is_convertible<_Up, pointer>::value,
2953 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2956 template <class _Tp, class _Dp>
2957 inline _LIBCPP_INLINE_VISIBILITY
2959 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2961 template <class _T1, class _D1, class _T2, class _D2>
2962 inline _LIBCPP_INLINE_VISIBILITY
2964 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2966 template <class _T1, class _D1, class _T2, class _D2>
2967 inline _LIBCPP_INLINE_VISIBILITY
2969 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2971 template <class _T1, class _D1, class _T2, class _D2>
2972 inline _LIBCPP_INLINE_VISIBILITY
2974 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2976 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2977 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2978 typedef typename common_type<_P1, _P2>::type _Vp;
2979 return less<_Vp>()(__x.get(), __y.get());
2982 template <class _T1, class _D1, class _T2, class _D2>
2983 inline _LIBCPP_INLINE_VISIBILITY
2985 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2987 template <class _T1, class _D1, class _T2, class _D2>
2988 inline _LIBCPP_INLINE_VISIBILITY
2990 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2992 template <class _T1, class _D1, class _T2, class _D2>
2993 inline _LIBCPP_INLINE_VISIBILITY
2995 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2997 template <class _T1, class _D1>
2998 inline _LIBCPP_INLINE_VISIBILITY
3000 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3005 template <class _T1, class _D1>
3006 inline _LIBCPP_INLINE_VISIBILITY
3008 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3013 template <class _T1, class _D1>
3014 inline _LIBCPP_INLINE_VISIBILITY
3016 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3018 return static_cast<bool>(__x);
3021 template <class _T1, class _D1>
3022 inline _LIBCPP_INLINE_VISIBILITY
3024 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3026 return static_cast<bool>(__x);
3029 template <class _T1, class _D1>
3030 inline _LIBCPP_INLINE_VISIBILITY
3032 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3034 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3035 return less<_P1>()(__x.get(), nullptr);
3038 template <class _T1, class _D1>
3039 inline _LIBCPP_INLINE_VISIBILITY
3041 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3043 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3044 return less<_P1>()(nullptr, __x.get());
3047 template <class _T1, class _D1>
3048 inline _LIBCPP_INLINE_VISIBILITY
3050 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3052 return nullptr < __x;
3055 template <class _T1, class _D1>
3056 inline _LIBCPP_INLINE_VISIBILITY
3058 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3060 return __x < nullptr;
3063 template <class _T1, class _D1>
3064 inline _LIBCPP_INLINE_VISIBILITY
3066 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3068 return !(nullptr < __x);
3071 template <class _T1, class _D1>
3072 inline _LIBCPP_INLINE_VISIBILITY
3074 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3076 return !(__x < nullptr);
3079 template <class _T1, class _D1>
3080 inline _LIBCPP_INLINE_VISIBILITY
3082 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3084 return !(__x < nullptr);
3087 template <class _T1, class _D1>
3088 inline _LIBCPP_INLINE_VISIBILITY
3090 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3092 return !(nullptr < __x);
3095 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3097 template <class _Tp, class _Dp>
3098 inline _LIBCPP_INLINE_VISIBILITY
3099 unique_ptr<_Tp, _Dp>
3100 move(unique_ptr<_Tp, _Dp>& __t)
3102 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3107 #if _LIBCPP_STD_VER > 11
3112 typedef unique_ptr<_Tp> __unique_single;
3116 struct __unique_if<_Tp[]>
3118 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3121 template<class _Tp, size_t _Np>
3122 struct __unique_if<_Tp[_Np]>
3124 typedef void __unique_array_known_bound;
3127 template<class _Tp, class... _Args>
3128 inline _LIBCPP_INLINE_VISIBILITY
3129 typename __unique_if<_Tp>::__unique_single
3130 make_unique(_Args&&... __args)
3132 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3136 inline _LIBCPP_INLINE_VISIBILITY
3137 typename __unique_if<_Tp>::__unique_array_unknown_bound
3138 make_unique(size_t __n)
3140 typedef typename remove_extent<_Tp>::type _Up;
3141 return unique_ptr<_Tp>(new _Up[__n]());
3144 template<class _Tp, class... _Args>
3145 typename __unique_if<_Tp>::__unique_array_known_bound
3146 make_unique(_Args&&...) = delete;
3148 #endif // _LIBCPP_STD_VER > 11
3150 template <class _Tp> struct hash;
3152 template <class _Size>
3153 inline _LIBCPP_INLINE_VISIBILITY
3155 __loadword(const void* __p)
3158 std::memcpy(&__r, __p, sizeof(__r));
3162 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3163 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3164 // multiplication, which can be very slow on 32-bit systems.
3165 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3166 struct __murmur2_or_cityhash;
3168 template <class _Size>
3169 struct __murmur2_or_cityhash<_Size, 32>
3171 _Size operator()(const void* __key, _Size __len);
3175 template <class _Size>
3177 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3179 const _Size __m = 0x5bd1e995;
3180 const _Size __r = 24;
3182 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3183 for (; __len >= 4; __data += 4, __len -= 4)
3185 _Size __k = __loadword<_Size>(__data);
3195 __h ^= __data[2] << 16;
3197 __h ^= __data[1] << 8;
3208 template <class _Size>
3209 struct __murmur2_or_cityhash<_Size, 64>
3211 _Size operator()(const void* __key, _Size __len);
3214 // Some primes between 2^63 and 2^64.
3215 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3216 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3217 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3218 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3220 static _Size __rotate(_Size __val, int __shift) {
3221 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3224 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3225 return (__val >> __shift) | (__val << (64 - __shift));
3228 static _Size __shift_mix(_Size __val) {
3229 return __val ^ (__val >> 47);
3232 static _Size __hash_len_16(_Size __u, _Size __v) {
3233 const _Size __mul = 0x9ddfea08eb382d69ULL;
3234 _Size __a = (__u ^ __v) * __mul;
3236 _Size __b = (__v ^ __a) * __mul;
3242 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3244 const _Size __a = __loadword<_Size>(__s);
3245 const _Size __b = __loadword<_Size>(__s + __len - 8);
3246 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3249 const uint32_t __a = __loadword<uint32_t>(__s);
3250 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3251 return __hash_len_16(__len + (__a << 3), __b);
3254 const unsigned char __a = __s[0];
3255 const unsigned char __b = __s[__len >> 1];
3256 const unsigned char __c = __s[__len - 1];
3257 const uint32_t __y = static_cast<uint32_t>(__a) +
3258 (static_cast<uint32_t>(__b) << 8);
3259 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3260 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3265 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3266 const _Size __a = __loadword<_Size>(__s) * __k1;
3267 const _Size __b = __loadword<_Size>(__s + 8);
3268 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3269 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3270 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3271 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3274 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3275 // Callers do best to use "random-looking" values for a and b.
3276 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3277 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3279 __b = __rotate(__b + __a + __z, 21);
3280 const _Size __c = __a;
3283 __b += __rotate(__a, 44);
3284 return pair<_Size, _Size>(__a + __z, __b + __c);
3287 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3288 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3289 const char* __s, _Size __a, _Size __b) {
3290 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3291 __loadword<_Size>(__s + 8),
3292 __loadword<_Size>(__s + 16),
3293 __loadword<_Size>(__s + 24),
3298 // Return an 8-byte hash for 33 to 64 bytes.
3299 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3300 _Size __z = __loadword<_Size>(__s + 24);
3301 _Size __a = __loadword<_Size>(__s) +
3302 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3303 _Size __b = __rotate(__a + __z, 52);
3304 _Size __c = __rotate(__a, 37);
3305 __a += __loadword<_Size>(__s + 8);
3306 __c += __rotate(__a, 7);
3307 __a += __loadword<_Size>(__s + 16);
3308 _Size __vf = __a + __z;
3309 _Size __vs = __b + __rotate(__a, 31) + __c;
3310 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3311 __z += __loadword<_Size>(__s + __len - 8);
3312 __b = __rotate(__a + __z, 52);
3313 __c = __rotate(__a, 37);
3314 __a += __loadword<_Size>(__s + __len - 24);
3315 __c += __rotate(__a, 7);
3316 __a += __loadword<_Size>(__s + __len - 16);
3317 _Size __wf = __a + __z;
3318 _Size __ws = __b + __rotate(__a, 31) + __c;
3319 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3320 return __shift_mix(__r * __k0 + __vs) * __k2;
3325 template <class _Size>
3327 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3329 const char* __s = static_cast<const char*>(__key);
3332 return __hash_len_0_to_16(__s, __len);
3334 return __hash_len_17_to_32(__s, __len);
3336 } else if (__len <= 64) {
3337 return __hash_len_33_to_64(__s, __len);
3340 // For strings over 64 bytes we hash the end first, and then as we
3341 // loop we keep 56 bytes of state: v, w, x, y, and z.
3342 _Size __x = __loadword<_Size>(__s + __len - 40);
3343 _Size __y = __loadword<_Size>(__s + __len - 16) +
3344 __loadword<_Size>(__s + __len - 56);
3345 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3346 __loadword<_Size>(__s + __len - 24));
3347 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3348 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3349 __x = __x * __k1 + __loadword<_Size>(__s);
3351 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3352 __len = (__len - 1) & ~static_cast<_Size>(63);
3354 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3355 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3357 __y += __v.first + __loadword<_Size>(__s + 40);
3358 __z = __rotate(__z + __w.first, 33) * __k1;
3359 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3360 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3361 __y + __loadword<_Size>(__s + 16));
3362 std::swap(__z, __x);
3365 } while (__len != 0);
3366 return __hash_len_16(
3367 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3368 __hash_len_16(__v.second, __w.second) + __x);
3371 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3372 struct __scalar_hash;
3374 template <class _Tp>
3375 struct __scalar_hash<_Tp, 0>
3376 : public unary_function<_Tp, size_t>
3378 _LIBCPP_INLINE_VISIBILITY
3379 size_t operator()(_Tp __v) const _NOEXCEPT
3392 template <class _Tp>
3393 struct __scalar_hash<_Tp, 1>
3394 : public unary_function<_Tp, size_t>
3396 _LIBCPP_INLINE_VISIBILITY
3397 size_t operator()(_Tp __v) const _NOEXCEPT
3409 template <class _Tp>
3410 struct __scalar_hash<_Tp, 2>
3411 : public unary_function<_Tp, size_t>
3413 _LIBCPP_INLINE_VISIBILITY
3414 size_t operator()(_Tp __v) const _NOEXCEPT
3426 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3430 template <class _Tp>
3431 struct __scalar_hash<_Tp, 3>
3432 : public unary_function<_Tp, size_t>
3434 _LIBCPP_INLINE_VISIBILITY
3435 size_t operator()(_Tp __v) const _NOEXCEPT
3448 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3452 template <class _Tp>
3453 struct __scalar_hash<_Tp, 4>
3454 : public unary_function<_Tp, size_t>
3456 _LIBCPP_INLINE_VISIBILITY
3457 size_t operator()(_Tp __v) const _NOEXCEPT
3471 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3476 struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3477 : public unary_function<_Tp*, size_t>
3479 _LIBCPP_INLINE_VISIBILITY
3480 size_t operator()(_Tp* __v) const _NOEXCEPT
3488 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3492 template <class _Tp, class _Dp>
3493 struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
3495 typedef unique_ptr<_Tp, _Dp> argument_type;
3496 typedef size_t result_type;
3497 _LIBCPP_INLINE_VISIBILITY
3498 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3500 typedef typename argument_type::pointer pointer;
3501 return hash<pointer>()(__ptr.get());
3510 template <class _Tp>
3511 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3512 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3514 template <class _Tp>
3515 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3518 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3520 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3523 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3525 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3528 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3531 template <class _Tp>
3532 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3533 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3535 template <class _Tp>
3536 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3537 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3539 template <class _Tp>
3540 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3541 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3544 template <class _Alloc>
3545 class __allocator_destructor
3547 typedef allocator_traits<_Alloc> __alloc_traits;
3549 typedef typename __alloc_traits::pointer pointer;
3550 typedef typename __alloc_traits::size_type size_type;
3555 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3557 : __alloc_(__a), __s_(__s) {}
3558 _LIBCPP_INLINE_VISIBILITY
3559 void operator()(pointer __p) _NOEXCEPT
3560 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3563 template <class _InputIterator, class _ForwardIterator>
3565 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3567 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3568 #ifndef _LIBCPP_NO_EXCEPTIONS
3569 _ForwardIterator __s = __r;
3573 for (; __f != __l; ++__f, (void) ++__r)
3574 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3575 #ifndef _LIBCPP_NO_EXCEPTIONS
3579 for (; __s != __r; ++__s)
3587 template <class _InputIterator, class _Size, class _ForwardIterator>
3589 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3591 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3592 #ifndef _LIBCPP_NO_EXCEPTIONS
3593 _ForwardIterator __s = __r;
3597 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3598 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3599 #ifndef _LIBCPP_NO_EXCEPTIONS
3603 for (; __s != __r; ++__s)
3611 template <class _ForwardIterator, class _Tp>
3613 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3615 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3616 #ifndef _LIBCPP_NO_EXCEPTIONS
3617 _ForwardIterator __s = __f;
3621 for (; __f != __l; ++__f)
3622 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3623 #ifndef _LIBCPP_NO_EXCEPTIONS
3627 for (; __s != __f; ++__s)
3634 template <class _ForwardIterator, class _Size, class _Tp>
3636 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3638 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3639 #ifndef _LIBCPP_NO_EXCEPTIONS
3640 _ForwardIterator __s = __f;
3644 for (; __n > 0; ++__f, (void) --__n)
3645 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3646 #ifndef _LIBCPP_NO_EXCEPTIONS
3650 for (; __s != __f; ++__s)
3658 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3659 : public std::exception
3662 virtual ~bad_weak_ptr() _NOEXCEPT;
3663 virtual const char* what() const _NOEXCEPT;
3666 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3668 class _LIBCPP_TYPE_VIS __shared_count
3670 __shared_count(const __shared_count&);
3671 __shared_count& operator=(const __shared_count&);
3674 long __shared_owners_;
3675 virtual ~__shared_count();
3677 virtual void __on_zero_shared() _NOEXCEPT = 0;
3680 _LIBCPP_INLINE_VISIBILITY
3681 explicit __shared_count(long __refs = 0) _NOEXCEPT
3682 : __shared_owners_(__refs) {}
3684 void __add_shared() _NOEXCEPT;
3685 bool __release_shared() _NOEXCEPT;
3686 _LIBCPP_INLINE_VISIBILITY
3687 long use_count() const _NOEXCEPT {
3688 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3692 class _LIBCPP_TYPE_VIS __shared_weak_count
3693 : private __shared_count
3695 long __shared_weak_owners_;
3698 _LIBCPP_INLINE_VISIBILITY
3699 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3700 : __shared_count(__refs),
3701 __shared_weak_owners_(__refs) {}
3703 virtual ~__shared_weak_count();
3706 void __add_shared() _NOEXCEPT;
3707 void __add_weak() _NOEXCEPT;
3708 void __release_shared() _NOEXCEPT;
3709 void __release_weak() _NOEXCEPT;
3710 _LIBCPP_INLINE_VISIBILITY
3711 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3712 __shared_weak_count* lock() _NOEXCEPT;
3714 // Define the function out only if we build static libc++ without RTTI.
3715 // Otherwise we may break clients who need to compile their projects with
3716 // -fno-rtti and yet link against a libc++.dylib compiled
3717 // without -fno-rtti.
3718 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3719 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3722 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3725 template <class _Tp, class _Dp, class _Alloc>
3726 class __shared_ptr_pointer
3727 : public __shared_weak_count
3729 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3731 _LIBCPP_INLINE_VISIBILITY
3732 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3733 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3735 #ifndef _LIBCPP_NO_RTTI
3736 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3740 virtual void __on_zero_shared() _NOEXCEPT;
3741 virtual void __on_zero_shared_weak() _NOEXCEPT;
3744 #ifndef _LIBCPP_NO_RTTI
3746 template <class _Tp, class _Dp, class _Alloc>
3748 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3750 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
3753 #endif // _LIBCPP_NO_RTTI
3755 template <class _Tp, class _Dp, class _Alloc>
3757 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3759 __data_.first().second()(__data_.first().first());
3760 __data_.first().second().~_Dp();
3763 template <class _Tp, class _Dp, class _Alloc>
3765 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3767 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3768 typedef allocator_traits<_Al> _ATraits;
3769 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3771 _Al __a(__data_.second());
3772 __data_.second().~_Alloc();
3773 __a.deallocate(_PTraits::pointer_to(*this), 1);
3776 template <class _Tp, class _Alloc>
3777 class __shared_ptr_emplace
3778 : public __shared_weak_count
3780 __compressed_pair<_Alloc, _Tp> __data_;
3782 #ifndef _LIBCPP_HAS_NO_VARIADICS
3784 _LIBCPP_INLINE_VISIBILITY
3785 __shared_ptr_emplace(_Alloc __a)
3786 : __data_(_VSTD::move(__a)) {}
3788 template <class ..._Args>
3789 _LIBCPP_INLINE_VISIBILITY
3790 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3791 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3792 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3794 #else // _LIBCPP_HAS_NO_VARIADICS
3796 _LIBCPP_INLINE_VISIBILITY
3797 __shared_ptr_emplace(_Alloc __a)
3800 template <class _A0>
3801 _LIBCPP_INLINE_VISIBILITY
3802 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3803 : __data_(__a, _Tp(__a0)) {}
3805 template <class _A0, class _A1>
3806 _LIBCPP_INLINE_VISIBILITY
3807 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3808 : __data_(__a, _Tp(__a0, __a1)) {}
3810 template <class _A0, class _A1, class _A2>
3811 _LIBCPP_INLINE_VISIBILITY
3812 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3813 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3815 #endif // _LIBCPP_HAS_NO_VARIADICS
3818 virtual void __on_zero_shared() _NOEXCEPT;
3819 virtual void __on_zero_shared_weak() _NOEXCEPT;
3821 _LIBCPP_INLINE_VISIBILITY
3822 _Tp* get() _NOEXCEPT {return &__data_.second();}
3825 template <class _Tp, class _Alloc>
3827 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3829 __data_.second().~_Tp();
3832 template <class _Tp, class _Alloc>
3834 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3836 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3837 typedef allocator_traits<_Al> _ATraits;
3838 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3839 _Al __a(__data_.first());
3840 __data_.first().~_Alloc();
3841 __a.deallocate(_PTraits::pointer_to(*this), 1);
3844 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3847 class _LIBCPP_TYPE_VIS_ONLY shared_ptr
3850 typedef _Tp element_type;
3852 element_type* __ptr_;
3853 __shared_weak_count* __cntrl_;
3855 struct __nat {int __for_bool_;};
3857 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3858 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3860 explicit shared_ptr(_Yp* __p,
3861 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3862 template<class _Yp, class _Dp>
3863 shared_ptr(_Yp* __p, _Dp __d,
3864 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3865 template<class _Yp, class _Dp, class _Alloc>
3866 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3867 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3868 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3869 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3870 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3871 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3873 shared_ptr(const shared_ptr<_Yp>& __r,
3874 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3876 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3877 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3878 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3879 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3881 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3882 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3883 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3884 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3886 shared_ptr(auto_ptr<_Yp>&& __r,
3887 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3890 shared_ptr(auto_ptr<_Yp> __r,
3891 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3893 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3894 template <class _Yp, class _Dp>
3895 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3898 !is_lvalue_reference<_Dp>::value &&
3899 !is_array<_Yp>::value &&
3900 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3903 template <class _Yp, class _Dp>
3904 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3907 is_lvalue_reference<_Dp>::value &&
3908 !is_array<_Yp>::value &&
3909 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3912 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3913 template <class _Yp, class _Dp>
3914 shared_ptr(unique_ptr<_Yp, _Dp>,
3917 !is_lvalue_reference<_Dp>::value &&
3918 !is_array<_Yp>::value &&
3919 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3922 template <class _Yp, class _Dp>
3923 shared_ptr(unique_ptr<_Yp, _Dp>,
3926 is_lvalue_reference<_Dp>::value &&
3927 !is_array<_Yp>::value &&
3928 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3931 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3935 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3939 is_convertible<_Yp*, element_type*>::value,
3942 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3943 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3944 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3948 is_convertible<_Yp*, element_type*>::value,
3951 operator=(shared_ptr<_Yp>&& __r);
3955 !is_array<_Yp>::value &&
3956 is_convertible<_Yp*, element_type*>::value,
3959 operator=(auto_ptr<_Yp>&& __r);
3960 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3964 !is_array<_Yp>::value &&
3965 is_convertible<_Yp*, element_type*>::value,
3968 operator=(auto_ptr<_Yp> __r);
3970 template <class _Yp, class _Dp>
3973 !is_array<_Yp>::value &&
3974 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3977 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3978 operator=(unique_ptr<_Yp, _Dp>&& __r);
3979 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3980 operator=(unique_ptr<_Yp, _Dp> __r);
3983 void swap(shared_ptr& __r) _NOEXCEPT;
3984 void reset() _NOEXCEPT;
3988 is_convertible<_Yp*, element_type*>::value,
3992 template<class _Yp, class _Dp>
3995 is_convertible<_Yp*, element_type*>::value,
3998 reset(_Yp* __p, _Dp __d);
3999 template<class _Yp, class _Dp, class _Alloc>
4002 is_convertible<_Yp*, element_type*>::value,
4005 reset(_Yp* __p, _Dp __d, _Alloc __a);
4007 _LIBCPP_INLINE_VISIBILITY
4008 element_type* get() const _NOEXCEPT {return __ptr_;}
4009 _LIBCPP_INLINE_VISIBILITY
4010 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4012 _LIBCPP_INLINE_VISIBILITY
4013 element_type* operator->() const _NOEXCEPT {return __ptr_;}
4014 _LIBCPP_INLINE_VISIBILITY
4015 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4016 _LIBCPP_INLINE_VISIBILITY
4017 bool unique() const _NOEXCEPT {return use_count() == 1;}
4018 _LIBCPP_INLINE_VISIBILITY
4019 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4020 template <class _Up>
4021 _LIBCPP_INLINE_VISIBILITY
4022 bool owner_before(shared_ptr<_Up> const& __p) const
4023 {return __cntrl_ < __p.__cntrl_;}
4024 template <class _Up>
4025 _LIBCPP_INLINE_VISIBILITY
4026 bool owner_before(weak_ptr<_Up> const& __p) const
4027 {return __cntrl_ < __p.__cntrl_;}
4028 _LIBCPP_INLINE_VISIBILITY
4030 __owner_equivalent(const shared_ptr& __p) const
4031 {return __cntrl_ == __p.__cntrl_;}
4033 #ifndef _LIBCPP_NO_RTTI
4034 template <class _Dp>
4035 _LIBCPP_INLINE_VISIBILITY
4036 _Dp* __get_deleter() const _NOEXCEPT
4037 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4038 #endif // _LIBCPP_NO_RTTI
4040 #ifndef _LIBCPP_HAS_NO_VARIADICS
4042 template<class ..._Args>
4045 make_shared(_Args&& ...__args);
4047 template<class _Alloc, class ..._Args>
4050 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4052 #else // _LIBCPP_HAS_NO_VARIADICS
4054 static shared_ptr<_Tp> make_shared();
4057 static shared_ptr<_Tp> make_shared(_A0&);
4059 template<class _A0, class _A1>
4060 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4062 template<class _A0, class _A1, class _A2>
4063 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4065 template<class _Alloc>
4066 static shared_ptr<_Tp>
4067 allocate_shared(const _Alloc& __a);
4069 template<class _Alloc, class _A0>
4070 static shared_ptr<_Tp>
4071 allocate_shared(const _Alloc& __a, _A0& __a0);
4073 template<class _Alloc, class _A0, class _A1>
4074 static shared_ptr<_Tp>
4075 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4077 template<class _Alloc, class _A0, class _A1, class _A2>
4078 static shared_ptr<_Tp>
4079 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4081 #endif // _LIBCPP_HAS_NO_VARIADICS
4085 template <class _Yp>
4086 _LIBCPP_INLINE_VISIBILITY
4088 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4092 __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e));
4093 __e->__weak_this_.__cntrl_ = __cntrl_;
4094 __cntrl_->__add_weak();
4098 _LIBCPP_INLINE_VISIBILITY
4099 void __enable_weak_this(const volatile void*) _NOEXCEPT {}
4101 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4102 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4106 inline _LIBCPP_INLINE_VISIBILITY
4108 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4115 inline _LIBCPP_INLINE_VISIBILITY
4117 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4125 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4126 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4129 unique_ptr<_Yp> __hold(__p);
4130 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4131 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4133 __enable_weak_this(__p);
4137 template<class _Yp, class _Dp>
4138 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4139 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4142 #ifndef _LIBCPP_NO_EXCEPTIONS
4145 #endif // _LIBCPP_NO_EXCEPTIONS
4146 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4147 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4148 __enable_weak_this(__p);
4149 #ifndef _LIBCPP_NO_EXCEPTIONS
4156 #endif // _LIBCPP_NO_EXCEPTIONS
4161 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4164 #ifndef _LIBCPP_NO_EXCEPTIONS
4167 #endif // _LIBCPP_NO_EXCEPTIONS
4168 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4169 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4170 #ifndef _LIBCPP_NO_EXCEPTIONS
4177 #endif // _LIBCPP_NO_EXCEPTIONS
4181 template<class _Yp, class _Dp, class _Alloc>
4182 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4183 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4186 #ifndef _LIBCPP_NO_EXCEPTIONS
4189 #endif // _LIBCPP_NO_EXCEPTIONS
4190 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4191 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4192 typedef __allocator_destructor<_A2> _D2;
4194 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4195 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4196 _CntrlBlk(__p, __d, __a);
4197 __cntrl_ = _VSTD::addressof(*__hold2.release());
4198 __enable_weak_this(__p);
4199 #ifndef _LIBCPP_NO_EXCEPTIONS
4206 #endif // _LIBCPP_NO_EXCEPTIONS
4210 template<class _Dp, class _Alloc>
4211 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4214 #ifndef _LIBCPP_NO_EXCEPTIONS
4217 #endif // _LIBCPP_NO_EXCEPTIONS
4218 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4219 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4220 typedef __allocator_destructor<_A2> _D2;
4222 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4223 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4224 _CntrlBlk(__p, __d, __a);
4225 __cntrl_ = _VSTD::addressof(*__hold2.release());
4226 #ifndef _LIBCPP_NO_EXCEPTIONS
4233 #endif // _LIBCPP_NO_EXCEPTIONS
4238 inline _LIBCPP_INLINE_VISIBILITY
4239 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4241 __cntrl_(__r.__cntrl_)
4244 __cntrl_->__add_shared();
4248 inline _LIBCPP_INLINE_VISIBILITY
4249 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4250 : __ptr_(__r.__ptr_),
4251 __cntrl_(__r.__cntrl_)
4254 __cntrl_->__add_shared();
4259 inline _LIBCPP_INLINE_VISIBILITY
4260 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4261 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4263 : __ptr_(__r.__ptr_),
4264 __cntrl_(__r.__cntrl_)
4267 __cntrl_->__add_shared();
4270 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4273 inline _LIBCPP_INLINE_VISIBILITY
4274 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4275 : __ptr_(__r.__ptr_),
4276 __cntrl_(__r.__cntrl_)
4284 inline _LIBCPP_INLINE_VISIBILITY
4285 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4286 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4288 : __ptr_(__r.__ptr_),
4289 __cntrl_(__r.__cntrl_)
4295 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4299 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4300 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4302 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4304 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4307 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4308 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4309 __enable_weak_this(__r.get());
4314 template <class _Yp, class _Dp>
4315 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4316 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4318 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4322 !is_lvalue_reference<_Dp>::value &&
4323 !is_array<_Yp>::value &&
4324 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4329 #if _LIBCPP_STD_VER > 11
4330 if (__ptr_ == nullptr)
4335 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4336 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4337 __enable_weak_this(__r.get());
4343 template <class _Yp, class _Dp>
4344 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4345 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4347 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4351 is_lvalue_reference<_Dp>::value &&
4352 !is_array<_Yp>::value &&
4353 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4358 #if _LIBCPP_STD_VER > 11
4359 if (__ptr_ == nullptr)
4364 typedef __shared_ptr_pointer<_Yp*,
4365 reference_wrapper<typename remove_reference<_Dp>::type>,
4366 allocator<_Yp> > _CntrlBlk;
4367 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4368 __enable_weak_this(__r.get());
4373 #ifndef _LIBCPP_HAS_NO_VARIADICS
4376 template<class ..._Args>
4378 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4380 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4381 typedef allocator<_CntrlBlk> _A2;
4382 typedef __allocator_destructor<_A2> _D2;
4384 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4385 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4386 shared_ptr<_Tp> __r;
4387 __r.__ptr_ = __hold2.get()->get();
4388 __r.__cntrl_ = __hold2.release();
4389 __r.__enable_weak_this(__r.__ptr_);
4394 template<class _Alloc, class ..._Args>
4396 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4398 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4399 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4400 typedef __allocator_destructor<_A2> _D2;
4402 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4403 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4404 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4405 shared_ptr<_Tp> __r;
4406 __r.__ptr_ = __hold2.get()->get();
4407 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4408 __r.__enable_weak_this(__r.__ptr_);
4412 #else // _LIBCPP_HAS_NO_VARIADICS
4416 shared_ptr<_Tp>::make_shared()
4418 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4419 typedef allocator<_CntrlBlk> _Alloc2;
4420 typedef __allocator_destructor<_Alloc2> _D2;
4422 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4423 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4424 shared_ptr<_Tp> __r;
4425 __r.__ptr_ = __hold2.get()->get();
4426 __r.__cntrl_ = __hold2.release();
4427 __r.__enable_weak_this(__r.__ptr_);
4434 shared_ptr<_Tp>::make_shared(_A0& __a0)
4436 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4437 typedef allocator<_CntrlBlk> _Alloc2;
4438 typedef __allocator_destructor<_Alloc2> _D2;
4440 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4441 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4442 shared_ptr<_Tp> __r;
4443 __r.__ptr_ = __hold2.get()->get();
4444 __r.__cntrl_ = __hold2.release();
4445 __r.__enable_weak_this(__r.__ptr_);
4450 template<class _A0, class _A1>
4452 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4454 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4455 typedef allocator<_CntrlBlk> _Alloc2;
4456 typedef __allocator_destructor<_Alloc2> _D2;
4458 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4459 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4460 shared_ptr<_Tp> __r;
4461 __r.__ptr_ = __hold2.get()->get();
4462 __r.__cntrl_ = __hold2.release();
4463 __r.__enable_weak_this(__r.__ptr_);
4468 template<class _A0, class _A1, class _A2>
4470 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4472 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4473 typedef allocator<_CntrlBlk> _Alloc2;
4474 typedef __allocator_destructor<_Alloc2> _D2;
4476 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4477 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4478 shared_ptr<_Tp> __r;
4479 __r.__ptr_ = __hold2.get()->get();
4480 __r.__cntrl_ = __hold2.release();
4481 __r.__enable_weak_this(__r.__ptr_);
4486 template<class _Alloc>
4488 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4490 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4491 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4492 typedef __allocator_destructor<_Alloc2> _D2;
4493 _Alloc2 __alloc2(__a);
4494 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4495 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4497 shared_ptr<_Tp> __r;
4498 __r.__ptr_ = __hold2.get()->get();
4499 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4500 __r.__enable_weak_this(__r.__ptr_);
4505 template<class _Alloc, class _A0>
4507 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4509 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4510 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4511 typedef __allocator_destructor<_Alloc2> _D2;
4512 _Alloc2 __alloc2(__a);
4513 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4514 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4515 _CntrlBlk(__a, __a0);
4516 shared_ptr<_Tp> __r;
4517 __r.__ptr_ = __hold2.get()->get();
4518 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4519 __r.__enable_weak_this(__r.__ptr_);
4524 template<class _Alloc, class _A0, class _A1>
4526 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
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())))
4534 _CntrlBlk(__a, __a0, __a1);
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_);
4543 template<class _Alloc, class _A0, class _A1, class _A2>
4545 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
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, __a1, __a2);
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_);
4561 #endif // _LIBCPP_HAS_NO_VARIADICS
4564 shared_ptr<_Tp>::~shared_ptr()
4567 __cntrl_->__release_shared();
4571 inline _LIBCPP_INLINE_VISIBILITY
4573 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4575 shared_ptr(__r).swap(*this);
4581 inline _LIBCPP_INLINE_VISIBILITY
4584 is_convertible<_Yp*, _Tp*>::value,
4587 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4589 shared_ptr(__r).swap(*this);
4593 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4596 inline _LIBCPP_INLINE_VISIBILITY
4598 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4600 shared_ptr(_VSTD::move(__r)).swap(*this);
4606 inline _LIBCPP_INLINE_VISIBILITY
4609 is_convertible<_Yp*, _Tp*>::value,
4612 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4614 shared_ptr(_VSTD::move(__r)).swap(*this);
4620 inline _LIBCPP_INLINE_VISIBILITY
4623 !is_array<_Yp>::value &&
4624 is_convertible<_Yp*, _Tp*>::value,
4627 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4629 shared_ptr(_VSTD::move(__r)).swap(*this);
4634 template <class _Yp, class _Dp>
4635 inline _LIBCPP_INLINE_VISIBILITY
4638 !is_array<_Yp>::value &&
4639 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4642 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4644 shared_ptr(_VSTD::move(__r)).swap(*this);
4648 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4652 inline _LIBCPP_INLINE_VISIBILITY
4655 !is_array<_Yp>::value &&
4656 is_convertible<_Yp*, _Tp*>::value,
4659 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4661 shared_ptr(__r).swap(*this);
4666 template <class _Yp, class _Dp>
4667 inline _LIBCPP_INLINE_VISIBILITY
4670 !is_array<_Yp>::value &&
4671 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4674 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4676 shared_ptr(_VSTD::move(__r)).swap(*this);
4680 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4683 inline _LIBCPP_INLINE_VISIBILITY
4685 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4687 _VSTD::swap(__ptr_, __r.__ptr_);
4688 _VSTD::swap(__cntrl_, __r.__cntrl_);
4692 inline _LIBCPP_INLINE_VISIBILITY
4694 shared_ptr<_Tp>::reset() _NOEXCEPT
4696 shared_ptr().swap(*this);
4701 inline _LIBCPP_INLINE_VISIBILITY
4704 is_convertible<_Yp*, _Tp*>::value,
4707 shared_ptr<_Tp>::reset(_Yp* __p)
4709 shared_ptr(__p).swap(*this);
4713 template<class _Yp, class _Dp>
4714 inline _LIBCPP_INLINE_VISIBILITY
4717 is_convertible<_Yp*, _Tp*>::value,
4720 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4722 shared_ptr(__p, __d).swap(*this);
4726 template<class _Yp, class _Dp, class _Alloc>
4727 inline _LIBCPP_INLINE_VISIBILITY
4730 is_convertible<_Yp*, _Tp*>::value,
4733 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4735 shared_ptr(__p, __d, __a).swap(*this);
4738 #ifndef _LIBCPP_HAS_NO_VARIADICS
4740 template<class _Tp, class ..._Args>
4741 inline _LIBCPP_INLINE_VISIBILITY
4744 !is_array<_Tp>::value,
4747 make_shared(_Args&& ...__args)
4749 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4752 template<class _Tp, class _Alloc, class ..._Args>
4753 inline _LIBCPP_INLINE_VISIBILITY
4756 !is_array<_Tp>::value,
4759 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4761 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4764 #else // _LIBCPP_HAS_NO_VARIADICS
4767 inline _LIBCPP_INLINE_VISIBILITY
4771 return shared_ptr<_Tp>::make_shared();
4774 template<class _Tp, class _A0>
4775 inline _LIBCPP_INLINE_VISIBILITY
4777 make_shared(_A0& __a0)
4779 return shared_ptr<_Tp>::make_shared(__a0);
4782 template<class _Tp, class _A0, class _A1>
4783 inline _LIBCPP_INLINE_VISIBILITY
4785 make_shared(_A0& __a0, _A1& __a1)
4787 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4790 template<class _Tp, class _A0, class _A1, class _A2>
4791 inline _LIBCPP_INLINE_VISIBILITY
4793 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4795 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4798 template<class _Tp, class _Alloc>
4799 inline _LIBCPP_INLINE_VISIBILITY
4801 allocate_shared(const _Alloc& __a)
4803 return shared_ptr<_Tp>::allocate_shared(__a);
4806 template<class _Tp, class _Alloc, class _A0>
4807 inline _LIBCPP_INLINE_VISIBILITY
4809 allocate_shared(const _Alloc& __a, _A0& __a0)
4811 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4814 template<class _Tp, class _Alloc, class _A0, class _A1>
4815 inline _LIBCPP_INLINE_VISIBILITY
4817 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4819 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4822 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4823 inline _LIBCPP_INLINE_VISIBILITY
4825 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4827 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4830 #endif // _LIBCPP_HAS_NO_VARIADICS
4832 template<class _Tp, class _Up>
4833 inline _LIBCPP_INLINE_VISIBILITY
4835 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4837 return __x.get() == __y.get();
4840 template<class _Tp, class _Up>
4841 inline _LIBCPP_INLINE_VISIBILITY
4843 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4845 return !(__x == __y);
4848 template<class _Tp, class _Up>
4849 inline _LIBCPP_INLINE_VISIBILITY
4851 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4853 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4854 return less<_Vp>()(__x.get(), __y.get());
4857 template<class _Tp, class _Up>
4858 inline _LIBCPP_INLINE_VISIBILITY
4860 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4865 template<class _Tp, class _Up>
4866 inline _LIBCPP_INLINE_VISIBILITY
4868 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4870 return !(__y < __x);
4873 template<class _Tp, class _Up>
4874 inline _LIBCPP_INLINE_VISIBILITY
4876 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4878 return !(__x < __y);
4882 inline _LIBCPP_INLINE_VISIBILITY
4884 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4890 inline _LIBCPP_INLINE_VISIBILITY
4892 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4898 inline _LIBCPP_INLINE_VISIBILITY
4900 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4902 return static_cast<bool>(__x);
4906 inline _LIBCPP_INLINE_VISIBILITY
4908 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4910 return static_cast<bool>(__x);
4914 inline _LIBCPP_INLINE_VISIBILITY
4916 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4918 return less<_Tp*>()(__x.get(), nullptr);
4922 inline _LIBCPP_INLINE_VISIBILITY
4924 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4926 return less<_Tp*>()(nullptr, __x.get());
4930 inline _LIBCPP_INLINE_VISIBILITY
4932 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4934 return nullptr < __x;
4938 inline _LIBCPP_INLINE_VISIBILITY
4940 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4942 return __x < nullptr;
4946 inline _LIBCPP_INLINE_VISIBILITY
4948 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4950 return !(nullptr < __x);
4954 inline _LIBCPP_INLINE_VISIBILITY
4956 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4958 return !(__x < nullptr);
4962 inline _LIBCPP_INLINE_VISIBILITY
4964 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4966 return !(__x < nullptr);
4970 inline _LIBCPP_INLINE_VISIBILITY
4972 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4974 return !(nullptr < __x);
4978 inline _LIBCPP_INLINE_VISIBILITY
4980 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4985 template<class _Tp, class _Up>
4986 inline _LIBCPP_INLINE_VISIBILITY
4989 !is_array<_Tp>::value && !is_array<_Up>::value,
4992 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4994 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4997 template<class _Tp, class _Up>
4998 inline _LIBCPP_INLINE_VISIBILITY
5001 !is_array<_Tp>::value && !is_array<_Up>::value,
5004 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5006 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5007 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5010 template<class _Tp, class _Up>
5013 is_array<_Tp>::value == is_array<_Up>::value,
5016 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5018 typedef typename remove_extent<_Tp>::type _RTp;
5019 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
5022 #ifndef _LIBCPP_NO_RTTI
5024 template<class _Dp, class _Tp>
5025 inline _LIBCPP_INLINE_VISIBILITY
5027 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
5029 return __p.template __get_deleter<_Dp>();
5032 #endif // _LIBCPP_NO_RTTI
5035 class _LIBCPP_TYPE_VIS_ONLY weak_ptr
5038 typedef _Tp element_type;
5040 element_type* __ptr_;
5041 __shared_weak_count* __cntrl_;
5044 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
5045 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
5046 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5048 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
5049 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
5050 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5053 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5054 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5055 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
5056 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5058 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5061 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5065 is_convertible<_Yp*, element_type*>::value,
5068 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5070 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5072 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5076 is_convertible<_Yp*, element_type*>::value,
5079 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5081 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5086 is_convertible<_Yp*, element_type*>::value,
5089 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5091 void swap(weak_ptr& __r) _NOEXCEPT;
5092 void reset() _NOEXCEPT;
5094 _LIBCPP_INLINE_VISIBILITY
5095 long use_count() const _NOEXCEPT
5096 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5097 _LIBCPP_INLINE_VISIBILITY
5098 bool expired() const _NOEXCEPT
5099 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5100 shared_ptr<_Tp> lock() const _NOEXCEPT;
5102 _LIBCPP_INLINE_VISIBILITY
5103 bool owner_before(const shared_ptr<_Up>& __r) const
5104 {return __cntrl_ < __r.__cntrl_;}
5106 _LIBCPP_INLINE_VISIBILITY
5107 bool owner_before(const weak_ptr<_Up>& __r) const
5108 {return __cntrl_ < __r.__cntrl_;}
5110 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5111 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
5115 inline _LIBCPP_INLINE_VISIBILITY
5117 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5124 inline _LIBCPP_INLINE_VISIBILITY
5125 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5126 : __ptr_(__r.__ptr_),
5127 __cntrl_(__r.__cntrl_)
5130 __cntrl_->__add_weak();
5135 inline _LIBCPP_INLINE_VISIBILITY
5136 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5137 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5139 : __ptr_(__r.__ptr_),
5140 __cntrl_(__r.__cntrl_)
5143 __cntrl_->__add_weak();
5148 inline _LIBCPP_INLINE_VISIBILITY
5149 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5150 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5152 : __ptr_(__r.__ptr_),
5153 __cntrl_(__r.__cntrl_)
5156 __cntrl_->__add_weak();
5159 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5162 inline _LIBCPP_INLINE_VISIBILITY
5163 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5164 : __ptr_(__r.__ptr_),
5165 __cntrl_(__r.__cntrl_)
5173 inline _LIBCPP_INLINE_VISIBILITY
5174 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5175 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5177 : __ptr_(__r.__ptr_),
5178 __cntrl_(__r.__cntrl_)
5184 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5187 weak_ptr<_Tp>::~weak_ptr()
5190 __cntrl_->__release_weak();
5194 inline _LIBCPP_INLINE_VISIBILITY
5196 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5198 weak_ptr(__r).swap(*this);
5204 inline _LIBCPP_INLINE_VISIBILITY
5207 is_convertible<_Yp*, _Tp*>::value,
5210 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5212 weak_ptr(__r).swap(*this);
5216 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5219 inline _LIBCPP_INLINE_VISIBILITY
5221 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5223 weak_ptr(_VSTD::move(__r)).swap(*this);
5229 inline _LIBCPP_INLINE_VISIBILITY
5232 is_convertible<_Yp*, _Tp*>::value,
5235 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5237 weak_ptr(_VSTD::move(__r)).swap(*this);
5241 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5245 inline _LIBCPP_INLINE_VISIBILITY
5248 is_convertible<_Yp*, _Tp*>::value,
5251 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5253 weak_ptr(__r).swap(*this);
5258 inline _LIBCPP_INLINE_VISIBILITY
5260 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5262 _VSTD::swap(__ptr_, __r.__ptr_);
5263 _VSTD::swap(__cntrl_, __r.__cntrl_);
5267 inline _LIBCPP_INLINE_VISIBILITY
5269 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5275 inline _LIBCPP_INLINE_VISIBILITY
5277 weak_ptr<_Tp>::reset() _NOEXCEPT
5279 weak_ptr().swap(*this);
5284 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5285 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5286 : __ptr_(__r.__ptr_),
5287 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5290 #ifndef _LIBCPP_NO_EXCEPTIONS
5291 throw bad_weak_ptr();
5293 assert(!"bad_weak_ptr");
5299 weak_ptr<_Tp>::lock() const _NOEXCEPT
5301 shared_ptr<_Tp> __r;
5302 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5304 __r.__ptr_ = __ptr_;
5308 template <class _Tp> struct owner_less;
5310 template <class _Tp>
5311 struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
5312 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5314 typedef bool result_type;
5315 _LIBCPP_INLINE_VISIBILITY
5316 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5317 {return __x.owner_before(__y);}
5318 _LIBCPP_INLINE_VISIBILITY
5319 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5320 {return __x.owner_before(__y);}
5321 _LIBCPP_INLINE_VISIBILITY
5322 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5323 {return __x.owner_before(__y);}
5326 template <class _Tp>
5327 struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
5328 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5330 typedef bool result_type;
5331 _LIBCPP_INLINE_VISIBILITY
5332 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5333 {return __x.owner_before(__y);}
5334 _LIBCPP_INLINE_VISIBILITY
5335 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5336 {return __x.owner_before(__y);}
5337 _LIBCPP_INLINE_VISIBILITY
5338 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5339 {return __x.owner_before(__y);}
5343 class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5345 mutable weak_ptr<_Tp> __weak_this_;
5347 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5348 enable_shared_from_this() _NOEXCEPT {}
5349 _LIBCPP_INLINE_VISIBILITY
5350 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5351 _LIBCPP_INLINE_VISIBILITY
5352 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5354 _LIBCPP_INLINE_VISIBILITY
5355 ~enable_shared_from_this() {}
5357 _LIBCPP_INLINE_VISIBILITY
5358 shared_ptr<_Tp> shared_from_this()
5359 {return shared_ptr<_Tp>(__weak_this_);}
5360 _LIBCPP_INLINE_VISIBILITY
5361 shared_ptr<_Tp const> shared_from_this() const
5362 {return shared_ptr<const _Tp>(__weak_this_);}
5364 template <class _Up> friend class shared_ptr;
5367 template <class _Tp>
5368 struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
5370 typedef shared_ptr<_Tp> argument_type;
5371 typedef size_t result_type;
5372 _LIBCPP_INLINE_VISIBILITY
5373 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5375 return hash<_Tp*>()(__ptr.get());
5379 template<class _CharT, class _Traits, class _Yp>
5380 inline _LIBCPP_INLINE_VISIBILITY
5381 basic_ostream<_CharT, _Traits>&
5382 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5384 // TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
5385 // enabled with clang.
5386 #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
5388 class _LIBCPP_TYPE_VIS __sp_mut
5392 void lock() _NOEXCEPT;
5393 void unlock() _NOEXCEPT;
5396 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5397 __sp_mut(const __sp_mut&);
5398 __sp_mut& operator=(const __sp_mut&);
5400 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5403 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5405 template <class _Tp>
5406 inline _LIBCPP_INLINE_VISIBILITY
5408 atomic_is_lock_free(const shared_ptr<_Tp>*)
5413 template <class _Tp>
5415 atomic_load(const shared_ptr<_Tp>* __p)
5417 __sp_mut& __m = __get_sp_mut(__p);
5419 shared_ptr<_Tp> __q = *__p;
5424 template <class _Tp>
5425 inline _LIBCPP_INLINE_VISIBILITY
5427 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5429 return atomic_load(__p);
5432 template <class _Tp>
5434 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5436 __sp_mut& __m = __get_sp_mut(__p);
5442 template <class _Tp>
5443 inline _LIBCPP_INLINE_VISIBILITY
5445 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5447 atomic_store(__p, __r);
5450 template <class _Tp>
5452 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5454 __sp_mut& __m = __get_sp_mut(__p);
5461 template <class _Tp>
5462 inline _LIBCPP_INLINE_VISIBILITY
5464 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5466 return atomic_exchange(__p, __r);
5469 template <class _Tp>
5471 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5473 __sp_mut& __m = __get_sp_mut(__p);
5475 if (__p->__owner_equivalent(*__v))
5486 template <class _Tp>
5487 inline _LIBCPP_INLINE_VISIBILITY
5489 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5491 return atomic_compare_exchange_strong(__p, __v, __w);
5494 template <class _Tp>
5495 inline _LIBCPP_INLINE_VISIBILITY
5497 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5498 shared_ptr<_Tp> __w, memory_order, memory_order)
5500 return atomic_compare_exchange_strong(__p, __v, __w);
5503 template <class _Tp>
5504 inline _LIBCPP_INLINE_VISIBILITY
5506 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5507 shared_ptr<_Tp> __w, memory_order, memory_order)
5509 return atomic_compare_exchange_weak(__p, __v, __w);
5512 #endif // defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
5515 struct _LIBCPP_TYPE_VIS pointer_safety
5526 _LIBCPP_INLINE_VISIBILITY
5527 pointer_safety(__lx __v) : __v_(__v) {}
5528 _LIBCPP_INLINE_VISIBILITY
5529 operator int() const {return __v_;}
5532 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5533 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5534 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5535 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5536 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5538 template <class _Tp>
5539 inline _LIBCPP_INLINE_VISIBILITY
5541 undeclare_reachable(_Tp* __p)
5543 return static_cast<_Tp*>(__undeclare_reachable(__p));
5546 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5548 // --- Helper for container swap --
5549 template <typename _Alloc>
5550 _LIBCPP_INLINE_VISIBILITY
5551 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5552 #if _LIBCPP_STD_VER >= 14
5555 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5558 __swap_allocator(__a1, __a2,
5559 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5562 template <typename _Alloc>
5563 _LIBCPP_INLINE_VISIBILITY
5564 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5565 #if _LIBCPP_STD_VER >= 14
5568 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5575 template <typename _Alloc>
5576 _LIBCPP_INLINE_VISIBILITY
5577 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5579 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5580 struct __noexcept_move_assign_container : public integral_constant<bool,
5581 _Traits::propagate_on_container_move_assignment::value
5582 #if _LIBCPP_STD_VER > 14
5583 || _Traits::is_always_equal::value
5585 && is_nothrow_move_assignable<_Alloc>::value
5589 _LIBCPP_END_NAMESPACE_STD
5591 #endif // _LIBCPP_MEMORY