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);}
935 template <class _From, class _To>
936 struct __rebind_pointer {
937 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
938 typedef typename pointer_traits<_From>::template rebind<_To> type;
940 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
946 namespace __has_pointer_type_imp
948 template <class _Up> static __two __test(...);
949 template <class _Up> static char __test(typename _Up::pointer* = 0);
953 struct __has_pointer_type
954 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
958 namespace __pointer_type_imp
961 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
962 struct __pointer_type
964 typedef typename _Dp::pointer type;
967 template <class _Tp, class _Dp>
968 struct __pointer_type<_Tp, _Dp, false>
973 } // __pointer_type_imp
975 template <class _Tp, class _Dp>
976 struct __pointer_type
978 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
982 struct __has_const_pointer
985 struct __two {char __lx; char __lxx;};
986 template <class _Up> static __two __test(...);
987 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
989 static const bool value = sizeof(__test<_Tp>(0)) == 1;
992 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
993 struct __const_pointer
995 typedef typename _Alloc::const_pointer type;
998 template <class _Tp, class _Ptr, class _Alloc>
999 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1001 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1002 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1004 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1008 template <class _Tp>
1009 struct __has_void_pointer
1012 struct __two {char __lx; char __lxx;};
1013 template <class _Up> static __two __test(...);
1014 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1016 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1019 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1020 struct __void_pointer
1022 typedef typename _Alloc::void_pointer type;
1025 template <class _Ptr, class _Alloc>
1026 struct __void_pointer<_Ptr, _Alloc, false>
1028 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1029 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1031 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1035 template <class _Tp>
1036 struct __has_const_void_pointer
1039 struct __two {char __lx; char __lxx;};
1040 template <class _Up> static __two __test(...);
1041 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1043 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1046 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1047 struct __const_void_pointer
1049 typedef typename _Alloc::const_void_pointer type;
1052 template <class _Ptr, class _Alloc>
1053 struct __const_void_pointer<_Ptr, _Alloc, false>
1055 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1056 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1058 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1062 template <class _Tp>
1063 inline _LIBCPP_INLINE_VISIBILITY
1065 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1070 template <class _Pointer>
1071 inline _LIBCPP_INLINE_VISIBILITY
1072 typename pointer_traits<_Pointer>::element_type*
1073 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1075 return _VSTD::__to_raw_pointer(__p.operator->());
1078 template <class _Tp>
1079 struct __has_size_type
1082 struct __two {char __lx; char __lxx;};
1083 template <class _Up> static __two __test(...);
1084 template <class _Up> static char __test(typename _Up::size_type* = 0);
1086 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1089 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1092 typedef typename make_unsigned<_DiffType>::type type;
1095 template <class _Alloc, class _DiffType>
1096 struct __size_type<_Alloc, _DiffType, true>
1098 typedef typename _Alloc::size_type type;
1101 template <class _Tp>
1102 struct __has_propagate_on_container_copy_assignment
1105 struct __two {char __lx; char __lxx;};
1106 template <class _Up> static __two __test(...);
1107 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1109 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1112 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1113 struct __propagate_on_container_copy_assignment
1115 typedef false_type type;
1118 template <class _Alloc>
1119 struct __propagate_on_container_copy_assignment<_Alloc, true>
1121 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1124 template <class _Tp>
1125 struct __has_propagate_on_container_move_assignment
1128 struct __two {char __lx; char __lxx;};
1129 template <class _Up> static __two __test(...);
1130 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1132 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1135 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1136 struct __propagate_on_container_move_assignment
1138 typedef false_type type;
1141 template <class _Alloc>
1142 struct __propagate_on_container_move_assignment<_Alloc, true>
1144 typedef typename _Alloc::propagate_on_container_move_assignment type;
1147 template <class _Tp>
1148 struct __has_propagate_on_container_swap
1151 struct __two {char __lx; char __lxx;};
1152 template <class _Up> static __two __test(...);
1153 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1155 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1158 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1159 struct __propagate_on_container_swap
1161 typedef false_type type;
1164 template <class _Alloc>
1165 struct __propagate_on_container_swap<_Alloc, true>
1167 typedef typename _Alloc::propagate_on_container_swap type;
1170 template <class _Tp>
1171 struct __has_is_always_equal
1174 struct __two {char __lx; char __lxx;};
1175 template <class _Up> static __two __test(...);
1176 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1178 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1181 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1182 struct __is_always_equal
1184 typedef typename _VSTD::is_empty<_Alloc>::type type;
1187 template <class _Alloc>
1188 struct __is_always_equal<_Alloc, true>
1190 typedef typename _Alloc::is_always_equal type;
1193 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1194 struct __has_rebind_other
1197 struct __two {char __lx; char __lxx;};
1198 template <class _Xp> static __two __test(...);
1199 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1201 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1204 template <class _Tp, class _Up>
1205 struct __has_rebind_other<_Tp, _Up, false>
1207 static const bool value = false;
1210 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1211 struct __allocator_traits_rebind
1213 typedef typename _Tp::template rebind<_Up>::other type;
1216 #ifndef _LIBCPP_HAS_NO_VARIADICS
1218 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1219 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1221 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1224 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1225 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1227 typedef _Alloc<_Up, _Args...> type;
1230 #else // _LIBCPP_HAS_NO_VARIADICS
1232 template <template <class> class _Alloc, class _Tp, class _Up>
1233 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1235 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1238 template <template <class> class _Alloc, class _Tp, class _Up>
1239 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1241 typedef _Alloc<_Up> type;
1244 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1245 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1247 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1250 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1251 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1253 typedef _Alloc<_Up, _A0> type;
1256 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1257 class _A1, class _Up>
1258 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1260 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1263 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1264 class _A1, class _Up>
1265 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1267 typedef _Alloc<_Up, _A0, _A1> type;
1270 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1271 class _A1, class _A2, class _Up>
1272 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1274 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1277 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1278 class _A1, class _A2, class _Up>
1279 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1281 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1284 #endif // _LIBCPP_HAS_NO_VARIADICS
1286 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1288 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1290 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1291 -> decltype(__a.allocate(__sz, __p), true_type());
1293 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1295 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1298 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1299 struct __has_allocate_hint
1300 : integral_constant<bool,
1302 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1303 declval<_SizeType>(),
1304 declval<_ConstVoidPtr>())),
1309 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1311 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1312 struct __has_allocate_hint
1317 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1319 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1321 template <class _Alloc, class _Tp, class ..._Args>
1322 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1323 _VSTD::declval<_Args>()...),
1325 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1327 template <class _Alloc, class _Pointer, class ..._Args>
1329 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1331 template <class _Alloc, class _Pointer, class ..._Args>
1332 struct __has_construct
1333 : integral_constant<bool,
1335 decltype(__has_construct_test(declval<_Alloc>(),
1336 declval<_Pointer>(),
1337 declval<_Args>()...)),
1342 template <class _Alloc, class _Pointer>
1344 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1345 -> decltype(__a.destroy(__p), true_type());
1347 template <class _Alloc, class _Pointer>
1349 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1352 template <class _Alloc, class _Pointer>
1353 struct __has_destroy
1354 : integral_constant<bool,
1356 decltype(__has_destroy_test(declval<_Alloc>(),
1357 declval<_Pointer>())),
1362 template <class _Alloc>
1364 __has_max_size_test(_Alloc&& __a)
1365 -> decltype(__a.max_size(), true_type());
1367 template <class _Alloc>
1369 __has_max_size_test(const volatile _Alloc& __a)
1372 template <class _Alloc>
1373 struct __has_max_size
1374 : integral_constant<bool,
1376 decltype(__has_max_size_test(declval<_Alloc&>())),
1381 template <class _Alloc>
1383 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1384 -> decltype(__a.select_on_container_copy_construction(), true_type());
1386 template <class _Alloc>
1388 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1391 template <class _Alloc>
1392 struct __has_select_on_container_copy_construction
1393 : integral_constant<bool,
1395 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1400 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1402 #ifndef _LIBCPP_HAS_NO_VARIADICS
1404 template <class _Alloc, class _Pointer, class ..._Args>
1405 struct __has_construct
1410 #else // _LIBCPP_HAS_NO_VARIADICS
1412 template <class _Alloc, class _Pointer, class _Args>
1413 struct __has_construct
1418 #endif // _LIBCPP_HAS_NO_VARIADICS
1420 template <class _Alloc, class _Pointer>
1421 struct __has_destroy
1426 template <class _Alloc>
1427 struct __has_max_size
1432 template <class _Alloc>
1433 struct __has_select_on_container_copy_construction
1438 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1440 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1441 struct __alloc_traits_difference_type
1443 typedef typename pointer_traits<_Ptr>::difference_type type;
1446 template <class _Alloc, class _Ptr>
1447 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1449 typedef typename _Alloc::difference_type type;
1452 template <class _Alloc>
1453 struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
1455 typedef _Alloc allocator_type;
1456 typedef typename allocator_type::value_type value_type;
1458 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1459 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1460 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1461 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1463 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1464 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1466 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1467 propagate_on_container_copy_assignment;
1468 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1469 propagate_on_container_move_assignment;
1470 typedef typename __propagate_on_container_swap<allocator_type>::type
1471 propagate_on_container_swap;
1472 typedef typename __is_always_equal<allocator_type>::type
1475 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1476 template <class _Tp> using rebind_alloc =
1477 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1478 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1479 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1480 template <class _Tp> struct rebind_alloc
1481 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1482 template <class _Tp> struct rebind_traits
1483 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1484 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1486 _LIBCPP_INLINE_VISIBILITY
1487 static pointer allocate(allocator_type& __a, size_type __n)
1488 {return __a.allocate(__n);}
1489 _LIBCPP_INLINE_VISIBILITY
1490 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1491 {return allocate(__a, __n, __hint,
1492 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1494 _LIBCPP_INLINE_VISIBILITY
1495 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1496 {__a.deallocate(__p, __n);}
1498 #ifndef _LIBCPP_HAS_NO_VARIADICS
1499 template <class _Tp, class... _Args>
1500 _LIBCPP_INLINE_VISIBILITY
1501 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1502 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1503 __a, __p, _VSTD::forward<_Args>(__args)...);}
1504 #else // _LIBCPP_HAS_NO_VARIADICS
1505 template <class _Tp>
1506 _LIBCPP_INLINE_VISIBILITY
1507 static void construct(allocator_type& __a, _Tp* __p)
1509 ::new ((void*)__p) _Tp();
1511 template <class _Tp, class _A0>
1512 _LIBCPP_INLINE_VISIBILITY
1513 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1515 ::new ((void*)__p) _Tp(__a0);
1517 template <class _Tp, class _A0, class _A1>
1518 _LIBCPP_INLINE_VISIBILITY
1519 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1522 ::new ((void*)__p) _Tp(__a0, __a1);
1524 template <class _Tp, class _A0, class _A1, class _A2>
1525 _LIBCPP_INLINE_VISIBILITY
1526 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1527 const _A1& __a1, const _A2& __a2)
1529 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1531 #endif // _LIBCPP_HAS_NO_VARIADICS
1533 template <class _Tp>
1534 _LIBCPP_INLINE_VISIBILITY
1535 static void destroy(allocator_type& __a, _Tp* __p)
1536 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1538 _LIBCPP_INLINE_VISIBILITY
1539 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1540 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1542 _LIBCPP_INLINE_VISIBILITY
1543 static allocator_type
1544 select_on_container_copy_construction(const allocator_type& __a)
1545 {return select_on_container_copy_construction(
1546 __has_select_on_container_copy_construction<const allocator_type>(),
1549 template <class _Ptr>
1550 _LIBCPP_INLINE_VISIBILITY
1553 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1555 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1556 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1559 template <class _Tp>
1560 _LIBCPP_INLINE_VISIBILITY
1564 (is_same<allocator_type, allocator<_Tp> >::value
1565 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1566 is_trivially_move_constructible<_Tp>::value,
1569 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1571 ptrdiff_t _Np = __end1 - __begin1;
1574 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1579 template <class _Iter, class _Ptr>
1580 _LIBCPP_INLINE_VISIBILITY
1583 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1585 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1586 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1589 template <class _Tp>
1590 _LIBCPP_INLINE_VISIBILITY
1594 (is_same<allocator_type, allocator<_Tp> >::value
1595 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1596 is_trivially_move_constructible<_Tp>::value,
1599 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1601 typedef typename remove_const<_Tp>::type _Vp;
1602 ptrdiff_t _Np = __end1 - __begin1;
1605 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1610 template <class _Ptr>
1611 _LIBCPP_INLINE_VISIBILITY
1614 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1616 while (__end1 != __begin1)
1618 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1623 template <class _Tp>
1624 _LIBCPP_INLINE_VISIBILITY
1628 (is_same<allocator_type, allocator<_Tp> >::value
1629 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1630 is_trivially_move_constructible<_Tp>::value,
1633 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1635 ptrdiff_t _Np = __end1 - __begin1;
1638 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1643 _LIBCPP_INLINE_VISIBILITY
1644 static pointer allocate(allocator_type& __a, size_type __n,
1645 const_void_pointer __hint, true_type)
1646 {return __a.allocate(__n, __hint);}
1647 _LIBCPP_INLINE_VISIBILITY
1648 static pointer allocate(allocator_type& __a, size_type __n,
1649 const_void_pointer, false_type)
1650 {return __a.allocate(__n);}
1652 #ifndef _LIBCPP_HAS_NO_VARIADICS
1653 template <class _Tp, class... _Args>
1654 _LIBCPP_INLINE_VISIBILITY
1655 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1656 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1657 template <class _Tp, class... _Args>
1658 _LIBCPP_INLINE_VISIBILITY
1659 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1661 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1663 #endif // _LIBCPP_HAS_NO_VARIADICS
1665 template <class _Tp>
1666 _LIBCPP_INLINE_VISIBILITY
1667 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1669 template <class _Tp>
1670 _LIBCPP_INLINE_VISIBILITY
1671 static void __destroy(false_type, allocator_type&, _Tp* __p)
1676 _LIBCPP_INLINE_VISIBILITY
1677 static size_type __max_size(true_type, const allocator_type& __a)
1678 {return __a.max_size();}
1679 _LIBCPP_INLINE_VISIBILITY
1680 static size_type __max_size(false_type, const allocator_type&)
1681 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1683 _LIBCPP_INLINE_VISIBILITY
1684 static allocator_type
1685 select_on_container_copy_construction(true_type, const allocator_type& __a)
1686 {return __a.select_on_container_copy_construction();}
1687 _LIBCPP_INLINE_VISIBILITY
1688 static allocator_type
1689 select_on_container_copy_construction(false_type, const allocator_type& __a)
1693 template <class _Traits, class _Tp>
1694 struct __rebind_alloc_helper
1696 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1697 typedef typename _Traits::template rebind_alloc<_Tp> type;
1699 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1705 template <class _Tp>
1706 class _LIBCPP_TYPE_VIS_ONLY allocator
1709 typedef size_t size_type;
1710 typedef ptrdiff_t difference_type;
1711 typedef _Tp* pointer;
1712 typedef const _Tp* const_pointer;
1713 typedef _Tp& reference;
1714 typedef const _Tp& const_reference;
1715 typedef _Tp value_type;
1717 typedef true_type propagate_on_container_move_assignment;
1718 typedef true_type is_always_equal;
1720 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1722 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1723 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1724 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1725 {return _VSTD::addressof(__x);}
1726 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1727 {return _VSTD::addressof(__x);}
1728 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1729 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1730 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1731 {_VSTD::__deallocate((void*)__p);}
1732 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1733 {return size_type(~0) / sizeof(_Tp);}
1734 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1735 template <class _Up, class... _Args>
1736 _LIBCPP_INLINE_VISIBILITY
1738 construct(_Up* __p, _Args&&... __args)
1740 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1742 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1743 _LIBCPP_INLINE_VISIBILITY
1745 construct(pointer __p)
1747 ::new((void*)__p) _Tp();
1749 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1751 template <class _A0>
1752 _LIBCPP_INLINE_VISIBILITY
1754 construct(pointer __p, _A0& __a0)
1756 ::new((void*)__p) _Tp(__a0);
1758 template <class _A0>
1759 _LIBCPP_INLINE_VISIBILITY
1761 construct(pointer __p, const _A0& __a0)
1763 ::new((void*)__p) _Tp(__a0);
1765 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1766 template <class _A0, class _A1>
1767 _LIBCPP_INLINE_VISIBILITY
1769 construct(pointer __p, _A0& __a0, _A1& __a1)
1771 ::new((void*)__p) _Tp(__a0, __a1);
1773 template <class _A0, class _A1>
1774 _LIBCPP_INLINE_VISIBILITY
1776 construct(pointer __p, const _A0& __a0, _A1& __a1)
1778 ::new((void*)__p) _Tp(__a0, __a1);
1780 template <class _A0, class _A1>
1781 _LIBCPP_INLINE_VISIBILITY
1783 construct(pointer __p, _A0& __a0, const _A1& __a1)
1785 ::new((void*)__p) _Tp(__a0, __a1);
1787 template <class _A0, class _A1>
1788 _LIBCPP_INLINE_VISIBILITY
1790 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1792 ::new((void*)__p) _Tp(__a0, __a1);
1794 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1795 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1798 template <class _Tp>
1799 class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1802 typedef size_t size_type;
1803 typedef ptrdiff_t difference_type;
1804 typedef const _Tp* pointer;
1805 typedef const _Tp* const_pointer;
1806 typedef const _Tp& reference;
1807 typedef const _Tp& const_reference;
1808 typedef const _Tp value_type;
1810 typedef true_type propagate_on_container_move_assignment;
1811 typedef true_type is_always_equal;
1813 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1815 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1816 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1817 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1818 {return _VSTD::addressof(__x);}
1819 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1820 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1821 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1822 {_VSTD::__deallocate((void*)__p);}
1823 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1824 {return size_type(~0) / sizeof(_Tp);}
1825 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1826 template <class _Up, class... _Args>
1827 _LIBCPP_INLINE_VISIBILITY
1829 construct(_Up* __p, _Args&&... __args)
1831 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1833 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1834 _LIBCPP_INLINE_VISIBILITY
1836 construct(pointer __p)
1838 ::new((void*)__p) _Tp();
1840 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1842 template <class _A0>
1843 _LIBCPP_INLINE_VISIBILITY
1845 construct(pointer __p, _A0& __a0)
1847 ::new((void*)__p) _Tp(__a0);
1849 template <class _A0>
1850 _LIBCPP_INLINE_VISIBILITY
1852 construct(pointer __p, const _A0& __a0)
1854 ::new((void*)__p) _Tp(__a0);
1856 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1857 template <class _A0, class _A1>
1858 _LIBCPP_INLINE_VISIBILITY
1860 construct(pointer __p, _A0& __a0, _A1& __a1)
1862 ::new((void*)__p) _Tp(__a0, __a1);
1864 template <class _A0, class _A1>
1865 _LIBCPP_INLINE_VISIBILITY
1867 construct(pointer __p, const _A0& __a0, _A1& __a1)
1869 ::new((void*)__p) _Tp(__a0, __a1);
1871 template <class _A0, class _A1>
1872 _LIBCPP_INLINE_VISIBILITY
1874 construct(pointer __p, _A0& __a0, const _A1& __a1)
1876 ::new((void*)__p) _Tp(__a0, __a1);
1878 template <class _A0, class _A1>
1879 _LIBCPP_INLINE_VISIBILITY
1881 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1883 ::new((void*)__p) _Tp(__a0, __a1);
1885 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1886 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1889 template <class _Tp, class _Up>
1890 inline _LIBCPP_INLINE_VISIBILITY
1891 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1893 template <class _Tp, class _Up>
1894 inline _LIBCPP_INLINE_VISIBILITY
1895 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1897 template <class _OutputIterator, class _Tp>
1898 class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
1899 : public iterator<output_iterator_tag,
1900 _Tp, // purposefully not C++03
1901 ptrdiff_t, // purposefully not C++03
1902 _Tp*, // purposefully not C++03
1903 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1906 _OutputIterator __x_;
1908 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1909 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1910 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1911 {::new(&*__x_) _Tp(__element); return *this;}
1912 #if _LIBCPP_STD_VER >= 14
1913 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1914 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1916 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1917 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1918 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1919 #if _LIBCPP_STD_VER >= 14
1920 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1924 template <class _Tp>
1925 pair<_Tp*, ptrdiff_t>
1926 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1928 pair<_Tp*, ptrdiff_t> __r(0, 0);
1929 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1930 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1936 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1947 template <class _Tp>
1948 inline _LIBCPP_INLINE_VISIBILITY
1949 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1951 template <class _Tp>
1958 class _LIBCPP_TYPE_VIS_ONLY auto_ptr
1963 typedef _Tp element_type;
1965 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1966 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1967 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1968 : __ptr_(__p.release()) {}
1969 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1970 {reset(__p.release()); return *this;}
1971 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1972 {reset(__p.release()); return *this;}
1973 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1974 {reset(__p.__ptr_); return *this;}
1975 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1977 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1979 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1980 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1981 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1987 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1994 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1995 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1996 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1997 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1998 {return auto_ptr<_Up>(release());}
2002 class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
2005 typedef void element_type;
2008 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
2009 typename remove_cv<_T2>::type>::value,
2010 bool = is_empty<_T1>::value
2011 && !__libcpp_is_final<_T1>::value,
2012 bool = is_empty<_T2>::value
2013 && !__libcpp_is_final<_T2>::value
2015 struct __libcpp_compressed_pair_switch;
2017 template <class _T1, class _T2, bool IsSame>
2018 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2020 template <class _T1, class _T2, bool IsSame>
2021 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2023 template <class _T1, class _T2, bool IsSame>
2024 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2026 template <class _T1, class _T2>
2027 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2029 template <class _T1, class _T2>
2030 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2032 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2033 class __libcpp_compressed_pair_imp;
2035 template <class _T1, class _T2>
2036 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2042 typedef _T1 _T1_param;
2043 typedef _T2 _T2_param;
2045 typedef typename remove_reference<_T1>::type& _T1_reference;
2046 typedef typename remove_reference<_T2>::type& _T2_reference;
2048 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2049 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2051 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
2052 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2053 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2054 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2055 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2056 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2057 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2059 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2061 _LIBCPP_INLINE_VISIBILITY
2062 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2063 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2064 is_nothrow_copy_constructible<_T2>::value)
2065 : __first_(__p.first()),
2066 __second_(__p.second()) {}
2068 _LIBCPP_INLINE_VISIBILITY
2069 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2070 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2071 is_nothrow_copy_assignable<_T2>::value)
2073 __first_ = __p.first();
2074 __second_ = __p.second();
2078 _LIBCPP_INLINE_VISIBILITY
2079 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2080 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2081 is_nothrow_move_constructible<_T2>::value)
2082 : __first_(_VSTD::forward<_T1>(__p.first())),
2083 __second_(_VSTD::forward<_T2>(__p.second())) {}
2085 _LIBCPP_INLINE_VISIBILITY
2086 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2087 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2088 is_nothrow_move_assignable<_T2>::value)
2090 __first_ = _VSTD::forward<_T1>(__p.first());
2091 __second_ = _VSTD::forward<_T2>(__p.second());
2095 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2097 #ifndef _LIBCPP_HAS_NO_VARIADICS
2099 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2100 _LIBCPP_INLINE_VISIBILITY
2101 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2102 tuple<_Args1...> __first_args,
2103 tuple<_Args2...> __second_args,
2104 __tuple_indices<_I1...>,
2105 __tuple_indices<_I2...>)
2106 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2107 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2110 #endif // _LIBCPP_HAS_NO_VARIADICS
2112 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2113 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2115 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2116 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2118 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2119 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2120 __is_nothrow_swappable<_T2>::value)
2123 swap(__first_, __x.__first_);
2124 swap(__second_, __x.__second_);
2128 template <class _T1, class _T2>
2129 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2135 typedef _T1 _T1_param;
2136 typedef _T2 _T2_param;
2138 typedef _T1& _T1_reference;
2139 typedef typename remove_reference<_T2>::type& _T2_reference;
2141 typedef const _T1& _T1_const_reference;
2142 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2144 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
2145 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2146 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
2147 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2148 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2149 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2150 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2152 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2154 _LIBCPP_INLINE_VISIBILITY
2155 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2156 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2157 is_nothrow_copy_constructible<_T2>::value)
2158 : _T1(__p.first()), __second_(__p.second()) {}
2160 _LIBCPP_INLINE_VISIBILITY
2161 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2162 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2163 is_nothrow_copy_assignable<_T2>::value)
2165 _T1::operator=(__p.first());
2166 __second_ = __p.second();
2170 _LIBCPP_INLINE_VISIBILITY
2171 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2172 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2173 is_nothrow_move_constructible<_T2>::value)
2174 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2176 _LIBCPP_INLINE_VISIBILITY
2177 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2178 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2179 is_nothrow_move_assignable<_T2>::value)
2181 _T1::operator=(_VSTD::move(__p.first()));
2182 __second_ = _VSTD::forward<_T2>(__p.second());
2186 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2188 #ifndef _LIBCPP_HAS_NO_VARIADICS
2190 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2191 _LIBCPP_INLINE_VISIBILITY
2192 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2193 tuple<_Args1...> __first_args,
2194 tuple<_Args2...> __second_args,
2195 __tuple_indices<_I1...>,
2196 __tuple_indices<_I2...>)
2197 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2198 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2201 #endif // _LIBCPP_HAS_NO_VARIADICS
2203 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2204 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2206 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2207 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2209 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2210 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2211 __is_nothrow_swappable<_T2>::value)
2214 swap(__second_, __x.__second_);
2218 template <class _T1, class _T2>
2219 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2225 typedef _T1 _T1_param;
2226 typedef _T2 _T2_param;
2228 typedef typename remove_reference<_T1>::type& _T1_reference;
2229 typedef _T2& _T2_reference;
2231 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2232 typedef const _T2& _T2_const_reference;
2234 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
2235 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2236 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2237 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2238 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
2239 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2240 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2241 is_nothrow_move_constructible<_T2>::value)
2242 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2244 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2246 _LIBCPP_INLINE_VISIBILITY
2247 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2248 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2249 is_nothrow_copy_constructible<_T2>::value)
2250 : _T2(__p.second()), __first_(__p.first()) {}
2252 _LIBCPP_INLINE_VISIBILITY
2253 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2254 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2255 is_nothrow_copy_assignable<_T2>::value)
2257 _T2::operator=(__p.second());
2258 __first_ = __p.first();
2262 _LIBCPP_INLINE_VISIBILITY
2263 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2264 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2265 is_nothrow_move_constructible<_T2>::value)
2266 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2268 _LIBCPP_INLINE_VISIBILITY
2269 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2270 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2271 is_nothrow_move_assignable<_T2>::value)
2273 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2274 __first_ = _VSTD::move(__p.first());
2278 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2280 #ifndef _LIBCPP_HAS_NO_VARIADICS
2282 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2283 _LIBCPP_INLINE_VISIBILITY
2284 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2285 tuple<_Args1...> __first_args,
2286 tuple<_Args2...> __second_args,
2287 __tuple_indices<_I1...>,
2288 __tuple_indices<_I2...>)
2289 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2290 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2294 #endif // _LIBCPP_HAS_NO_VARIADICS
2296 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2297 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2299 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2300 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2302 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2303 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2304 __is_nothrow_swappable<_T2>::value)
2307 swap(__first_, __x.__first_);
2311 template <class _T1, class _T2>
2312 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2317 typedef _T1 _T1_param;
2318 typedef _T2 _T2_param;
2320 typedef _T1& _T1_reference;
2321 typedef _T2& _T2_reference;
2323 typedef const _T1& _T1_const_reference;
2324 typedef const _T2& _T2_const_reference;
2326 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2327 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2328 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2329 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2330 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2331 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2332 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2334 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2336 _LIBCPP_INLINE_VISIBILITY
2337 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2338 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2339 is_nothrow_copy_constructible<_T2>::value)
2340 : _T1(__p.first()), _T2(__p.second()) {}
2342 _LIBCPP_INLINE_VISIBILITY
2343 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2344 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2345 is_nothrow_copy_assignable<_T2>::value)
2347 _T1::operator=(__p.first());
2348 _T2::operator=(__p.second());
2352 _LIBCPP_INLINE_VISIBILITY
2353 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2354 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2355 is_nothrow_move_constructible<_T2>::value)
2356 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2358 _LIBCPP_INLINE_VISIBILITY
2359 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2360 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2361 is_nothrow_move_assignable<_T2>::value)
2363 _T1::operator=(_VSTD::move(__p.first()));
2364 _T2::operator=(_VSTD::move(__p.second()));
2368 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2370 #ifndef _LIBCPP_HAS_NO_VARIADICS
2372 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2373 _LIBCPP_INLINE_VISIBILITY
2374 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2375 tuple<_Args1...> __first_args,
2376 tuple<_Args2...> __second_args,
2377 __tuple_indices<_I1...>,
2378 __tuple_indices<_I2...>)
2379 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2380 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2383 #endif // _LIBCPP_HAS_NO_VARIADICS
2385 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2386 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2388 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2389 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2391 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2392 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2393 __is_nothrow_swappable<_T2>::value)
2398 template <class _T1, class _T2>
2399 class __compressed_pair
2400 : private __libcpp_compressed_pair_imp<_T1, _T2>
2402 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2404 typedef typename base::_T1_param _T1_param;
2405 typedef typename base::_T2_param _T2_param;
2407 typedef typename base::_T1_reference _T1_reference;
2408 typedef typename base::_T2_reference _T2_reference;
2410 typedef typename base::_T1_const_reference _T1_const_reference;
2411 typedef typename base::_T2_const_reference _T2_const_reference;
2413 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2414 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2415 : base(_VSTD::forward<_T1_param>(__t1)) {}
2416 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2417 : base(_VSTD::forward<_T2_param>(__t2)) {}
2418 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2419 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2421 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2423 _LIBCPP_INLINE_VISIBILITY
2424 __compressed_pair(const __compressed_pair& __p)
2425 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2426 is_nothrow_copy_constructible<_T2>::value)
2429 _LIBCPP_INLINE_VISIBILITY
2430 __compressed_pair& operator=(const __compressed_pair& __p)
2431 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2432 is_nothrow_copy_assignable<_T2>::value)
2434 base::operator=(__p);
2438 _LIBCPP_INLINE_VISIBILITY
2439 __compressed_pair(__compressed_pair&& __p)
2440 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2441 is_nothrow_move_constructible<_T2>::value)
2442 : base(_VSTD::move(__p)) {}
2444 _LIBCPP_INLINE_VISIBILITY
2445 __compressed_pair& operator=(__compressed_pair&& __p)
2446 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2447 is_nothrow_move_assignable<_T2>::value)
2449 base::operator=(_VSTD::move(__p));
2453 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2455 #ifndef _LIBCPP_HAS_NO_VARIADICS
2457 template <class... _Args1, class... _Args2>
2458 _LIBCPP_INLINE_VISIBILITY
2459 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2460 tuple<_Args2...> __second_args)
2461 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2462 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2463 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2466 #endif // _LIBCPP_HAS_NO_VARIADICS
2468 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2469 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2471 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2472 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2474 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2475 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2476 __is_nothrow_swappable<_T2>::value)
2480 template <class _T1, class _T2>
2481 inline _LIBCPP_INLINE_VISIBILITY
2483 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2484 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2485 __is_nothrow_swappable<_T2>::value)
2488 // __same_or_less_cv_qualified
2490 template <class _Ptr1, class _Ptr2,
2491 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2492 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2495 struct __same_or_less_cv_qualified_imp
2496 : is_convertible<_Ptr1, _Ptr2> {};
2498 template <class _Ptr1, class _Ptr2>
2499 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2502 template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2503 is_same<_Ptr1, _Ptr2>::value ||
2504 __has_element_type<_Ptr1>::value>
2505 struct __same_or_less_cv_qualified
2506 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2508 template <class _Ptr1, class _Ptr2>
2509 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2514 template <class _Tp>
2515 struct _LIBCPP_TYPE_VIS_ONLY default_delete
2517 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2518 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2520 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2522 template <class _Up>
2523 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2524 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2525 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2527 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2528 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2533 template <class _Tp>
2534 struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2537 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2538 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2542 template <class _Up>
2543 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2544 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2545 template <class _Up>
2546 _LIBCPP_INLINE_VISIBILITY
2547 void operator() (_Up* __ptr,
2548 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2550 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2551 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2556 template <class _Tp, class _Dp = default_delete<_Tp> >
2557 class _LIBCPP_TYPE_VIS_ONLY unique_ptr
2560 typedef _Tp element_type;
2561 typedef _Dp deleter_type;
2562 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2564 __compressed_pair<pointer, deleter_type> __ptr_;
2566 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2567 unique_ptr(unique_ptr&);
2568 template <class _Up, class _Ep>
2569 unique_ptr(unique_ptr<_Up, _Ep>&);
2570 unique_ptr& operator=(unique_ptr&);
2571 template <class _Up, class _Ep>
2572 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2573 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2575 struct __nat {int __for_bool_;};
2577 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2578 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2580 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2583 static_assert(!is_pointer<deleter_type>::value,
2584 "unique_ptr constructed with null function pointer deleter");
2586 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2589 static_assert(!is_pointer<deleter_type>::value,
2590 "unique_ptr constructed with null function pointer deleter");
2592 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2593 : __ptr_(_VSTD::move(__p))
2595 static_assert(!is_pointer<deleter_type>::value,
2596 "unique_ptr constructed with null function pointer deleter");
2599 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2600 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2601 is_reference<deleter_type>::value,
2603 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2605 : __ptr_(__p, __d) {}
2607 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2609 : __ptr_(__p, _VSTD::move(__d))
2611 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2613 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2614 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2615 template <class _Up, class _Ep>
2616 _LIBCPP_INLINE_VISIBILITY
2617 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2620 !is_array<_Up>::value &&
2621 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2622 is_convertible<_Ep, deleter_type>::value &&
2624 !is_reference<deleter_type>::value ||
2625 is_same<deleter_type, _Ep>::value
2628 >::type = __nat()) _NOEXCEPT
2629 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2631 template <class _Up>
2632 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2634 is_convertible<_Up*, _Tp*>::value &&
2635 is_same<_Dp, default_delete<_Tp> >::value,
2637 >::type = __nat()) _NOEXCEPT
2638 : __ptr_(__p.release())
2642 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2644 reset(__u.release());
2645 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2649 template <class _Up, class _Ep>
2650 _LIBCPP_INLINE_VISIBILITY
2653 !is_array<_Up>::value &&
2654 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2655 is_assignable<deleter_type&, _Ep&&>::value,
2658 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2660 reset(__u.release());
2661 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2664 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2666 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2668 return __rv<unique_ptr>(*this);
2671 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2672 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2674 template <class _Up, class _Ep>
2675 _LIBCPP_INLINE_VISIBILITY
2677 !is_array<_Up>::value &&
2678 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2679 is_assignable<deleter_type&, _Ep&>::value,
2682 operator=(unique_ptr<_Up, _Ep> __u)
2684 reset(__u.release());
2685 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2689 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2690 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2692 template <class _Up>
2693 _LIBCPP_INLINE_VISIBILITY
2695 is_convertible<_Up*, _Tp*>::value &&
2696 is_same<_Dp, default_delete<_Tp> >::value,
2699 operator=(auto_ptr<_Up> __p)
2700 {reset(__p.release()); return *this;}
2702 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2703 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2705 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2711 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2712 {return *__ptr_.first();}
2713 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2714 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2715 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2716 {return __ptr_.second();}
2717 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2718 {return __ptr_.second();}
2719 _LIBCPP_INLINE_VISIBILITY
2720 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2721 {return __ptr_.first() != nullptr;}
2723 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2725 pointer __t = __ptr_.first();
2726 __ptr_.first() = pointer();
2730 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2732 pointer __tmp = __ptr_.first();
2733 __ptr_.first() = __p;
2735 __ptr_.second()(__tmp);
2738 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2739 {__ptr_.swap(__u.__ptr_);}
2742 template <class _Tp, class _Dp>
2743 class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
2746 typedef _Tp element_type;
2747 typedef _Dp deleter_type;
2748 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2750 __compressed_pair<pointer, deleter_type> __ptr_;
2752 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2753 unique_ptr(unique_ptr&);
2754 template <class _Up>
2755 unique_ptr(unique_ptr<_Up>&);
2756 unique_ptr& operator=(unique_ptr&);
2757 template <class _Up>
2758 unique_ptr& operator=(unique_ptr<_Up>&);
2759 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2761 struct __nat {int __for_bool_;};
2763 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2764 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2766 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2769 static_assert(!is_pointer<deleter_type>::value,
2770 "unique_ptr constructed with null function pointer deleter");
2772 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2775 static_assert(!is_pointer<deleter_type>::value,
2776 "unique_ptr constructed with null function pointer deleter");
2778 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2779 template <class _Pp>
2780 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2781 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
2784 static_assert(!is_pointer<deleter_type>::value,
2785 "unique_ptr constructed with null function pointer deleter");
2788 template <class _Pp>
2789 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2790 is_reference<deleter_type>::value,
2792 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2793 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2795 : __ptr_(__p, __d) {}
2797 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2798 is_reference<deleter_type>::value,
2800 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2802 : __ptr_(pointer(), __d) {}
2804 template <class _Pp>
2805 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2806 typename remove_reference<deleter_type>::type&& __d,
2807 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2809 : __ptr_(__p, _VSTD::move(__d))
2811 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2814 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2816 : __ptr_(pointer(), _VSTD::move(__d))
2818 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2821 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2822 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2824 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2826 reset(__u.release());
2827 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2831 template <class _Up, class _Ep>
2832 _LIBCPP_INLINE_VISIBILITY
2833 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2836 is_array<_Up>::value &&
2837 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2838 && is_convertible<_Ep, deleter_type>::value &&
2840 !is_reference<deleter_type>::value ||
2841 is_same<deleter_type, _Ep>::value
2846 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2849 template <class _Up, class _Ep>
2850 _LIBCPP_INLINE_VISIBILITY
2853 is_array<_Up>::value &&
2854 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2855 is_assignable<deleter_type&, _Ep&&>::value,
2858 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2860 reset(__u.release());
2861 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2864 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2866 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2869 static_assert(!is_pointer<deleter_type>::value,
2870 "unique_ptr constructed with null function pointer deleter");
2873 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2874 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2876 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2877 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2879 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2881 return __rv<unique_ptr>(*this);
2884 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2885 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2887 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2889 reset(__u->release());
2890 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2894 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2895 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2897 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2903 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2904 {return __ptr_.first()[__i];}
2905 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2906 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2907 {return __ptr_.second();}
2908 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2909 {return __ptr_.second();}
2910 _LIBCPP_INLINE_VISIBILITY
2911 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2912 {return __ptr_.first() != nullptr;}
2914 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2916 pointer __t = __ptr_.first();
2917 __ptr_.first() = pointer();
2921 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2922 template <class _Pp>
2923 _LIBCPP_INLINE_VISIBILITY
2924 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2925 reset(_Pp __p) _NOEXCEPT
2927 pointer __tmp = __ptr_.first();
2928 __ptr_.first() = __p;
2930 __ptr_.second()(__tmp);
2932 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2934 pointer __tmp = __ptr_.first();
2935 __ptr_.first() = nullptr;
2937 __ptr_.second()(__tmp);
2939 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2941 pointer __tmp = __ptr_.first();
2942 __ptr_.first() = nullptr;
2944 __ptr_.second()(__tmp);
2946 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2947 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2949 pointer __tmp = __ptr_.first();
2950 __ptr_.first() = __p;
2952 __ptr_.second()(__tmp);
2954 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2956 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2959 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2960 template <class _Up>
2961 explicit unique_ptr(_Up);
2962 template <class _Up>
2964 typename conditional<
2965 is_reference<deleter_type>::value,
2967 typename add_lvalue_reference<const deleter_type>::type>::type,
2970 is_convertible<_Up, pointer>::value,
2973 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2976 template <class _Tp, class _Dp>
2977 inline _LIBCPP_INLINE_VISIBILITY
2979 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2981 template <class _T1, class _D1, class _T2, class _D2>
2982 inline _LIBCPP_INLINE_VISIBILITY
2984 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2986 template <class _T1, class _D1, class _T2, class _D2>
2987 inline _LIBCPP_INLINE_VISIBILITY
2989 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2991 template <class _T1, class _D1, class _T2, class _D2>
2992 inline _LIBCPP_INLINE_VISIBILITY
2994 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2996 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2997 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2998 typedef typename common_type<_P1, _P2>::type _Vp;
2999 return less<_Vp>()(__x.get(), __y.get());
3002 template <class _T1, class _D1, class _T2, class _D2>
3003 inline _LIBCPP_INLINE_VISIBILITY
3005 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
3007 template <class _T1, class _D1, class _T2, class _D2>
3008 inline _LIBCPP_INLINE_VISIBILITY
3010 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
3012 template <class _T1, class _D1, class _T2, class _D2>
3013 inline _LIBCPP_INLINE_VISIBILITY
3015 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
3017 template <class _T1, class _D1>
3018 inline _LIBCPP_INLINE_VISIBILITY
3020 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3025 template <class _T1, class _D1>
3026 inline _LIBCPP_INLINE_VISIBILITY
3028 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3033 template <class _T1, class _D1>
3034 inline _LIBCPP_INLINE_VISIBILITY
3036 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3038 return static_cast<bool>(__x);
3041 template <class _T1, class _D1>
3042 inline _LIBCPP_INLINE_VISIBILITY
3044 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3046 return static_cast<bool>(__x);
3049 template <class _T1, class _D1>
3050 inline _LIBCPP_INLINE_VISIBILITY
3052 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3054 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3055 return less<_P1>()(__x.get(), nullptr);
3058 template <class _T1, class _D1>
3059 inline _LIBCPP_INLINE_VISIBILITY
3061 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3063 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3064 return less<_P1>()(nullptr, __x.get());
3067 template <class _T1, class _D1>
3068 inline _LIBCPP_INLINE_VISIBILITY
3070 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3072 return nullptr < __x;
3075 template <class _T1, class _D1>
3076 inline _LIBCPP_INLINE_VISIBILITY
3078 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3080 return __x < nullptr;
3083 template <class _T1, class _D1>
3084 inline _LIBCPP_INLINE_VISIBILITY
3086 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3088 return !(nullptr < __x);
3091 template <class _T1, class _D1>
3092 inline _LIBCPP_INLINE_VISIBILITY
3094 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3096 return !(__x < nullptr);
3099 template <class _T1, class _D1>
3100 inline _LIBCPP_INLINE_VISIBILITY
3102 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3104 return !(__x < nullptr);
3107 template <class _T1, class _D1>
3108 inline _LIBCPP_INLINE_VISIBILITY
3110 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3112 return !(nullptr < __x);
3115 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3117 template <class _Tp, class _Dp>
3118 inline _LIBCPP_INLINE_VISIBILITY
3119 unique_ptr<_Tp, _Dp>
3120 move(unique_ptr<_Tp, _Dp>& __t)
3122 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3127 #if _LIBCPP_STD_VER > 11
3132 typedef unique_ptr<_Tp> __unique_single;
3136 struct __unique_if<_Tp[]>
3138 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3141 template<class _Tp, size_t _Np>
3142 struct __unique_if<_Tp[_Np]>
3144 typedef void __unique_array_known_bound;
3147 template<class _Tp, class... _Args>
3148 inline _LIBCPP_INLINE_VISIBILITY
3149 typename __unique_if<_Tp>::__unique_single
3150 make_unique(_Args&&... __args)
3152 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3156 inline _LIBCPP_INLINE_VISIBILITY
3157 typename __unique_if<_Tp>::__unique_array_unknown_bound
3158 make_unique(size_t __n)
3160 typedef typename remove_extent<_Tp>::type _Up;
3161 return unique_ptr<_Tp>(new _Up[__n]());
3164 template<class _Tp, class... _Args>
3165 typename __unique_if<_Tp>::__unique_array_known_bound
3166 make_unique(_Args&&...) = delete;
3168 #endif // _LIBCPP_STD_VER > 11
3170 template <class _Tp> struct hash;
3172 template <class _Size>
3173 inline _LIBCPP_INLINE_VISIBILITY
3175 __loadword(const void* __p)
3178 std::memcpy(&__r, __p, sizeof(__r));
3182 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3183 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3184 // multiplication, which can be very slow on 32-bit systems.
3185 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3186 struct __murmur2_or_cityhash;
3188 template <class _Size>
3189 struct __murmur2_or_cityhash<_Size, 32>
3191 _Size operator()(const void* __key, _Size __len);
3195 template <class _Size>
3197 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3199 const _Size __m = 0x5bd1e995;
3200 const _Size __r = 24;
3202 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3203 for (; __len >= 4; __data += 4, __len -= 4)
3205 _Size __k = __loadword<_Size>(__data);
3215 __h ^= __data[2] << 16;
3217 __h ^= __data[1] << 8;
3228 template <class _Size>
3229 struct __murmur2_or_cityhash<_Size, 64>
3231 _Size operator()(const void* __key, _Size __len);
3234 // Some primes between 2^63 and 2^64.
3235 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3236 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3237 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3238 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3240 static _Size __rotate(_Size __val, int __shift) {
3241 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3244 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3245 return (__val >> __shift) | (__val << (64 - __shift));
3248 static _Size __shift_mix(_Size __val) {
3249 return __val ^ (__val >> 47);
3252 static _Size __hash_len_16(_Size __u, _Size __v) {
3253 const _Size __mul = 0x9ddfea08eb382d69ULL;
3254 _Size __a = (__u ^ __v) * __mul;
3256 _Size __b = (__v ^ __a) * __mul;
3262 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3264 const _Size __a = __loadword<_Size>(__s);
3265 const _Size __b = __loadword<_Size>(__s + __len - 8);
3266 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3269 const uint32_t __a = __loadword<uint32_t>(__s);
3270 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3271 return __hash_len_16(__len + (__a << 3), __b);
3274 const unsigned char __a = __s[0];
3275 const unsigned char __b = __s[__len >> 1];
3276 const unsigned char __c = __s[__len - 1];
3277 const uint32_t __y = static_cast<uint32_t>(__a) +
3278 (static_cast<uint32_t>(__b) << 8);
3279 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3280 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3285 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3286 const _Size __a = __loadword<_Size>(__s) * __k1;
3287 const _Size __b = __loadword<_Size>(__s + 8);
3288 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3289 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3290 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3291 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3294 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3295 // Callers do best to use "random-looking" values for a and b.
3296 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3297 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3299 __b = __rotate(__b + __a + __z, 21);
3300 const _Size __c = __a;
3303 __b += __rotate(__a, 44);
3304 return pair<_Size, _Size>(__a + __z, __b + __c);
3307 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3308 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3309 const char* __s, _Size __a, _Size __b) {
3310 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3311 __loadword<_Size>(__s + 8),
3312 __loadword<_Size>(__s + 16),
3313 __loadword<_Size>(__s + 24),
3318 // Return an 8-byte hash for 33 to 64 bytes.
3319 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3320 _Size __z = __loadword<_Size>(__s + 24);
3321 _Size __a = __loadword<_Size>(__s) +
3322 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3323 _Size __b = __rotate(__a + __z, 52);
3324 _Size __c = __rotate(__a, 37);
3325 __a += __loadword<_Size>(__s + 8);
3326 __c += __rotate(__a, 7);
3327 __a += __loadword<_Size>(__s + 16);
3328 _Size __vf = __a + __z;
3329 _Size __vs = __b + __rotate(__a, 31) + __c;
3330 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3331 __z += __loadword<_Size>(__s + __len - 8);
3332 __b = __rotate(__a + __z, 52);
3333 __c = __rotate(__a, 37);
3334 __a += __loadword<_Size>(__s + __len - 24);
3335 __c += __rotate(__a, 7);
3336 __a += __loadword<_Size>(__s + __len - 16);
3337 _Size __wf = __a + __z;
3338 _Size __ws = __b + __rotate(__a, 31) + __c;
3339 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3340 return __shift_mix(__r * __k0 + __vs) * __k2;
3345 template <class _Size>
3347 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3349 const char* __s = static_cast<const char*>(__key);
3352 return __hash_len_0_to_16(__s, __len);
3354 return __hash_len_17_to_32(__s, __len);
3356 } else if (__len <= 64) {
3357 return __hash_len_33_to_64(__s, __len);
3360 // For strings over 64 bytes we hash the end first, and then as we
3361 // loop we keep 56 bytes of state: v, w, x, y, and z.
3362 _Size __x = __loadword<_Size>(__s + __len - 40);
3363 _Size __y = __loadword<_Size>(__s + __len - 16) +
3364 __loadword<_Size>(__s + __len - 56);
3365 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3366 __loadword<_Size>(__s + __len - 24));
3367 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3368 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3369 __x = __x * __k1 + __loadword<_Size>(__s);
3371 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3372 __len = (__len - 1) & ~static_cast<_Size>(63);
3374 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3375 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3377 __y += __v.first + __loadword<_Size>(__s + 40);
3378 __z = __rotate(__z + __w.first, 33) * __k1;
3379 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3380 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3381 __y + __loadword<_Size>(__s + 16));
3382 std::swap(__z, __x);
3385 } while (__len != 0);
3386 return __hash_len_16(
3387 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3388 __hash_len_16(__v.second, __w.second) + __x);
3391 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3392 struct __scalar_hash;
3394 template <class _Tp>
3395 struct __scalar_hash<_Tp, 0>
3396 : public unary_function<_Tp, size_t>
3398 _LIBCPP_INLINE_VISIBILITY
3399 size_t operator()(_Tp __v) const _NOEXCEPT
3412 template <class _Tp>
3413 struct __scalar_hash<_Tp, 1>
3414 : public unary_function<_Tp, size_t>
3416 _LIBCPP_INLINE_VISIBILITY
3417 size_t operator()(_Tp __v) const _NOEXCEPT
3429 template <class _Tp>
3430 struct __scalar_hash<_Tp, 2>
3431 : public unary_function<_Tp, size_t>
3433 _LIBCPP_INLINE_VISIBILITY
3434 size_t operator()(_Tp __v) const _NOEXCEPT
3446 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3450 template <class _Tp>
3451 struct __scalar_hash<_Tp, 3>
3452 : public unary_function<_Tp, size_t>
3454 _LIBCPP_INLINE_VISIBILITY
3455 size_t operator()(_Tp __v) const _NOEXCEPT
3468 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3472 template <class _Tp>
3473 struct __scalar_hash<_Tp, 4>
3474 : public unary_function<_Tp, size_t>
3476 _LIBCPP_INLINE_VISIBILITY
3477 size_t operator()(_Tp __v) const _NOEXCEPT
3491 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3496 struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3497 : public unary_function<_Tp*, size_t>
3499 _LIBCPP_INLINE_VISIBILITY
3500 size_t operator()(_Tp* __v) const _NOEXCEPT
3508 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3512 template <class _Tp, class _Dp>
3513 struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
3515 typedef unique_ptr<_Tp, _Dp> argument_type;
3516 typedef size_t result_type;
3517 _LIBCPP_INLINE_VISIBILITY
3518 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3520 typedef typename argument_type::pointer pointer;
3521 return hash<pointer>()(__ptr.get());
3530 template <class _Tp>
3531 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3532 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3534 template <class _Tp>
3535 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3538 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3540 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3543 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3545 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3548 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3551 template <class _Tp>
3552 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3553 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3555 template <class _Tp>
3556 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3557 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3559 template <class _Tp>
3560 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3561 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3564 template <class _Alloc>
3565 class __allocator_destructor
3567 typedef allocator_traits<_Alloc> __alloc_traits;
3569 typedef typename __alloc_traits::pointer pointer;
3570 typedef typename __alloc_traits::size_type size_type;
3575 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3577 : __alloc_(__a), __s_(__s) {}
3578 _LIBCPP_INLINE_VISIBILITY
3579 void operator()(pointer __p) _NOEXCEPT
3580 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3583 template <class _InputIterator, class _ForwardIterator>
3585 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3587 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3588 #ifndef _LIBCPP_NO_EXCEPTIONS
3589 _ForwardIterator __s = __r;
3593 for (; __f != __l; ++__f, (void) ++__r)
3594 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3595 #ifndef _LIBCPP_NO_EXCEPTIONS
3599 for (; __s != __r; ++__s)
3607 template <class _InputIterator, class _Size, class _ForwardIterator>
3609 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3611 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3612 #ifndef _LIBCPP_NO_EXCEPTIONS
3613 _ForwardIterator __s = __r;
3617 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3618 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3619 #ifndef _LIBCPP_NO_EXCEPTIONS
3623 for (; __s != __r; ++__s)
3631 template <class _ForwardIterator, class _Tp>
3633 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3635 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3636 #ifndef _LIBCPP_NO_EXCEPTIONS
3637 _ForwardIterator __s = __f;
3641 for (; __f != __l; ++__f)
3642 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3643 #ifndef _LIBCPP_NO_EXCEPTIONS
3647 for (; __s != __f; ++__s)
3654 template <class _ForwardIterator, class _Size, class _Tp>
3656 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3658 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3659 #ifndef _LIBCPP_NO_EXCEPTIONS
3660 _ForwardIterator __s = __f;
3664 for (; __n > 0; ++__f, (void) --__n)
3665 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3666 #ifndef _LIBCPP_NO_EXCEPTIONS
3670 for (; __s != __f; ++__s)
3678 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3679 : public std::exception
3682 virtual ~bad_weak_ptr() _NOEXCEPT;
3683 virtual const char* what() const _NOEXCEPT;
3686 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3688 class _LIBCPP_TYPE_VIS __shared_count
3690 __shared_count(const __shared_count&);
3691 __shared_count& operator=(const __shared_count&);
3694 long __shared_owners_;
3695 virtual ~__shared_count();
3697 virtual void __on_zero_shared() _NOEXCEPT = 0;
3700 _LIBCPP_INLINE_VISIBILITY
3701 explicit __shared_count(long __refs = 0) _NOEXCEPT
3702 : __shared_owners_(__refs) {}
3704 void __add_shared() _NOEXCEPT;
3705 bool __release_shared() _NOEXCEPT;
3706 _LIBCPP_INLINE_VISIBILITY
3707 long use_count() const _NOEXCEPT {
3708 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3712 class _LIBCPP_TYPE_VIS __shared_weak_count
3713 : private __shared_count
3715 long __shared_weak_owners_;
3718 _LIBCPP_INLINE_VISIBILITY
3719 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3720 : __shared_count(__refs),
3721 __shared_weak_owners_(__refs) {}
3723 virtual ~__shared_weak_count();
3726 void __add_shared() _NOEXCEPT;
3727 void __add_weak() _NOEXCEPT;
3728 void __release_shared() _NOEXCEPT;
3729 void __release_weak() _NOEXCEPT;
3730 _LIBCPP_INLINE_VISIBILITY
3731 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3732 __shared_weak_count* lock() _NOEXCEPT;
3734 // Define the function out only if we build static libc++ without RTTI.
3735 // Otherwise we may break clients who need to compile their projects with
3736 // -fno-rtti and yet link against a libc++.dylib compiled
3737 // without -fno-rtti.
3738 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3739 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3742 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3745 template <class _Tp, class _Dp, class _Alloc>
3746 class __shared_ptr_pointer
3747 : public __shared_weak_count
3749 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3751 _LIBCPP_INLINE_VISIBILITY
3752 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3753 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3755 #ifndef _LIBCPP_NO_RTTI
3756 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3760 virtual void __on_zero_shared() _NOEXCEPT;
3761 virtual void __on_zero_shared_weak() _NOEXCEPT;
3764 #ifndef _LIBCPP_NO_RTTI
3766 template <class _Tp, class _Dp, class _Alloc>
3768 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3770 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
3773 #endif // _LIBCPP_NO_RTTI
3775 template <class _Tp, class _Dp, class _Alloc>
3777 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3779 __data_.first().second()(__data_.first().first());
3780 __data_.first().second().~_Dp();
3783 template <class _Tp, class _Dp, class _Alloc>
3785 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3787 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3788 typedef allocator_traits<_Al> _ATraits;
3789 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3791 _Al __a(__data_.second());
3792 __data_.second().~_Alloc();
3793 __a.deallocate(_PTraits::pointer_to(*this), 1);
3796 template <class _Tp, class _Alloc>
3797 class __shared_ptr_emplace
3798 : public __shared_weak_count
3800 __compressed_pair<_Alloc, _Tp> __data_;
3802 #ifndef _LIBCPP_HAS_NO_VARIADICS
3804 _LIBCPP_INLINE_VISIBILITY
3805 __shared_ptr_emplace(_Alloc __a)
3806 : __data_(_VSTD::move(__a)) {}
3808 template <class ..._Args>
3809 _LIBCPP_INLINE_VISIBILITY
3810 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3811 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3812 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3814 #else // _LIBCPP_HAS_NO_VARIADICS
3816 _LIBCPP_INLINE_VISIBILITY
3817 __shared_ptr_emplace(_Alloc __a)
3820 template <class _A0>
3821 _LIBCPP_INLINE_VISIBILITY
3822 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3823 : __data_(__a, _Tp(__a0)) {}
3825 template <class _A0, class _A1>
3826 _LIBCPP_INLINE_VISIBILITY
3827 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3828 : __data_(__a, _Tp(__a0, __a1)) {}
3830 template <class _A0, class _A1, class _A2>
3831 _LIBCPP_INLINE_VISIBILITY
3832 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3833 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3835 #endif // _LIBCPP_HAS_NO_VARIADICS
3838 virtual void __on_zero_shared() _NOEXCEPT;
3839 virtual void __on_zero_shared_weak() _NOEXCEPT;
3841 _LIBCPP_INLINE_VISIBILITY
3842 _Tp* get() _NOEXCEPT {return &__data_.second();}
3845 template <class _Tp, class _Alloc>
3847 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3849 __data_.second().~_Tp();
3852 template <class _Tp, class _Alloc>
3854 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3856 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3857 typedef allocator_traits<_Al> _ATraits;
3858 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3859 _Al __a(__data_.first());
3860 __data_.first().~_Alloc();
3861 __a.deallocate(_PTraits::pointer_to(*this), 1);
3864 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3867 class _LIBCPP_TYPE_VIS_ONLY shared_ptr
3870 typedef _Tp element_type;
3872 element_type* __ptr_;
3873 __shared_weak_count* __cntrl_;
3875 struct __nat {int __for_bool_;};
3877 _LIBCPP_INLINE_VISIBILITY
3878 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3879 _LIBCPP_INLINE_VISIBILITY
3880 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3882 explicit shared_ptr(_Yp* __p,
3883 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3884 template<class _Yp, class _Dp>
3885 shared_ptr(_Yp* __p, _Dp __d,
3886 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3887 template<class _Yp, class _Dp, class _Alloc>
3888 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3889 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3890 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3891 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3892 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3893 _LIBCPP_INLINE_VISIBILITY
3894 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3896 _LIBCPP_INLINE_VISIBILITY
3897 shared_ptr(const shared_ptr<_Yp>& __r,
3898 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3900 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3901 _LIBCPP_INLINE_VISIBILITY
3902 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3903 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3904 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3906 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3907 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3908 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3909 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3911 shared_ptr(auto_ptr<_Yp>&& __r,
3912 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3915 shared_ptr(auto_ptr<_Yp> __r,
3916 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3918 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3919 template <class _Yp, class _Dp>
3920 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3923 !is_lvalue_reference<_Dp>::value &&
3924 !is_array<_Yp>::value &&
3925 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3928 template <class _Yp, class _Dp>
3929 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3932 is_lvalue_reference<_Dp>::value &&
3933 !is_array<_Yp>::value &&
3934 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3937 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3938 template <class _Yp, class _Dp>
3939 shared_ptr(unique_ptr<_Yp, _Dp>,
3942 !is_lvalue_reference<_Dp>::value &&
3943 !is_array<_Yp>::value &&
3944 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3947 template <class _Yp, class _Dp>
3948 shared_ptr(unique_ptr<_Yp, _Dp>,
3951 is_lvalue_reference<_Dp>::value &&
3952 !is_array<_Yp>::value &&
3953 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3956 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3960 _LIBCPP_INLINE_VISIBILITY
3961 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3965 is_convertible<_Yp*, element_type*>::value,
3968 _LIBCPP_INLINE_VISIBILITY
3969 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3970 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3971 _LIBCPP_INLINE_VISIBILITY
3972 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3976 is_convertible<_Yp*, element_type*>::value,
3979 _LIBCPP_INLINE_VISIBILITY
3980 operator=(shared_ptr<_Yp>&& __r);
3984 !is_array<_Yp>::value &&
3985 is_convertible<_Yp*, element_type*>::value,
3988 _LIBCPP_INLINE_VISIBILITY
3989 operator=(auto_ptr<_Yp>&& __r);
3990 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3994 !is_array<_Yp>::value &&
3995 is_convertible<_Yp*, element_type*>::value,
3998 operator=(auto_ptr<_Yp> __r);
4000 template <class _Yp, class _Dp>
4003 !is_array<_Yp>::value &&
4004 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4007 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4008 _LIBCPP_INLINE_VISIBILITY
4009 operator=(unique_ptr<_Yp, _Dp>&& __r);
4010 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4011 operator=(unique_ptr<_Yp, _Dp> __r);
4014 _LIBCPP_INLINE_VISIBILITY
4015 void swap(shared_ptr& __r) _NOEXCEPT;
4016 _LIBCPP_INLINE_VISIBILITY
4017 void reset() _NOEXCEPT;
4021 is_convertible<_Yp*, element_type*>::value,
4024 _LIBCPP_INLINE_VISIBILITY
4026 template<class _Yp, class _Dp>
4029 is_convertible<_Yp*, element_type*>::value,
4032 _LIBCPP_INLINE_VISIBILITY
4033 reset(_Yp* __p, _Dp __d);
4034 template<class _Yp, class _Dp, class _Alloc>
4037 is_convertible<_Yp*, element_type*>::value,
4040 _LIBCPP_INLINE_VISIBILITY
4041 reset(_Yp* __p, _Dp __d, _Alloc __a);
4043 _LIBCPP_INLINE_VISIBILITY
4044 element_type* get() const _NOEXCEPT {return __ptr_;}
4045 _LIBCPP_INLINE_VISIBILITY
4046 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4048 _LIBCPP_INLINE_VISIBILITY
4049 element_type* operator->() const _NOEXCEPT {return __ptr_;}
4050 _LIBCPP_INLINE_VISIBILITY
4051 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4052 _LIBCPP_INLINE_VISIBILITY
4053 bool unique() const _NOEXCEPT {return use_count() == 1;}
4054 _LIBCPP_INLINE_VISIBILITY
4055 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4056 template <class _Up>
4057 _LIBCPP_INLINE_VISIBILITY
4058 bool owner_before(shared_ptr<_Up> const& __p) const
4059 {return __cntrl_ < __p.__cntrl_;}
4060 template <class _Up>
4061 _LIBCPP_INLINE_VISIBILITY
4062 bool owner_before(weak_ptr<_Up> const& __p) const
4063 {return __cntrl_ < __p.__cntrl_;}
4064 _LIBCPP_INLINE_VISIBILITY
4066 __owner_equivalent(const shared_ptr& __p) const
4067 {return __cntrl_ == __p.__cntrl_;}
4069 #ifndef _LIBCPP_NO_RTTI
4070 template <class _Dp>
4071 _LIBCPP_INLINE_VISIBILITY
4072 _Dp* __get_deleter() const _NOEXCEPT
4073 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4074 #endif // _LIBCPP_NO_RTTI
4076 #ifndef _LIBCPP_HAS_NO_VARIADICS
4078 template<class ..._Args>
4081 make_shared(_Args&& ...__args);
4083 template<class _Alloc, class ..._Args>
4086 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4088 #else // _LIBCPP_HAS_NO_VARIADICS
4090 static shared_ptr<_Tp> make_shared();
4093 static shared_ptr<_Tp> make_shared(_A0&);
4095 template<class _A0, class _A1>
4096 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4098 template<class _A0, class _A1, class _A2>
4099 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4101 template<class _Alloc>
4102 static shared_ptr<_Tp>
4103 allocate_shared(const _Alloc& __a);
4105 template<class _Alloc, class _A0>
4106 static shared_ptr<_Tp>
4107 allocate_shared(const _Alloc& __a, _A0& __a0);
4109 template<class _Alloc, class _A0, class _A1>
4110 static shared_ptr<_Tp>
4111 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4113 template<class _Alloc, class _A0, class _A1, class _A2>
4114 static shared_ptr<_Tp>
4115 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4117 #endif // _LIBCPP_HAS_NO_VARIADICS
4121 template <class _Yp>
4122 _LIBCPP_INLINE_VISIBILITY
4124 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4128 __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e));
4129 __e->__weak_this_.__cntrl_ = __cntrl_;
4130 __cntrl_->__add_weak();
4134 _LIBCPP_INLINE_VISIBILITY
4135 void __enable_weak_this(const volatile void*) _NOEXCEPT {}
4137 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4138 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4144 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4153 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4161 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4162 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4165 unique_ptr<_Yp> __hold(__p);
4166 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4167 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4169 __enable_weak_this(__p);
4173 template<class _Yp, class _Dp>
4174 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4175 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4178 #ifndef _LIBCPP_NO_EXCEPTIONS
4181 #endif // _LIBCPP_NO_EXCEPTIONS
4182 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4183 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4184 __enable_weak_this(__p);
4185 #ifndef _LIBCPP_NO_EXCEPTIONS
4192 #endif // _LIBCPP_NO_EXCEPTIONS
4197 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4200 #ifndef _LIBCPP_NO_EXCEPTIONS
4203 #endif // _LIBCPP_NO_EXCEPTIONS
4204 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4205 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4206 #ifndef _LIBCPP_NO_EXCEPTIONS
4213 #endif // _LIBCPP_NO_EXCEPTIONS
4217 template<class _Yp, class _Dp, class _Alloc>
4218 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4219 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4222 #ifndef _LIBCPP_NO_EXCEPTIONS
4225 #endif // _LIBCPP_NO_EXCEPTIONS
4226 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4227 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4228 typedef __allocator_destructor<_A2> _D2;
4230 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4231 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4232 _CntrlBlk(__p, __d, __a);
4233 __cntrl_ = _VSTD::addressof(*__hold2.release());
4234 __enable_weak_this(__p);
4235 #ifndef _LIBCPP_NO_EXCEPTIONS
4242 #endif // _LIBCPP_NO_EXCEPTIONS
4246 template<class _Dp, class _Alloc>
4247 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4250 #ifndef _LIBCPP_NO_EXCEPTIONS
4253 #endif // _LIBCPP_NO_EXCEPTIONS
4254 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4255 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4256 typedef __allocator_destructor<_A2> _D2;
4258 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4259 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4260 _CntrlBlk(__p, __d, __a);
4261 __cntrl_ = _VSTD::addressof(*__hold2.release());
4262 #ifndef _LIBCPP_NO_EXCEPTIONS
4269 #endif // _LIBCPP_NO_EXCEPTIONS
4275 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4277 __cntrl_(__r.__cntrl_)
4280 __cntrl_->__add_shared();
4285 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4286 : __ptr_(__r.__ptr_),
4287 __cntrl_(__r.__cntrl_)
4290 __cntrl_->__add_shared();
4296 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4297 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4299 : __ptr_(__r.__ptr_),
4300 __cntrl_(__r.__cntrl_)
4303 __cntrl_->__add_shared();
4306 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4310 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4311 : __ptr_(__r.__ptr_),
4312 __cntrl_(__r.__cntrl_)
4321 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4322 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4324 : __ptr_(__r.__ptr_),
4325 __cntrl_(__r.__cntrl_)
4331 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4335 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4336 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4338 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4340 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4343 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4344 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4345 __enable_weak_this(__r.get());
4350 template <class _Yp, class _Dp>
4351 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4352 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4354 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4358 !is_lvalue_reference<_Dp>::value &&
4359 !is_array<_Yp>::value &&
4360 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4365 #if _LIBCPP_STD_VER > 11
4366 if (__ptr_ == nullptr)
4371 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4372 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4373 __enable_weak_this(__r.get());
4379 template <class _Yp, class _Dp>
4380 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4381 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4383 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4387 is_lvalue_reference<_Dp>::value &&
4388 !is_array<_Yp>::value &&
4389 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4394 #if _LIBCPP_STD_VER > 11
4395 if (__ptr_ == nullptr)
4400 typedef __shared_ptr_pointer<_Yp*,
4401 reference_wrapper<typename remove_reference<_Dp>::type>,
4402 allocator<_Yp> > _CntrlBlk;
4403 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4404 __enable_weak_this(__r.get());
4409 #ifndef _LIBCPP_HAS_NO_VARIADICS
4412 template<class ..._Args>
4414 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4416 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4417 typedef allocator<_CntrlBlk> _A2;
4418 typedef __allocator_destructor<_A2> _D2;
4420 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4421 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4422 shared_ptr<_Tp> __r;
4423 __r.__ptr_ = __hold2.get()->get();
4424 __r.__cntrl_ = __hold2.release();
4425 __r.__enable_weak_this(__r.__ptr_);
4430 template<class _Alloc, class ..._Args>
4432 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4434 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4435 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4436 typedef __allocator_destructor<_A2> _D2;
4438 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4439 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4440 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4441 shared_ptr<_Tp> __r;
4442 __r.__ptr_ = __hold2.get()->get();
4443 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4444 __r.__enable_weak_this(__r.__ptr_);
4448 #else // _LIBCPP_HAS_NO_VARIADICS
4452 shared_ptr<_Tp>::make_shared()
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);
4460 shared_ptr<_Tp> __r;
4461 __r.__ptr_ = __hold2.get()->get();
4462 __r.__cntrl_ = __hold2.release();
4463 __r.__enable_weak_this(__r.__ptr_);
4470 shared_ptr<_Tp>::make_shared(_A0& __a0)
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);
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 _A0, class _A1>
4488 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4490 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4491 typedef allocator<_CntrlBlk> _Alloc2;
4492 typedef __allocator_destructor<_Alloc2> _D2;
4494 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4495 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4496 shared_ptr<_Tp> __r;
4497 __r.__ptr_ = __hold2.get()->get();
4498 __r.__cntrl_ = __hold2.release();
4499 __r.__enable_weak_this(__r.__ptr_);
4504 template<class _A0, class _A1, class _A2>
4506 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4508 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4509 typedef allocator<_CntrlBlk> _Alloc2;
4510 typedef __allocator_destructor<_Alloc2> _D2;
4512 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4513 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4514 shared_ptr<_Tp> __r;
4515 __r.__ptr_ = __hold2.get()->get();
4516 __r.__cntrl_ = __hold2.release();
4517 __r.__enable_weak_this(__r.__ptr_);
4522 template<class _Alloc>
4524 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4526 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4527 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4528 typedef __allocator_destructor<_Alloc2> _D2;
4529 _Alloc2 __alloc2(__a);
4530 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4531 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4533 shared_ptr<_Tp> __r;
4534 __r.__ptr_ = __hold2.get()->get();
4535 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4536 __r.__enable_weak_this(__r.__ptr_);
4541 template<class _Alloc, class _A0>
4543 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4545 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4546 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4547 typedef __allocator_destructor<_Alloc2> _D2;
4548 _Alloc2 __alloc2(__a);
4549 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4550 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4551 _CntrlBlk(__a, __a0);
4552 shared_ptr<_Tp> __r;
4553 __r.__ptr_ = __hold2.get()->get();
4554 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4555 __r.__enable_weak_this(__r.__ptr_);
4560 template<class _Alloc, class _A0, class _A1>
4562 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4564 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4565 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4566 typedef __allocator_destructor<_Alloc2> _D2;
4567 _Alloc2 __alloc2(__a);
4568 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4569 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4570 _CntrlBlk(__a, __a0, __a1);
4571 shared_ptr<_Tp> __r;
4572 __r.__ptr_ = __hold2.get()->get();
4573 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4574 __r.__enable_weak_this(__r.__ptr_);
4579 template<class _Alloc, class _A0, class _A1, class _A2>
4581 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4583 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4584 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4585 typedef __allocator_destructor<_Alloc2> _D2;
4586 _Alloc2 __alloc2(__a);
4587 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4588 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4589 _CntrlBlk(__a, __a0, __a1, __a2);
4590 shared_ptr<_Tp> __r;
4591 __r.__ptr_ = __hold2.get()->get();
4592 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4593 __r.__enable_weak_this(__r.__ptr_);
4597 #endif // _LIBCPP_HAS_NO_VARIADICS
4600 shared_ptr<_Tp>::~shared_ptr()
4603 __cntrl_->__release_shared();
4609 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4611 shared_ptr(__r).swap(*this);
4620 is_convertible<_Yp*, _Tp*>::value,
4623 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4625 shared_ptr(__r).swap(*this);
4629 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4634 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4636 shared_ptr(_VSTD::move(__r)).swap(*this);
4645 is_convertible<_Yp*, _Tp*>::value,
4648 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4650 shared_ptr(_VSTD::move(__r)).swap(*this);
4659 !is_array<_Yp>::value &&
4660 is_convertible<_Yp*, _Tp*>::value,
4663 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4665 shared_ptr(_VSTD::move(__r)).swap(*this);
4670 template <class _Yp, class _Dp>
4674 !is_array<_Yp>::value &&
4675 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4678 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4680 shared_ptr(_VSTD::move(__r)).swap(*this);
4684 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4688 inline _LIBCPP_INLINE_VISIBILITY
4691 !is_array<_Yp>::value &&
4692 is_convertible<_Yp*, _Tp*>::value,
4695 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4697 shared_ptr(__r).swap(*this);
4702 template <class _Yp, class _Dp>
4703 inline _LIBCPP_INLINE_VISIBILITY
4706 !is_array<_Yp>::value &&
4707 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4710 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4712 shared_ptr(_VSTD::move(__r)).swap(*this);
4716 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4721 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4723 _VSTD::swap(__ptr_, __r.__ptr_);
4724 _VSTD::swap(__cntrl_, __r.__cntrl_);
4730 shared_ptr<_Tp>::reset() _NOEXCEPT
4732 shared_ptr().swap(*this);
4740 is_convertible<_Yp*, _Tp*>::value,
4743 shared_ptr<_Tp>::reset(_Yp* __p)
4745 shared_ptr(__p).swap(*this);
4749 template<class _Yp, class _Dp>
4753 is_convertible<_Yp*, _Tp*>::value,
4756 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4758 shared_ptr(__p, __d).swap(*this);
4762 template<class _Yp, class _Dp, class _Alloc>
4766 is_convertible<_Yp*, _Tp*>::value,
4769 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4771 shared_ptr(__p, __d, __a).swap(*this);
4774 #ifndef _LIBCPP_HAS_NO_VARIADICS
4776 template<class _Tp, class ..._Args>
4777 inline _LIBCPP_INLINE_VISIBILITY
4780 !is_array<_Tp>::value,
4783 make_shared(_Args&& ...__args)
4785 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4788 template<class _Tp, class _Alloc, class ..._Args>
4789 inline _LIBCPP_INLINE_VISIBILITY
4792 !is_array<_Tp>::value,
4795 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4797 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4800 #else // _LIBCPP_HAS_NO_VARIADICS
4803 inline _LIBCPP_INLINE_VISIBILITY
4807 return shared_ptr<_Tp>::make_shared();
4810 template<class _Tp, class _A0>
4811 inline _LIBCPP_INLINE_VISIBILITY
4813 make_shared(_A0& __a0)
4815 return shared_ptr<_Tp>::make_shared(__a0);
4818 template<class _Tp, class _A0, class _A1>
4819 inline _LIBCPP_INLINE_VISIBILITY
4821 make_shared(_A0& __a0, _A1& __a1)
4823 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4826 template<class _Tp, class _A0, class _A1, class _A2>
4827 inline _LIBCPP_INLINE_VISIBILITY
4829 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4831 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4834 template<class _Tp, class _Alloc>
4835 inline _LIBCPP_INLINE_VISIBILITY
4837 allocate_shared(const _Alloc& __a)
4839 return shared_ptr<_Tp>::allocate_shared(__a);
4842 template<class _Tp, class _Alloc, class _A0>
4843 inline _LIBCPP_INLINE_VISIBILITY
4845 allocate_shared(const _Alloc& __a, _A0& __a0)
4847 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4850 template<class _Tp, class _Alloc, class _A0, class _A1>
4851 inline _LIBCPP_INLINE_VISIBILITY
4853 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4855 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4858 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4859 inline _LIBCPP_INLINE_VISIBILITY
4861 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4863 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4866 #endif // _LIBCPP_HAS_NO_VARIADICS
4868 template<class _Tp, class _Up>
4869 inline _LIBCPP_INLINE_VISIBILITY
4871 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4873 return __x.get() == __y.get();
4876 template<class _Tp, class _Up>
4877 inline _LIBCPP_INLINE_VISIBILITY
4879 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4881 return !(__x == __y);
4884 template<class _Tp, class _Up>
4885 inline _LIBCPP_INLINE_VISIBILITY
4887 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4889 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4890 return less<_Vp>()(__x.get(), __y.get());
4893 template<class _Tp, class _Up>
4894 inline _LIBCPP_INLINE_VISIBILITY
4896 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4901 template<class _Tp, class _Up>
4902 inline _LIBCPP_INLINE_VISIBILITY
4904 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4906 return !(__y < __x);
4909 template<class _Tp, class _Up>
4910 inline _LIBCPP_INLINE_VISIBILITY
4912 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4914 return !(__x < __y);
4918 inline _LIBCPP_INLINE_VISIBILITY
4920 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4926 inline _LIBCPP_INLINE_VISIBILITY
4928 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4934 inline _LIBCPP_INLINE_VISIBILITY
4936 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4938 return static_cast<bool>(__x);
4942 inline _LIBCPP_INLINE_VISIBILITY
4944 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4946 return static_cast<bool>(__x);
4950 inline _LIBCPP_INLINE_VISIBILITY
4952 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4954 return less<_Tp*>()(__x.get(), nullptr);
4958 inline _LIBCPP_INLINE_VISIBILITY
4960 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4962 return less<_Tp*>()(nullptr, __x.get());
4966 inline _LIBCPP_INLINE_VISIBILITY
4968 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4970 return nullptr < __x;
4974 inline _LIBCPP_INLINE_VISIBILITY
4976 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4978 return __x < nullptr;
4982 inline _LIBCPP_INLINE_VISIBILITY
4984 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4986 return !(nullptr < __x);
4990 inline _LIBCPP_INLINE_VISIBILITY
4992 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4994 return !(__x < nullptr);
4998 inline _LIBCPP_INLINE_VISIBILITY
5000 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5002 return !(__x < nullptr);
5006 inline _LIBCPP_INLINE_VISIBILITY
5008 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5010 return !(nullptr < __x);
5014 inline _LIBCPP_INLINE_VISIBILITY
5016 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
5021 template<class _Tp, class _Up>
5022 inline _LIBCPP_INLINE_VISIBILITY
5025 !is_array<_Tp>::value && !is_array<_Up>::value,
5028 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5030 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
5033 template<class _Tp, class _Up>
5034 inline _LIBCPP_INLINE_VISIBILITY
5037 !is_array<_Tp>::value && !is_array<_Up>::value,
5040 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5042 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5043 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5046 template<class _Tp, class _Up>
5049 is_array<_Tp>::value == is_array<_Up>::value,
5052 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
5054 typedef typename remove_extent<_Tp>::type _RTp;
5055 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
5058 #ifndef _LIBCPP_NO_RTTI
5060 template<class _Dp, class _Tp>
5061 inline _LIBCPP_INLINE_VISIBILITY
5063 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
5065 return __p.template __get_deleter<_Dp>();
5068 #endif // _LIBCPP_NO_RTTI
5071 class _LIBCPP_TYPE_VIS_ONLY weak_ptr
5074 typedef _Tp element_type;
5076 element_type* __ptr_;
5077 __shared_weak_count* __cntrl_;
5080 _LIBCPP_INLINE_VISIBILITY
5081 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
5082 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
5083 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5085 _LIBCPP_INLINE_VISIBILITY
5086 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
5087 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
5088 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5091 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5092 _LIBCPP_INLINE_VISIBILITY
5093 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5094 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
5095 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5097 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5100 _LIBCPP_INLINE_VISIBILITY
5101 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5105 is_convertible<_Yp*, element_type*>::value,
5108 _LIBCPP_INLINE_VISIBILITY
5109 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5111 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5113 _LIBCPP_INLINE_VISIBILITY
5114 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5118 is_convertible<_Yp*, element_type*>::value,
5121 _LIBCPP_INLINE_VISIBILITY
5122 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5124 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5129 is_convertible<_Yp*, element_type*>::value,
5132 _LIBCPP_INLINE_VISIBILITY
5133 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5135 _LIBCPP_INLINE_VISIBILITY
5136 void swap(weak_ptr& __r) _NOEXCEPT;
5137 _LIBCPP_INLINE_VISIBILITY
5138 void reset() _NOEXCEPT;
5140 _LIBCPP_INLINE_VISIBILITY
5141 long use_count() const _NOEXCEPT
5142 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5143 _LIBCPP_INLINE_VISIBILITY
5144 bool expired() const _NOEXCEPT
5145 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5146 shared_ptr<_Tp> lock() const _NOEXCEPT;
5148 _LIBCPP_INLINE_VISIBILITY
5149 bool owner_before(const shared_ptr<_Up>& __r) const
5150 {return __cntrl_ < __r.__cntrl_;}
5152 _LIBCPP_INLINE_VISIBILITY
5153 bool owner_before(const weak_ptr<_Up>& __r) const
5154 {return __cntrl_ < __r.__cntrl_;}
5156 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5157 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
5163 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5171 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5172 : __ptr_(__r.__ptr_),
5173 __cntrl_(__r.__cntrl_)
5176 __cntrl_->__add_weak();
5182 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5183 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5185 : __ptr_(__r.__ptr_),
5186 __cntrl_(__r.__cntrl_)
5189 __cntrl_->__add_weak();
5195 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5196 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5198 : __ptr_(__r.__ptr_),
5199 __cntrl_(__r.__cntrl_)
5202 __cntrl_->__add_weak();
5205 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5209 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5210 : __ptr_(__r.__ptr_),
5211 __cntrl_(__r.__cntrl_)
5220 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5221 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5223 : __ptr_(__r.__ptr_),
5224 __cntrl_(__r.__cntrl_)
5230 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5233 weak_ptr<_Tp>::~weak_ptr()
5236 __cntrl_->__release_weak();
5242 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5244 weak_ptr(__r).swap(*this);
5253 is_convertible<_Yp*, _Tp*>::value,
5256 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5258 weak_ptr(__r).swap(*this);
5262 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5267 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5269 weak_ptr(_VSTD::move(__r)).swap(*this);
5278 is_convertible<_Yp*, _Tp*>::value,
5281 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5283 weak_ptr(_VSTD::move(__r)).swap(*this);
5287 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5294 is_convertible<_Yp*, _Tp*>::value,
5297 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5299 weak_ptr(__r).swap(*this);
5306 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5308 _VSTD::swap(__ptr_, __r.__ptr_);
5309 _VSTD::swap(__cntrl_, __r.__cntrl_);
5313 inline _LIBCPP_INLINE_VISIBILITY
5315 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5323 weak_ptr<_Tp>::reset() _NOEXCEPT
5325 weak_ptr().swap(*this);
5330 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5331 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5332 : __ptr_(__r.__ptr_),
5333 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5336 #ifndef _LIBCPP_NO_EXCEPTIONS
5337 throw bad_weak_ptr();
5339 assert(!"bad_weak_ptr");
5345 weak_ptr<_Tp>::lock() const _NOEXCEPT
5347 shared_ptr<_Tp> __r;
5348 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5350 __r.__ptr_ = __ptr_;
5354 template <class _Tp> struct owner_less;
5356 template <class _Tp>
5357 struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
5358 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5360 typedef bool result_type;
5361 _LIBCPP_INLINE_VISIBILITY
5362 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5363 {return __x.owner_before(__y);}
5364 _LIBCPP_INLINE_VISIBILITY
5365 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5366 {return __x.owner_before(__y);}
5367 _LIBCPP_INLINE_VISIBILITY
5368 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5369 {return __x.owner_before(__y);}
5372 template <class _Tp>
5373 struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
5374 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5376 typedef bool result_type;
5377 _LIBCPP_INLINE_VISIBILITY
5378 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5379 {return __x.owner_before(__y);}
5380 _LIBCPP_INLINE_VISIBILITY
5381 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5382 {return __x.owner_before(__y);}
5383 _LIBCPP_INLINE_VISIBILITY
5384 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5385 {return __x.owner_before(__y);}
5389 class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5391 mutable weak_ptr<_Tp> __weak_this_;
5393 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5394 enable_shared_from_this() _NOEXCEPT {}
5395 _LIBCPP_INLINE_VISIBILITY
5396 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5397 _LIBCPP_INLINE_VISIBILITY
5398 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5400 _LIBCPP_INLINE_VISIBILITY
5401 ~enable_shared_from_this() {}
5403 _LIBCPP_INLINE_VISIBILITY
5404 shared_ptr<_Tp> shared_from_this()
5405 {return shared_ptr<_Tp>(__weak_this_);}
5406 _LIBCPP_INLINE_VISIBILITY
5407 shared_ptr<_Tp const> shared_from_this() const
5408 {return shared_ptr<const _Tp>(__weak_this_);}
5410 template <class _Up> friend class shared_ptr;
5413 template <class _Tp>
5414 struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
5416 typedef shared_ptr<_Tp> argument_type;
5417 typedef size_t result_type;
5418 _LIBCPP_INLINE_VISIBILITY
5419 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5421 return hash<_Tp*>()(__ptr.get());
5425 template<class _CharT, class _Traits, class _Yp>
5426 inline _LIBCPP_INLINE_VISIBILITY
5427 basic_ostream<_CharT, _Traits>&
5428 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5430 // TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
5431 // enabled with clang.
5432 #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
5434 class _LIBCPP_TYPE_VIS __sp_mut
5438 void lock() _NOEXCEPT;
5439 void unlock() _NOEXCEPT;
5442 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5443 __sp_mut(const __sp_mut&);
5444 __sp_mut& operator=(const __sp_mut&);
5446 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5449 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5451 template <class _Tp>
5452 inline _LIBCPP_INLINE_VISIBILITY
5454 atomic_is_lock_free(const shared_ptr<_Tp>*)
5459 template <class _Tp>
5461 atomic_load(const shared_ptr<_Tp>* __p)
5463 __sp_mut& __m = __get_sp_mut(__p);
5465 shared_ptr<_Tp> __q = *__p;
5470 template <class _Tp>
5471 inline _LIBCPP_INLINE_VISIBILITY
5473 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5475 return atomic_load(__p);
5478 template <class _Tp>
5480 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5482 __sp_mut& __m = __get_sp_mut(__p);
5488 template <class _Tp>
5489 inline _LIBCPP_INLINE_VISIBILITY
5491 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5493 atomic_store(__p, __r);
5496 template <class _Tp>
5498 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5500 __sp_mut& __m = __get_sp_mut(__p);
5507 template <class _Tp>
5508 inline _LIBCPP_INLINE_VISIBILITY
5510 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5512 return atomic_exchange(__p, __r);
5515 template <class _Tp>
5517 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5519 __sp_mut& __m = __get_sp_mut(__p);
5521 if (__p->__owner_equivalent(*__v))
5532 template <class _Tp>
5533 inline _LIBCPP_INLINE_VISIBILITY
5535 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5537 return atomic_compare_exchange_strong(__p, __v, __w);
5540 template <class _Tp>
5541 inline _LIBCPP_INLINE_VISIBILITY
5543 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5544 shared_ptr<_Tp> __w, memory_order, memory_order)
5546 return atomic_compare_exchange_strong(__p, __v, __w);
5549 template <class _Tp>
5550 inline _LIBCPP_INLINE_VISIBILITY
5552 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5553 shared_ptr<_Tp> __w, memory_order, memory_order)
5555 return atomic_compare_exchange_weak(__p, __v, __w);
5558 #endif // defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
5561 struct _LIBCPP_TYPE_VIS pointer_safety
5572 _LIBCPP_INLINE_VISIBILITY
5573 pointer_safety(__lx __v) : __v_(__v) {}
5574 _LIBCPP_INLINE_VISIBILITY
5575 operator int() const {return __v_;}
5578 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5579 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5580 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5581 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5582 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5584 template <class _Tp>
5585 inline _LIBCPP_INLINE_VISIBILITY
5587 undeclare_reachable(_Tp* __p)
5589 return static_cast<_Tp*>(__undeclare_reachable(__p));
5592 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5594 // --- Helper for container swap --
5595 template <typename _Alloc>
5596 _LIBCPP_INLINE_VISIBILITY
5597 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5598 #if _LIBCPP_STD_VER >= 14
5601 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5604 __swap_allocator(__a1, __a2,
5605 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5608 template <typename _Alloc>
5609 _LIBCPP_INLINE_VISIBILITY
5610 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5611 #if _LIBCPP_STD_VER >= 14
5614 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5621 template <typename _Alloc>
5622 _LIBCPP_INLINE_VISIBILITY
5623 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5625 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5626 struct __noexcept_move_assign_container : public integral_constant<bool,
5627 _Traits::propagate_on_container_move_assignment::value
5628 #if _LIBCPP_STD_VER > 14
5629 || _Traits::is_always_equal::value
5631 && is_nothrow_move_assignable<_Alloc>::value
5635 _LIBCPP_END_NAMESPACE_STD
5637 #endif // _LIBCPP_MEMORY