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;
79 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
80 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
82 static pointer allocate(allocator_type& a, size_type n);
83 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
85 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
87 template <class T, class... Args>
88 static void construct(allocator_type& a, T* p, Args&&... args);
91 static void destroy(allocator_type& a, T* p);
93 static size_type max_size(const allocator_type& a);
96 select_on_container_copy_construction(const allocator_type& a);
100 class allocator<void>
103 typedef void* pointer;
104 typedef const void* const_pointer;
105 typedef void value_type;
107 template <class _Up> struct rebind {typedef allocator<_Up> other;};
114 typedef size_t size_type;
115 typedef ptrdiff_t difference_type;
117 typedef const T* const_pointer;
118 typedef typename add_lvalue_reference<T>::type reference;
119 typedef typename add_lvalue_reference<const T>::type const_reference;
120 typedef T value_type;
122 template <class U> struct rebind {typedef allocator<U> other;};
124 allocator() noexcept;
125 allocator(const allocator&) noexcept;
126 template <class U> allocator(const allocator<U>&) noexcept;
128 pointer address(reference x) const noexcept;
129 const_pointer address(const_reference x) const noexcept;
130 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
131 void deallocate(pointer p, size_type n) noexcept;
132 size_type max_size() const noexcept;
133 template<class U, class... Args>
134 void construct(U* p, Args&&... args);
139 template <class T, class U>
140 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
142 template <class T, class U>
143 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
145 template <class OutputIterator, class T>
146 class raw_storage_iterator
147 : public iterator<output_iterator_tag,
148 T, // purposefully not C++03
149 ptrdiff_t, // purposefully not C++03
150 T*, // purposefully not C++03
151 raw_storage_iterator&> // purposefully not C++03
154 explicit raw_storage_iterator(OutputIterator x);
155 raw_storage_iterator& operator*();
156 raw_storage_iterator& operator=(const T& element);
157 raw_storage_iterator& operator++();
158 raw_storage_iterator operator++(int);
161 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162 template <class T> void return_temporary_buffer(T* p) noexcept;
164 template <class T> T* addressof(T& r) noexcept;
166 template <class InputIterator, class ForwardIterator>
168 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
170 template <class InputIterator, class Size, class ForwardIterator>
172 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
174 template <class ForwardIterator, class T>
175 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
177 template <class ForwardIterator, class Size, class T>
179 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
181 template <class Y> struct auto_ptr_ref {};
187 typedef X element_type;
189 explicit auto_ptr(X* p =0) throw();
190 auto_ptr(auto_ptr&) throw();
191 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192 auto_ptr& operator=(auto_ptr&) throw();
193 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
197 typename add_lvalue_reference<X>::type operator*() const throw();
198 X* operator->() const throw();
199 X* get() const throw();
200 X* release() throw();
201 void reset(X* p =0) throw();
203 auto_ptr(auto_ptr_ref<X>) throw();
204 template<class Y> operator auto_ptr_ref<Y>() throw();
205 template<class Y> operator auto_ptr<Y>() throw();
209 struct default_delete
211 constexpr default_delete() noexcept = default;
212 template <class U> default_delete(const default_delete<U>&) noexcept;
214 void operator()(T*) const noexcept;
218 struct default_delete<T[]>
220 constexpr default_delete() noexcept = default;
221 void operator()(T*) const noexcept;
222 template <class U> void operator()(U*) const = delete;
225 template <class T, class D = default_delete<T>>
229 typedef see below pointer;
230 typedef T element_type;
231 typedef D deleter_type;
234 constexpr unique_ptr() noexcept;
235 explicit unique_ptr(pointer p) noexcept;
236 unique_ptr(pointer p, see below d1) noexcept;
237 unique_ptr(pointer p, see below d2) noexcept;
238 unique_ptr(unique_ptr&& u) noexcept;
239 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
240 template <class U, class E>
241 unique_ptr(unique_ptr<U, E>&& u) noexcept;
243 unique_ptr(auto_ptr<U>&& u) noexcept;
249 unique_ptr& operator=(unique_ptr&& u) noexcept;
250 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251 unique_ptr& operator=(nullptr_t) noexcept;
254 typename add_lvalue_reference<T>::type operator*() const;
255 pointer operator->() const noexcept;
256 pointer get() const noexcept;
257 deleter_type& get_deleter() noexcept;
258 const deleter_type& get_deleter() const noexcept;
259 explicit operator bool() const noexcept;
262 pointer release() noexcept;
263 void reset(pointer p = pointer()) noexcept;
264 void swap(unique_ptr& u) noexcept;
267 template <class T, class D>
268 class unique_ptr<T[], D>
271 typedef implementation-defined pointer;
272 typedef T element_type;
273 typedef D deleter_type;
276 constexpr unique_ptr() noexcept;
277 explicit unique_ptr(pointer p) noexcept;
278 unique_ptr(pointer p, see below d) noexcept;
279 unique_ptr(pointer p, see below d) noexcept;
280 unique_ptr(unique_ptr&& u) noexcept;
281 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
287 unique_ptr& operator=(unique_ptr&& u) noexcept;
288 unique_ptr& operator=(nullptr_t) noexcept;
291 T& operator[](size_t i) const;
292 pointer get() const noexcept;
293 deleter_type& get_deleter() noexcept;
294 const deleter_type& get_deleter() const noexcept;
295 explicit operator bool() const noexcept;
298 pointer release() noexcept;
299 void reset(pointer p = pointer()) noexcept;
300 void reset(nullptr_t) noexcept;
301 template <class U> void reset(U) = delete;
302 void swap(unique_ptr& u) noexcept;
305 template <class T, class D>
306 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
308 template <class T1, class D1, class T2, class D2>
309 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
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);
321 template <class T, class D>
322 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323 template <class T, class D>
324 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325 template <class T, class D>
326 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327 template <class T, class D>
328 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
330 template <class T, class D>
331 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332 template <class T, class D>
333 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334 template <class T, class D>
335 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336 template <class T, class D>
337 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338 template <class T, class D>
339 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340 template <class T, class D>
341 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342 template <class T, class D>
343 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344 template <class T, class D>
345 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
348 : public std::exception
350 bad_weak_ptr() noexcept;
353 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
354 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
355 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
361 typedef T element_type;
364 constexpr shared_ptr() noexcept;
365 template<class Y> explicit shared_ptr(Y* p);
366 template<class Y, class D> shared_ptr(Y* p, D d);
367 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
368 template <class D> shared_ptr(nullptr_t p, D d);
369 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
370 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
371 shared_ptr(const shared_ptr& r) noexcept;
372 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
373 shared_ptr(shared_ptr&& r) noexcept;
374 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
375 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
376 template<class Y> shared_ptr(auto_ptr<Y>&& r);
377 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
378 shared_ptr(nullptr_t) : shared_ptr() { }
384 shared_ptr& operator=(const shared_ptr& r) noexcept;
385 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
386 shared_ptr& operator=(shared_ptr&& r) noexcept;
387 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
388 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
389 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
392 void swap(shared_ptr& r) noexcept;
393 void reset() noexcept;
394 template<class Y> void reset(Y* p);
395 template<class Y, class D> void reset(Y* p, D d);
396 template<class Y, class D, class A> void reset(Y* p, D d, A a);
399 T* get() const noexcept;
400 T& operator*() const noexcept;
401 T* operator->() const noexcept;
402 long use_count() const noexcept;
403 bool unique() const noexcept;
404 explicit operator bool() const noexcept;
405 template<class U> bool owner_before(shared_ptr<U> const& b) const;
406 template<class U> bool owner_before(weak_ptr<U> const& b) const;
409 // shared_ptr comparisons:
410 template<class T, class U>
411 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
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;
424 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
426 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
428 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
430 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
432 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
434 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
436 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
438 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
440 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
442 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
444 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
446 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
448 // shared_ptr specialized algorithms:
449 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
452 template<class T, class U>
453 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
454 template<class T, class U>
455 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
456 template<class T, class U>
457 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
460 template<class E, class T, class Y>
461 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
463 // shared_ptr get_deleter:
464 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
466 template<class T, class... Args>
467 shared_ptr<T> make_shared(Args&&... args);
468 template<class T, class A, class... Args>
469 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
475 typedef T element_type;
478 constexpr weak_ptr() noexcept;
479 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
480 weak_ptr(weak_ptr const& r) noexcept;
481 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
487 weak_ptr& operator=(weak_ptr const& r) noexcept;
488 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
489 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
492 void swap(weak_ptr& r) noexcept;
493 void reset() noexcept;
496 long use_count() const noexcept;
497 bool expired() const noexcept;
498 shared_ptr<T> lock() const noexcept;
499 template<class U> bool owner_before(shared_ptr<U> const& b);
500 template<class U> bool owner_before(weak_ptr<U> const& b);
503 // weak_ptr specialized algorithms:
504 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
507 template<class T> struct owner_less;
510 struct owner_less<shared_ptr<T>>
511 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
513 typedef bool result_type;
514 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
515 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
516 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
520 struct owner_less<weak_ptr<T>>
521 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
523 typedef bool result_type;
524 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
525 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
526 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
530 class enable_shared_from_this
533 constexpr enable_shared_from_this() noexcept;
534 enable_shared_from_this(enable_shared_from_this const&) noexcept;
535 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
536 ~enable_shared_from_this();
538 shared_ptr<T> shared_from_this();
539 shared_ptr<T const> shared_from_this() const;
543 bool atomic_is_lock_free(const shared_ptr<T>* p);
545 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
547 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
549 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
551 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
553 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
556 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
559 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
562 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
565 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
566 shared_ptr<T> w, memory_order success,
567 memory_order failure);
570 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
571 shared_ptr<T> w, memory_order success,
572 memory_order failure);
574 template <class T> struct hash;
575 template <class T, class D> struct hash<unique_ptr<T, D> >;
576 template <class T> struct hash<shared_ptr<T> >;
579 enum class pointer_safety { relaxed, preferred, strict };
580 void declare_reachable(void *p);
581 template <class T> T *undeclare_reachable(T *p);
582 void declare_no_pointers(char *p, size_t n);
583 void undeclare_no_pointers(char *p, size_t n);
584 pointer_safety get_pointer_safety() noexcept;
586 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
593 #include <type_traits>
601 #include <__functional_base>
605 #if defined(_LIBCPP_NO_EXCEPTIONS)
609 #if __has_feature(cxx_atomic)
613 #include <__undef_min_max>
615 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
616 #pragma GCC system_header
619 _LIBCPP_BEGIN_NAMESPACE_STD
624 inline _LIBCPP_INLINE_VISIBILITY
626 addressof(_Tp& __x) _NOEXCEPT
628 return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
631 #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
632 // Objective-C++ Automatic Reference Counting uses qualified pointers
633 // that require special addressof() signatures. When
634 // _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
635 // itself is providing these definitions. Otherwise, we provide them.
637 inline _LIBCPP_INLINE_VISIBILITY
639 addressof(__strong _Tp& __x) _NOEXCEPT
644 #ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
646 inline _LIBCPP_INLINE_VISIBILITY
648 addressof(__weak _Tp& __x) _NOEXCEPT
655 inline _LIBCPP_INLINE_VISIBILITY
657 addressof(__autoreleasing _Tp& __x) _NOEXCEPT
663 inline _LIBCPP_INLINE_VISIBILITY
664 __unsafe_unretained _Tp*
665 addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
671 template <class _Tp> class allocator;
674 class _LIBCPP_TYPE_VIS allocator<void>
677 typedef void* pointer;
678 typedef const void* const_pointer;
679 typedef void value_type;
681 template <class _Up> struct rebind {typedef allocator<_Up> other;};
685 class _LIBCPP_TYPE_VIS allocator<const void>
688 typedef const void* pointer;
689 typedef const void* const_pointer;
690 typedef const void value_type;
692 template <class _Up> struct rebind {typedef allocator<_Up> other;};
698 struct __has_element_type
701 struct __two {char __lx; char __lxx;};
702 template <class _Up> static __two __test(...);
703 template <class _Up> static char __test(typename _Up::element_type* = 0);
705 static const bool value = sizeof(__test<_Tp>(0)) == 1;
708 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
709 struct __pointer_traits_element_type;
711 template <class _Ptr>
712 struct __pointer_traits_element_type<_Ptr, true>
714 typedef typename _Ptr::element_type type;
717 #ifndef _LIBCPP_HAS_NO_VARIADICS
719 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
720 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
722 typedef typename _Sp<_Tp, _Args...>::element_type type;
725 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
726 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
731 #else // _LIBCPP_HAS_NO_VARIADICS
733 template <template <class> class _Sp, class _Tp>
734 struct __pointer_traits_element_type<_Sp<_Tp>, true>
736 typedef typename _Sp<_Tp>::element_type type;
739 template <template <class> class _Sp, class _Tp>
740 struct __pointer_traits_element_type<_Sp<_Tp>, false>
745 template <template <class, class> class _Sp, class _Tp, class _A0>
746 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
748 typedef typename _Sp<_Tp, _A0>::element_type type;
751 template <template <class, class> class _Sp, class _Tp, class _A0>
752 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
757 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
758 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
760 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
763 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
764 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
769 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
770 class _A1, class _A2>
771 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
773 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
776 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
777 class _A1, class _A2>
778 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
783 #endif // _LIBCPP_HAS_NO_VARIADICS
786 struct __has_difference_type
789 struct __two {char __lx; char __lxx;};
790 template <class _Up> static __two __test(...);
791 template <class _Up> static char __test(typename _Up::difference_type* = 0);
793 static const bool value = sizeof(__test<_Tp>(0)) == 1;
796 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
797 struct __pointer_traits_difference_type
799 typedef ptrdiff_t type;
802 template <class _Ptr>
803 struct __pointer_traits_difference_type<_Ptr, true>
805 typedef typename _Ptr::difference_type type;
808 template <class _Tp, class _Up>
812 struct __two {char __lx; char __lxx;};
813 template <class _Xp> static __two __test(...);
814 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
816 static const bool value = sizeof(__test<_Tp>(0)) == 1;
819 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
820 struct __pointer_traits_rebind
822 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
823 typedef typename _Tp::template rebind<_Up> type;
825 typedef typename _Tp::template rebind<_Up>::other type;
829 #ifndef _LIBCPP_HAS_NO_VARIADICS
831 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
832 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
834 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
835 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
837 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
841 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
842 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
844 typedef _Sp<_Up, _Args...> type;
847 #else // _LIBCPP_HAS_NO_VARIADICS
849 template <template <class> class _Sp, class _Tp, class _Up>
850 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
852 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
853 typedef typename _Sp<_Tp>::template rebind<_Up> type;
855 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
859 template <template <class> class _Sp, class _Tp, class _Up>
860 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
862 typedef _Sp<_Up> type;
865 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
866 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
868 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
869 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
871 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
875 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
876 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
878 typedef _Sp<_Up, _A0> type;
881 template <template <class, class, class> class _Sp, class _Tp, class _A0,
882 class _A1, class _Up>
883 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
885 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
886 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
888 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
892 template <template <class, class, class> class _Sp, class _Tp, class _A0,
893 class _A1, class _Up>
894 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
896 typedef _Sp<_Up, _A0, _A1> type;
899 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
900 class _A1, class _A2, class _Up>
901 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
903 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
904 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
906 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
910 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
911 class _A1, class _A2, class _Up>
912 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
914 typedef _Sp<_Up, _A0, _A1, _A2> type;
917 #endif // _LIBCPP_HAS_NO_VARIADICS
919 template <class _Ptr>
920 struct _LIBCPP_TYPE_VIS pointer_traits
922 typedef _Ptr pointer;
923 typedef typename __pointer_traits_element_type<pointer>::type element_type;
924 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
926 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
927 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
929 template <class _Up> struct rebind
930 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
931 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
936 _LIBCPP_INLINE_VISIBILITY
937 static pointer pointer_to(typename conditional<is_void<element_type>::value,
938 __nat, element_type>::type& __r)
939 {return pointer::pointer_to(__r);}
943 struct _LIBCPP_TYPE_VIS pointer_traits<_Tp*>
945 typedef _Tp* pointer;
946 typedef _Tp element_type;
947 typedef ptrdiff_t difference_type;
949 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
950 template <class _Up> using rebind = _Up*;
952 template <class _Up> struct rebind {typedef _Up* other;};
958 _LIBCPP_INLINE_VISIBILITY
959 static pointer pointer_to(typename conditional<is_void<element_type>::value,
960 __nat, element_type>::type& __r) _NOEXCEPT
961 {return _VSTD::addressof(__r);}
966 namespace __has_pointer_type_imp
968 template <class _Up> static __two __test(...);
969 template <class _Up> static char __test(typename _Up::pointer* = 0);
973 struct __has_pointer_type
974 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
978 namespace __pointer_type_imp
981 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
982 struct __pointer_type
984 typedef typename _Dp::pointer type;
987 template <class _Tp, class _Dp>
988 struct __pointer_type<_Tp, _Dp, false>
993 } // __pointer_type_imp
995 template <class _Tp, class _Dp>
996 struct __pointer_type
998 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1001 template <class _Tp>
1002 struct __has_const_pointer
1005 struct __two {char __lx; char __lxx;};
1006 template <class _Up> static __two __test(...);
1007 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1009 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1012 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1013 struct __const_pointer
1015 typedef typename _Alloc::const_pointer type;
1018 template <class _Tp, class _Ptr, class _Alloc>
1019 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1021 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1022 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1024 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1028 template <class _Tp>
1029 struct __has_void_pointer
1032 struct __two {char __lx; char __lxx;};
1033 template <class _Up> static __two __test(...);
1034 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1036 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1039 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1040 struct __void_pointer
1042 typedef typename _Alloc::void_pointer type;
1045 template <class _Ptr, class _Alloc>
1046 struct __void_pointer<_Ptr, _Alloc, false>
1048 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1049 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1051 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1055 template <class _Tp>
1056 struct __has_const_void_pointer
1059 struct __two {char __lx; char __lxx;};
1060 template <class _Up> static __two __test(...);
1061 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1063 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1066 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1067 struct __const_void_pointer
1069 typedef typename _Alloc::const_void_pointer type;
1072 template <class _Ptr, class _Alloc>
1073 struct __const_void_pointer<_Ptr, _Alloc, false>
1075 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1076 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1078 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1082 template <class _Tp>
1083 inline _LIBCPP_INLINE_VISIBILITY
1085 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1090 template <class _Pointer>
1091 inline _LIBCPP_INLINE_VISIBILITY
1092 typename pointer_traits<_Pointer>::element_type*
1093 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1095 return _VSTD::__to_raw_pointer(__p.operator->());
1098 template <class _Tp>
1099 struct __has_size_type
1102 struct __two {char __lx; char __lxx;};
1103 template <class _Up> static __two __test(...);
1104 template <class _Up> static char __test(typename _Up::size_type* = 0);
1106 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1109 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1112 typedef typename make_unsigned<_DiffType>::type type;
1115 template <class _Alloc, class _DiffType>
1116 struct __size_type<_Alloc, _DiffType, true>
1118 typedef typename _Alloc::size_type type;
1121 template <class _Tp>
1122 struct __has_propagate_on_container_copy_assignment
1125 struct __two {char __lx; char __lxx;};
1126 template <class _Up> static __two __test(...);
1127 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1129 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1132 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1133 struct __propagate_on_container_copy_assignment
1135 typedef false_type type;
1138 template <class _Alloc>
1139 struct __propagate_on_container_copy_assignment<_Alloc, true>
1141 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1144 template <class _Tp>
1145 struct __has_propagate_on_container_move_assignment
1148 struct __two {char __lx; char __lxx;};
1149 template <class _Up> static __two __test(...);
1150 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1152 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1155 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1156 struct __propagate_on_container_move_assignment
1158 typedef false_type type;
1161 template <class _Alloc>
1162 struct __propagate_on_container_move_assignment<_Alloc, true>
1164 typedef typename _Alloc::propagate_on_container_move_assignment type;
1167 template <class _Tp>
1168 struct __has_propagate_on_container_swap
1171 struct __two {char __lx; char __lxx;};
1172 template <class _Up> static __two __test(...);
1173 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1175 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1178 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1179 struct __propagate_on_container_swap
1181 typedef false_type type;
1184 template <class _Alloc>
1185 struct __propagate_on_container_swap<_Alloc, true>
1187 typedef typename _Alloc::propagate_on_container_swap type;
1190 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1191 struct __has_rebind_other
1194 struct __two {char __lx; char __lxx;};
1195 template <class _Xp> static __two __test(...);
1196 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1198 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1201 template <class _Tp, class _Up>
1202 struct __has_rebind_other<_Tp, _Up, false>
1204 static const bool value = false;
1207 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1208 struct __allocator_traits_rebind
1210 typedef typename _Tp::template rebind<_Up>::other type;
1213 #ifndef _LIBCPP_HAS_NO_VARIADICS
1215 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1216 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1218 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1221 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1222 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1224 typedef _Alloc<_Up, _Args...> type;
1227 #else // _LIBCPP_HAS_NO_VARIADICS
1229 template <template <class> class _Alloc, class _Tp, class _Up>
1230 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1232 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1235 template <template <class> class _Alloc, class _Tp, class _Up>
1236 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1238 typedef _Alloc<_Up> type;
1241 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1242 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1244 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1247 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1248 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1250 typedef _Alloc<_Up, _A0> type;
1253 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1254 class _A1, class _Up>
1255 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1257 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1260 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1261 class _A1, class _Up>
1262 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1264 typedef _Alloc<_Up, _A0, _A1> type;
1267 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1268 class _A1, class _A2, class _Up>
1269 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1271 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1274 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1275 class _A1, class _A2, class _Up>
1276 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1278 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1281 #endif // _LIBCPP_HAS_NO_VARIADICS
1283 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1285 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1287 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1288 -> decltype(__a.allocate(__sz, __p), true_type());
1290 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1292 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1295 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1296 struct __has_allocate_hint
1297 : integral_constant<bool,
1299 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1300 declval<_SizeType>(),
1301 declval<_ConstVoidPtr>())),
1306 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1308 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1309 struct __has_allocate_hint
1314 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1316 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1318 template <class _Alloc, class _Tp, class ..._Args>
1319 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1320 _VSTD::declval<_Args>()...),
1322 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1324 template <class _Alloc, class _Pointer, class ..._Args>
1326 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1328 template <class _Alloc, class _Pointer, class ..._Args>
1329 struct __has_construct
1330 : integral_constant<bool,
1332 decltype(__has_construct_test(declval<_Alloc>(),
1333 declval<_Pointer>(),
1334 declval<_Args>()...)),
1339 template <class _Alloc, class _Pointer>
1341 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1342 -> decltype(__a.destroy(__p), true_type());
1344 template <class _Alloc, class _Pointer>
1346 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1349 template <class _Alloc, class _Pointer>
1350 struct __has_destroy
1351 : integral_constant<bool,
1353 decltype(__has_destroy_test(declval<_Alloc>(),
1354 declval<_Pointer>())),
1359 template <class _Alloc>
1361 __has_max_size_test(_Alloc&& __a)
1362 -> decltype(__a.max_size(), true_type());
1364 template <class _Alloc>
1366 __has_max_size_test(const volatile _Alloc& __a)
1369 template <class _Alloc>
1370 struct __has_max_size
1371 : integral_constant<bool,
1373 decltype(__has_max_size_test(declval<_Alloc&>())),
1378 template <class _Alloc>
1380 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1381 -> decltype(__a.select_on_container_copy_construction(), true_type());
1383 template <class _Alloc>
1385 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1388 template <class _Alloc>
1389 struct __has_select_on_container_copy_construction
1390 : integral_constant<bool,
1392 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1397 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1399 #ifndef _LIBCPP_HAS_NO_VARIADICS
1401 template <class _Alloc, class _Pointer, class ..._Args>
1402 struct __has_construct
1407 #else // _LIBCPP_HAS_NO_VARIADICS
1409 template <class _Alloc, class _Pointer, class _Args>
1410 struct __has_construct
1415 #endif // _LIBCPP_HAS_NO_VARIADICS
1417 template <class _Alloc, class _Pointer>
1418 struct __has_destroy
1423 template <class _Alloc>
1424 struct __has_max_size
1429 template <class _Alloc>
1430 struct __has_select_on_container_copy_construction
1435 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1437 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1438 struct __alloc_traits_difference_type
1440 typedef typename pointer_traits<_Ptr>::difference_type type;
1443 template <class _Alloc, class _Ptr>
1444 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1446 typedef typename _Alloc::difference_type type;
1449 template <class _Alloc>
1450 struct _LIBCPP_TYPE_VIS allocator_traits
1452 typedef _Alloc allocator_type;
1453 typedef typename allocator_type::value_type value_type;
1455 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1456 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1457 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1458 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1460 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1461 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1463 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1464 propagate_on_container_copy_assignment;
1465 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1466 propagate_on_container_move_assignment;
1467 typedef typename __propagate_on_container_swap<allocator_type>::type
1468 propagate_on_container_swap;
1470 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1471 template <class _Tp> using rebind_alloc =
1472 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1473 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1474 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1475 template <class _Tp> struct rebind_alloc
1476 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1477 template <class _Tp> struct rebind_traits
1478 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1479 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1481 _LIBCPP_INLINE_VISIBILITY
1482 static pointer allocate(allocator_type& __a, size_type __n)
1483 {return __a.allocate(__n);}
1484 _LIBCPP_INLINE_VISIBILITY
1485 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1486 {return allocate(__a, __n, __hint,
1487 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1489 _LIBCPP_INLINE_VISIBILITY
1490 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1491 {__a.deallocate(__p, __n);}
1493 #ifndef _LIBCPP_HAS_NO_VARIADICS
1494 template <class _Tp, class... _Args>
1495 _LIBCPP_INLINE_VISIBILITY
1496 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1497 {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1498 __a, __p, _VSTD::forward<_Args>(__args)...);}
1499 #else // _LIBCPP_HAS_NO_VARIADICS
1500 template <class _Tp>
1501 _LIBCPP_INLINE_VISIBILITY
1502 static void construct(allocator_type& __a, _Tp* __p)
1504 ::new ((void*)__p) _Tp();
1506 template <class _Tp, class _A0>
1507 _LIBCPP_INLINE_VISIBILITY
1508 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1510 ::new ((void*)__p) _Tp(__a0);
1512 template <class _Tp, class _A0, class _A1>
1513 _LIBCPP_INLINE_VISIBILITY
1514 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1517 ::new ((void*)__p) _Tp(__a0, __a1);
1519 template <class _Tp, class _A0, class _A1, class _A2>
1520 _LIBCPP_INLINE_VISIBILITY
1521 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1522 const _A1& __a1, const _A2& __a2)
1524 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1526 #endif // _LIBCPP_HAS_NO_VARIADICS
1528 template <class _Tp>
1529 _LIBCPP_INLINE_VISIBILITY
1530 static void destroy(allocator_type& __a, _Tp* __p)
1531 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1533 _LIBCPP_INLINE_VISIBILITY
1534 static size_type max_size(const allocator_type& __a)
1535 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1537 _LIBCPP_INLINE_VISIBILITY
1538 static allocator_type
1539 select_on_container_copy_construction(const allocator_type& __a)
1540 {return select_on_container_copy_construction(
1541 __has_select_on_container_copy_construction<const allocator_type>(),
1544 template <class _Ptr>
1545 _LIBCPP_INLINE_VISIBILITY
1548 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1550 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1551 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1554 template <class _Tp>
1555 _LIBCPP_INLINE_VISIBILITY
1559 (is_same<allocator_type, allocator<_Tp> >::value
1560 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1561 is_trivially_move_constructible<_Tp>::value,
1564 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1566 ptrdiff_t _Np = __end1 - __begin1;
1567 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1571 template <class _Ptr>
1572 _LIBCPP_INLINE_VISIBILITY
1575 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1577 while (__end1 != __begin1)
1579 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1584 template <class _Tp>
1585 _LIBCPP_INLINE_VISIBILITY
1589 (is_same<allocator_type, allocator<_Tp> >::value
1590 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1591 is_trivially_move_constructible<_Tp>::value,
1594 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1596 ptrdiff_t _Np = __end1 - __begin1;
1598 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1603 _LIBCPP_INLINE_VISIBILITY
1604 static pointer allocate(allocator_type& __a, size_type __n,
1605 const_void_pointer __hint, true_type)
1606 {return __a.allocate(__n, __hint);}
1607 _LIBCPP_INLINE_VISIBILITY
1608 static pointer allocate(allocator_type& __a, size_type __n,
1609 const_void_pointer, false_type)
1610 {return __a.allocate(__n);}
1612 #ifndef _LIBCPP_HAS_NO_VARIADICS
1613 template <class _Tp, class... _Args>
1614 _LIBCPP_INLINE_VISIBILITY
1615 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1616 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1617 template <class _Tp, class... _Args>
1618 _LIBCPP_INLINE_VISIBILITY
1619 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1621 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1623 #endif // _LIBCPP_HAS_NO_VARIADICS
1625 template <class _Tp>
1626 _LIBCPP_INLINE_VISIBILITY
1627 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1629 template <class _Tp>
1630 _LIBCPP_INLINE_VISIBILITY
1631 static void __destroy(false_type, allocator_type&, _Tp* __p)
1636 _LIBCPP_INLINE_VISIBILITY
1637 static size_type __max_size(true_type, const allocator_type& __a)
1638 {return __a.max_size();}
1639 _LIBCPP_INLINE_VISIBILITY
1640 static size_type __max_size(false_type, const allocator_type&)
1641 {return numeric_limits<size_type>::max();}
1643 _LIBCPP_INLINE_VISIBILITY
1644 static allocator_type
1645 select_on_container_copy_construction(true_type, const allocator_type& __a)
1646 {return __a.select_on_container_copy_construction();}
1647 _LIBCPP_INLINE_VISIBILITY
1648 static allocator_type
1649 select_on_container_copy_construction(false_type, const allocator_type& __a)
1655 template <class _Tp>
1656 class _LIBCPP_TYPE_VIS allocator
1659 typedef size_t size_type;
1660 typedef ptrdiff_t difference_type;
1661 typedef _Tp* pointer;
1662 typedef const _Tp* const_pointer;
1663 typedef _Tp& reference;
1664 typedef const _Tp& const_reference;
1665 typedef _Tp value_type;
1667 typedef true_type propagate_on_container_move_assignment;
1669 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1671 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1672 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1673 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1674 {return _VSTD::addressof(__x);}
1675 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1676 {return _VSTD::addressof(__x);}
1677 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1678 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1679 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1680 {::operator delete((void*)__p);}
1681 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1682 {return size_type(~0) / sizeof(_Tp);}
1683 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1684 template <class _Up, class... _Args>
1685 _LIBCPP_INLINE_VISIBILITY
1687 construct(_Up* __p, _Args&&... __args)
1689 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1691 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1692 _LIBCPP_INLINE_VISIBILITY
1694 construct(pointer __p)
1696 ::new((void*)__p) _Tp();
1698 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1700 template <class _A0>
1701 _LIBCPP_INLINE_VISIBILITY
1703 construct(pointer __p, _A0& __a0)
1705 ::new((void*)__p) _Tp(__a0);
1707 template <class _A0>
1708 _LIBCPP_INLINE_VISIBILITY
1710 construct(pointer __p, const _A0& __a0)
1712 ::new((void*)__p) _Tp(__a0);
1714 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1715 template <class _A0, class _A1>
1716 _LIBCPP_INLINE_VISIBILITY
1718 construct(pointer __p, _A0& __a0, _A1& __a1)
1720 ::new((void*)__p) _Tp(__a0, __a1);
1722 template <class _A0, class _A1>
1723 _LIBCPP_INLINE_VISIBILITY
1725 construct(pointer __p, const _A0& __a0, _A1& __a1)
1727 ::new((void*)__p) _Tp(__a0, __a1);
1729 template <class _A0, class _A1>
1730 _LIBCPP_INLINE_VISIBILITY
1732 construct(pointer __p, _A0& __a0, const _A1& __a1)
1734 ::new((void*)__p) _Tp(__a0, __a1);
1736 template <class _A0, class _A1>
1737 _LIBCPP_INLINE_VISIBILITY
1739 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1741 ::new((void*)__p) _Tp(__a0, __a1);
1743 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1744 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1747 template <class _Tp>
1748 class _LIBCPP_TYPE_VIS allocator<const _Tp>
1751 typedef size_t size_type;
1752 typedef ptrdiff_t difference_type;
1753 typedef const _Tp* pointer;
1754 typedef const _Tp* const_pointer;
1755 typedef const _Tp& reference;
1756 typedef const _Tp& const_reference;
1757 typedef const _Tp value_type;
1759 typedef true_type propagate_on_container_move_assignment;
1761 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1763 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1764 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1765 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1766 {return _VSTD::addressof(__x);}
1767 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1768 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1769 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1770 {::operator delete((void*)__p);}
1771 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1772 {return size_type(~0) / sizeof(_Tp);}
1773 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1774 template <class _Up, class... _Args>
1775 _LIBCPP_INLINE_VISIBILITY
1777 construct(_Up* __p, _Args&&... __args)
1779 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1781 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1782 _LIBCPP_INLINE_VISIBILITY
1784 construct(pointer __p)
1786 ::new((void*)__p) _Tp();
1788 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1790 template <class _A0>
1791 _LIBCPP_INLINE_VISIBILITY
1793 construct(pointer __p, _A0& __a0)
1795 ::new((void*)__p) _Tp(__a0);
1797 template <class _A0>
1798 _LIBCPP_INLINE_VISIBILITY
1800 construct(pointer __p, const _A0& __a0)
1802 ::new((void*)__p) _Tp(__a0);
1804 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1805 template <class _A0, class _A1>
1806 _LIBCPP_INLINE_VISIBILITY
1808 construct(pointer __p, _A0& __a0, _A1& __a1)
1810 ::new((void*)__p) _Tp(__a0, __a1);
1812 template <class _A0, class _A1>
1813 _LIBCPP_INLINE_VISIBILITY
1815 construct(pointer __p, const _A0& __a0, _A1& __a1)
1817 ::new((void*)__p) _Tp(__a0, __a1);
1819 template <class _A0, class _A1>
1820 _LIBCPP_INLINE_VISIBILITY
1822 construct(pointer __p, _A0& __a0, const _A1& __a1)
1824 ::new((void*)__p) _Tp(__a0, __a1);
1826 template <class _A0, class _A1>
1827 _LIBCPP_INLINE_VISIBILITY
1829 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1831 ::new((void*)__p) _Tp(__a0, __a1);
1833 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1834 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1837 template <class _Tp, class _Up>
1838 inline _LIBCPP_INLINE_VISIBILITY
1839 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1841 template <class _Tp, class _Up>
1842 inline _LIBCPP_INLINE_VISIBILITY
1843 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1845 template <class _OutputIterator, class _Tp>
1846 class _LIBCPP_TYPE_VIS raw_storage_iterator
1847 : public iterator<output_iterator_tag,
1848 _Tp, // purposefully not C++03
1849 ptrdiff_t, // purposefully not C++03
1850 _Tp*, // purposefully not C++03
1851 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1854 _OutputIterator __x_;
1856 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1857 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1858 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1859 {::new(&*__x_) _Tp(__element); return *this;}
1860 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1861 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1862 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1865 template <class _Tp>
1866 pair<_Tp*, ptrdiff_t>
1867 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1869 pair<_Tp*, ptrdiff_t> __r(0, 0);
1870 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1871 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1877 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1888 template <class _Tp>
1889 inline _LIBCPP_INLINE_VISIBILITY
1890 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1892 template <class _Tp>
1899 class _LIBCPP_TYPE_VIS auto_ptr
1904 typedef _Tp element_type;
1906 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1907 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1908 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1909 : __ptr_(__p.release()) {}
1910 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1911 {reset(__p.release()); return *this;}
1912 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1913 {reset(__p.release()); return *this;}
1914 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1915 {reset(__p.__ptr_); return *this;}
1916 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1918 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1920 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1921 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1922 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1928 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1935 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1936 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1937 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1938 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1939 {return auto_ptr<_Up>(release());}
1943 class _LIBCPP_TYPE_VIS auto_ptr<void>
1946 typedef void element_type;
1949 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1950 typename remove_cv<_T2>::type>::value,
1951 bool = is_empty<_T1>::value
1952 #if __has_feature(is_final)
1956 bool = is_empty<_T2>::value
1957 #if __has_feature(is_final)
1961 struct __libcpp_compressed_pair_switch;
1963 template <class _T1, class _T2, bool IsSame>
1964 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1966 template <class _T1, class _T2, bool IsSame>
1967 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1969 template <class _T1, class _T2, bool IsSame>
1970 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1972 template <class _T1, class _T2>
1973 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1975 template <class _T1, class _T2>
1976 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1978 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1979 class __libcpp_compressed_pair_imp;
1981 template <class _T1, class _T2>
1982 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1988 typedef _T1 _T1_param;
1989 typedef _T2 _T2_param;
1991 typedef typename remove_reference<_T1>::type& _T1_reference;
1992 typedef typename remove_reference<_T2>::type& _T2_reference;
1994 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1995 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1997 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1998 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1999 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2000 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2001 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2002 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2003 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2005 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2007 _LIBCPP_INLINE_VISIBILITY
2008 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2009 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2010 is_nothrow_copy_constructible<_T2>::value)
2011 : __first_(__p.first()),
2012 __second_(__p.second()) {}
2014 _LIBCPP_INLINE_VISIBILITY
2015 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2016 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2017 is_nothrow_copy_assignable<_T2>::value)
2019 __first_ = __p.first();
2020 __second_ = __p.second();
2024 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2026 _LIBCPP_INLINE_VISIBILITY
2027 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2028 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2029 is_nothrow_move_constructible<_T2>::value)
2030 : __first_(_VSTD::forward<_T1>(__p.first())),
2031 __second_(_VSTD::forward<_T2>(__p.second())) {}
2033 _LIBCPP_INLINE_VISIBILITY
2034 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2035 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2036 is_nothrow_move_assignable<_T2>::value)
2038 __first_ = _VSTD::forward<_T1>(__p.first());
2039 __second_ = _VSTD::forward<_T2>(__p.second());
2043 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2045 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2047 #ifndef _LIBCPP_HAS_NO_VARIADICS
2049 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2050 _LIBCPP_INLINE_VISIBILITY
2051 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2052 tuple<_Args1...> __first_args,
2053 tuple<_Args2...> __second_args,
2054 __tuple_indices<_I1...>,
2055 __tuple_indices<_I2...>)
2056 : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2057 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2060 #endif // _LIBCPP_HAS_NO_VARIADICS
2062 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2063 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2065 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2066 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2068 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2069 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2070 __is_nothrow_swappable<_T1>::value)
2073 swap(__first_, __x.__first_);
2074 swap(__second_, __x.__second_);
2078 template <class _T1, class _T2>
2079 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2085 typedef _T1 _T1_param;
2086 typedef _T2 _T2_param;
2088 typedef _T1& _T1_reference;
2089 typedef typename remove_reference<_T2>::type& _T2_reference;
2091 typedef const _T1& _T1_const_reference;
2092 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2094 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2095 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2096 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2097 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2098 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2099 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2100 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2102 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2104 _LIBCPP_INLINE_VISIBILITY
2105 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2106 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2107 is_nothrow_copy_constructible<_T2>::value)
2108 : _T1(__p.first()), __second_(__p.second()) {}
2110 _LIBCPP_INLINE_VISIBILITY
2111 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2112 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2113 is_nothrow_copy_assignable<_T2>::value)
2115 _T1::operator=(__p.first());
2116 __second_ = __p.second();
2120 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2122 _LIBCPP_INLINE_VISIBILITY
2123 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2124 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2125 is_nothrow_move_constructible<_T2>::value)
2126 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2128 _LIBCPP_INLINE_VISIBILITY
2129 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2130 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2131 is_nothrow_move_assignable<_T2>::value)
2133 _T1::operator=(_VSTD::move(__p.first()));
2134 __second_ = _VSTD::forward<_T2>(__p.second());
2138 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2140 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2142 #ifndef _LIBCPP_HAS_NO_VARIADICS
2144 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2145 _LIBCPP_INLINE_VISIBILITY
2146 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2147 tuple<_Args1...> __first_args,
2148 tuple<_Args2...> __second_args,
2149 __tuple_indices<_I1...>,
2150 __tuple_indices<_I2...>)
2151 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2152 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2155 #endif // _LIBCPP_HAS_NO_VARIADICS
2157 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2158 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2160 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2161 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2163 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2164 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2165 __is_nothrow_swappable<_T1>::value)
2168 swap(__second_, __x.__second_);
2172 template <class _T1, class _T2>
2173 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2179 typedef _T1 _T1_param;
2180 typedef _T2 _T2_param;
2182 typedef typename remove_reference<_T1>::type& _T1_reference;
2183 typedef _T2& _T2_reference;
2185 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2186 typedef const _T2& _T2_const_reference;
2188 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2189 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2190 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2191 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2192 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2193 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2194 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2195 is_nothrow_move_constructible<_T2>::value)
2196 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2198 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2200 _LIBCPP_INLINE_VISIBILITY
2201 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2202 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2203 is_nothrow_copy_constructible<_T2>::value)
2204 : _T2(__p.second()), __first_(__p.first()) {}
2206 _LIBCPP_INLINE_VISIBILITY
2207 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2208 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2209 is_nothrow_copy_assignable<_T2>::value)
2211 _T2::operator=(__p.second());
2212 __first_ = __p.first();
2216 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2218 _LIBCPP_INLINE_VISIBILITY
2219 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2220 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2221 is_nothrow_move_constructible<_T2>::value)
2222 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2224 _LIBCPP_INLINE_VISIBILITY
2225 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2226 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2227 is_nothrow_move_assignable<_T2>::value)
2229 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2230 __first_ = _VSTD::move(__p.first());
2234 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2236 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2238 #ifndef _LIBCPP_HAS_NO_VARIADICS
2240 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2241 _LIBCPP_INLINE_VISIBILITY
2242 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2243 tuple<_Args1...> __first_args,
2244 tuple<_Args2...> __second_args,
2245 __tuple_indices<_I1...>,
2246 __tuple_indices<_I2...>)
2247 : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2248 __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2252 #endif // _LIBCPP_HAS_NO_VARIADICS
2254 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2255 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2257 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2258 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2260 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2261 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2262 __is_nothrow_swappable<_T1>::value)
2265 swap(__first_, __x.__first_);
2269 template <class _T1, class _T2>
2270 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2275 typedef _T1 _T1_param;
2276 typedef _T2 _T2_param;
2278 typedef _T1& _T1_reference;
2279 typedef _T2& _T2_reference;
2281 typedef const _T1& _T1_const_reference;
2282 typedef const _T2& _T2_const_reference;
2284 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2285 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2286 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2287 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2288 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2289 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2290 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2292 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2294 _LIBCPP_INLINE_VISIBILITY
2295 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2296 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2297 is_nothrow_copy_constructible<_T2>::value)
2298 : _T1(__p.first()), _T2(__p.second()) {}
2300 _LIBCPP_INLINE_VISIBILITY
2301 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2302 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2303 is_nothrow_copy_assignable<_T2>::value)
2305 _T1::operator=(__p.first());
2306 _T2::operator=(__p.second());
2310 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2312 _LIBCPP_INLINE_VISIBILITY
2313 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2314 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2315 is_nothrow_move_constructible<_T2>::value)
2316 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2318 _LIBCPP_INLINE_VISIBILITY
2319 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2320 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2321 is_nothrow_move_assignable<_T2>::value)
2323 _T1::operator=(_VSTD::move(__p.first()));
2324 _T2::operator=(_VSTD::move(__p.second()));
2328 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2330 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2332 #ifndef _LIBCPP_HAS_NO_VARIADICS
2334 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2335 _LIBCPP_INLINE_VISIBILITY
2336 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2337 tuple<_Args1...> __first_args,
2338 tuple<_Args2...> __second_args,
2339 __tuple_indices<_I1...>,
2340 __tuple_indices<_I2...>)
2341 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2342 _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2345 #endif // _LIBCPP_HAS_NO_VARIADICS
2347 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2348 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2350 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2351 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2353 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2354 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2355 __is_nothrow_swappable<_T1>::value)
2360 template <class _T1, class _T2>
2361 class __compressed_pair
2362 : private __libcpp_compressed_pair_imp<_T1, _T2>
2364 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2366 typedef typename base::_T1_param _T1_param;
2367 typedef typename base::_T2_param _T2_param;
2369 typedef typename base::_T1_reference _T1_reference;
2370 typedef typename base::_T2_reference _T2_reference;
2372 typedef typename base::_T1_const_reference _T1_const_reference;
2373 typedef typename base::_T2_const_reference _T2_const_reference;
2375 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2376 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2377 : base(_VSTD::forward<_T1_param>(__t1)) {}
2378 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2379 : base(_VSTD::forward<_T2_param>(__t2)) {}
2380 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2381 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2383 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2385 _LIBCPP_INLINE_VISIBILITY
2386 __compressed_pair(const __compressed_pair& __p)
2387 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2388 is_nothrow_copy_constructible<_T2>::value)
2391 _LIBCPP_INLINE_VISIBILITY
2392 __compressed_pair& operator=(const __compressed_pair& __p)
2393 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2394 is_nothrow_copy_assignable<_T2>::value)
2396 base::operator=(__p);
2400 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2401 _LIBCPP_INLINE_VISIBILITY
2402 __compressed_pair(__compressed_pair&& __p)
2403 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2404 is_nothrow_move_constructible<_T2>::value)
2405 : base(_VSTD::move(__p)) {}
2407 _LIBCPP_INLINE_VISIBILITY
2408 __compressed_pair& operator=(__compressed_pair&& __p)
2409 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2410 is_nothrow_move_assignable<_T2>::value)
2412 base::operator=(_VSTD::move(__p));
2416 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2418 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2420 #ifndef _LIBCPP_HAS_NO_VARIADICS
2422 template <class... _Args1, class... _Args2>
2423 _LIBCPP_INLINE_VISIBILITY
2424 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2425 tuple<_Args2...> __second_args)
2426 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2427 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2428 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2431 #endif // _LIBCPP_HAS_NO_VARIADICS
2433 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2434 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2436 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2437 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2439 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2440 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2441 __is_nothrow_swappable<_T1>::value)
2445 template <class _T1, class _T2>
2446 inline _LIBCPP_INLINE_VISIBILITY
2448 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2449 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2450 __is_nothrow_swappable<_T1>::value)
2453 // __same_or_less_cv_qualified
2455 template <class _Ptr1, class _Ptr2,
2456 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2457 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2460 struct __same_or_less_cv_qualified_imp
2461 : is_convertible<_Ptr1, _Ptr2> {};
2463 template <class _Ptr1, class _Ptr2>
2464 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2467 template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2468 !is_pointer<_Ptr1>::value>
2469 struct __same_or_less_cv_qualified
2470 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2472 template <class _Ptr1, class _Ptr2>
2473 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2478 template <class _Tp>
2479 struct _LIBCPP_TYPE_VIS default_delete
2481 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2484 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2486 template <class _Up>
2487 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2488 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2489 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2491 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2492 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2497 template <class _Tp>
2498 struct _LIBCPP_TYPE_VIS default_delete<_Tp[]>
2501 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2502 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2504 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2506 template <class _Up>
2507 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2508 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2509 template <class _Up>
2510 _LIBCPP_INLINE_VISIBILITY
2511 void operator() (_Up* __ptr,
2512 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2514 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2515 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2520 template <class _Tp, class _Dp = default_delete<_Tp> >
2521 class _LIBCPP_TYPE_VIS unique_ptr
2524 typedef _Tp element_type;
2525 typedef _Dp deleter_type;
2526 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2528 __compressed_pair<pointer, deleter_type> __ptr_;
2530 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2531 unique_ptr(unique_ptr&);
2532 template <class _Up, class _Ep>
2533 unique_ptr(unique_ptr<_Up, _Ep>&);
2534 unique_ptr& operator=(unique_ptr&);
2535 template <class _Up, class _Ep>
2536 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2537 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2539 struct __nat {int __for_bool_;};
2541 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2542 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2544 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2547 static_assert(!is_pointer<deleter_type>::value,
2548 "unique_ptr constructed with null function pointer deleter");
2550 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2553 static_assert(!is_pointer<deleter_type>::value,
2554 "unique_ptr constructed with null function pointer deleter");
2556 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2557 : __ptr_(_VSTD::move(__p))
2559 static_assert(!is_pointer<deleter_type>::value,
2560 "unique_ptr constructed with null function pointer deleter");
2563 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2564 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2565 is_reference<deleter_type>::value,
2567 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2569 : __ptr_(__p, __d) {}
2571 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2573 : __ptr_(__p, _VSTD::move(__d))
2575 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2577 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2578 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2579 template <class _Up, class _Ep>
2580 _LIBCPP_INLINE_VISIBILITY
2581 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2584 !is_array<_Up>::value &&
2585 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2586 is_convertible<_Ep, deleter_type>::value &&
2588 !is_reference<deleter_type>::value ||
2589 is_same<deleter_type, _Ep>::value
2592 >::type = __nat()) _NOEXCEPT
2593 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2595 template <class _Up>
2596 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2598 is_convertible<_Up*, _Tp*>::value &&
2599 is_same<_Dp, default_delete<_Tp> >::value,
2601 >::type = __nat()) _NOEXCEPT
2602 : __ptr_(__p.release())
2606 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2608 reset(__u.release());
2609 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2613 template <class _Up, class _Ep>
2614 _LIBCPP_INLINE_VISIBILITY
2617 !is_array<_Up>::value &&
2618 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2619 is_assignable<deleter_type&, _Ep&&>::value,
2622 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2624 reset(__u.release());
2625 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2628 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2630 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2632 return __rv<unique_ptr>(*this);
2635 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2636 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2638 template <class _Up, class _Ep>
2639 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2641 reset(__u.release());
2642 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2646 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2647 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2649 template <class _Up>
2650 _LIBCPP_INLINE_VISIBILITY
2652 is_convertible<_Up*, _Tp*>::value &&
2653 is_same<_Dp, default_delete<_Tp> >::value,
2656 operator=(auto_ptr<_Up> __p)
2657 {reset(__p.release()); return *this;}
2659 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2660 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2662 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2668 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2669 {return *__ptr_.first();}
2670 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2671 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2672 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2673 {return __ptr_.second();}
2674 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2675 {return __ptr_.second();}
2676 _LIBCPP_INLINE_VISIBILITY
2677 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2678 {return __ptr_.first() != nullptr;}
2680 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2682 pointer __t = __ptr_.first();
2683 __ptr_.first() = pointer();
2687 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2689 pointer __tmp = __ptr_.first();
2690 __ptr_.first() = __p;
2692 __ptr_.second()(__tmp);
2695 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2696 {__ptr_.swap(__u.__ptr_);}
2699 template <class _Tp, class _Dp>
2700 class _LIBCPP_TYPE_VIS unique_ptr<_Tp[], _Dp>
2703 typedef _Tp element_type;
2704 typedef _Dp deleter_type;
2705 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2707 __compressed_pair<pointer, deleter_type> __ptr_;
2709 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2710 unique_ptr(unique_ptr&);
2711 template <class _Up>
2712 unique_ptr(unique_ptr<_Up>&);
2713 unique_ptr& operator=(unique_ptr&);
2714 template <class _Up>
2715 unique_ptr& operator=(unique_ptr<_Up>&);
2716 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2718 struct __nat {int __for_bool_;};
2720 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2721 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2723 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2726 static_assert(!is_pointer<deleter_type>::value,
2727 "unique_ptr constructed with null function pointer deleter");
2729 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2732 static_assert(!is_pointer<deleter_type>::value,
2733 "unique_ptr constructed with null function pointer deleter");
2735 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2736 template <class _Pp,
2737 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2739 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2742 static_assert(!is_pointer<deleter_type>::value,
2743 "unique_ptr constructed with null function pointer deleter");
2746 template <class _Pp,
2747 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2749 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2750 is_reference<deleter_type>::value,
2752 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2754 : __ptr_(__p, __d) {}
2756 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2757 is_reference<deleter_type>::value,
2759 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2761 : __ptr_(pointer(), __d) {}
2763 template <class _Pp,
2764 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2766 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2768 : __ptr_(__p, _VSTD::move(__d))
2770 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2773 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2775 : __ptr_(pointer(), _VSTD::move(__d))
2777 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2780 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2781 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2783 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2785 reset(__u.release());
2786 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2790 template <class _Up, class _Ep>
2791 _LIBCPP_INLINE_VISIBILITY
2792 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2795 is_array<_Up>::value &&
2796 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2797 && is_convertible<_Ep, deleter_type>::value &&
2799 !is_reference<deleter_type>::value ||
2800 is_same<deleter_type, _Ep>::value
2805 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2808 template <class _Up, class _Ep>
2809 _LIBCPP_INLINE_VISIBILITY
2812 is_array<_Up>::value &&
2813 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2814 is_assignable<deleter_type&, _Ep&&>::value,
2817 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2819 reset(__u.release());
2820 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2823 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2825 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2828 static_assert(!is_pointer<deleter_type>::value,
2829 "unique_ptr constructed with null function pointer deleter");
2832 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2833 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2835 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2836 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2838 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2840 return __rv<unique_ptr>(*this);
2843 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2844 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2846 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2848 reset(__u->release());
2849 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2853 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2854 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2856 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2862 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2863 {return __ptr_.first()[__i];}
2864 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2865 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2866 {return __ptr_.second();}
2867 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2868 {return __ptr_.second();}
2869 _LIBCPP_INLINE_VISIBILITY
2870 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2871 {return __ptr_.first() != nullptr;}
2873 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2875 pointer __t = __ptr_.first();
2876 __ptr_.first() = pointer();
2880 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2881 template <class _Pp,
2882 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2884 _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2886 pointer __tmp = __ptr_.first();
2887 __ptr_.first() = __p;
2889 __ptr_.second()(__tmp);
2891 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2893 pointer __tmp = __ptr_.first();
2894 __ptr_.first() = nullptr;
2896 __ptr_.second()(__tmp);
2898 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2900 pointer __tmp = __ptr_.first();
2901 __ptr_.first() = nullptr;
2903 __ptr_.second()(__tmp);
2905 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2906 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2908 pointer __tmp = __ptr_.first();
2909 __ptr_.first() = __p;
2911 __ptr_.second()(__tmp);
2913 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2915 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2918 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2919 template <class _Up>
2920 explicit unique_ptr(_Up);
2921 template <class _Up>
2923 typename conditional<
2924 is_reference<deleter_type>::value,
2926 typename add_lvalue_reference<const deleter_type>::type>::type,
2929 is_convertible<_Up, pointer>::value,
2932 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2935 template <class _Tp, class _Dp>
2936 inline _LIBCPP_INLINE_VISIBILITY
2938 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2940 template <class _T1, class _D1, class _T2, class _D2>
2941 inline _LIBCPP_INLINE_VISIBILITY
2943 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2945 template <class _T1, class _D1, class _T2, class _D2>
2946 inline _LIBCPP_INLINE_VISIBILITY
2948 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2950 template <class _T1, class _D1, class _T2, class _D2>
2951 inline _LIBCPP_INLINE_VISIBILITY
2953 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2955 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2956 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2957 typedef typename common_type<_P1, _P2>::type _V;
2958 return less<_V>()(__x.get(), __y.get());
2961 template <class _T1, class _D1, class _T2, class _D2>
2962 inline _LIBCPP_INLINE_VISIBILITY
2964 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2966 template <class _T1, class _D1, class _T2, class _D2>
2967 inline _LIBCPP_INLINE_VISIBILITY
2969 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2971 template <class _T1, class _D1, class _T2, class _D2>
2972 inline _LIBCPP_INLINE_VISIBILITY
2974 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2976 template <class _T1, class _D1>
2977 inline _LIBCPP_INLINE_VISIBILITY
2979 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2984 template <class _T1, class _D1>
2985 inline _LIBCPP_INLINE_VISIBILITY
2987 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2992 template <class _T1, class _D1>
2993 inline _LIBCPP_INLINE_VISIBILITY
2995 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2997 return static_cast<bool>(__x);
3000 template <class _T1, class _D1>
3001 inline _LIBCPP_INLINE_VISIBILITY
3003 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3005 return static_cast<bool>(__x);
3008 template <class _T1, class _D1>
3009 inline _LIBCPP_INLINE_VISIBILITY
3011 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3013 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3014 return less<_P1>()(__x.get(), nullptr);
3017 template <class _T1, class _D1>
3018 inline _LIBCPP_INLINE_VISIBILITY
3020 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3022 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3023 return less<_P1>()(nullptr, __x.get());
3026 template <class _T1, class _D1>
3027 inline _LIBCPP_INLINE_VISIBILITY
3029 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3031 return nullptr < __x;
3034 template <class _T1, class _D1>
3035 inline _LIBCPP_INLINE_VISIBILITY
3037 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3039 return __x < nullptr;
3042 template <class _T1, class _D1>
3043 inline _LIBCPP_INLINE_VISIBILITY
3045 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3047 return !(nullptr < __x);
3050 template <class _T1, class _D1>
3051 inline _LIBCPP_INLINE_VISIBILITY
3053 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3055 return !(__x < nullptr);
3058 template <class _T1, class _D1>
3059 inline _LIBCPP_INLINE_VISIBILITY
3061 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3063 return !(__x < nullptr);
3066 template <class _T1, class _D1>
3067 inline _LIBCPP_INLINE_VISIBILITY
3069 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3071 return !(nullptr < __x);
3074 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3076 template <class _Tp, class _Dp>
3077 inline _LIBCPP_INLINE_VISIBILITY
3078 unique_ptr<_Tp, _Dp>
3079 move(unique_ptr<_Tp, _Dp>& __t)
3081 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3086 #if _LIBCPP_STD_VER > 11
3091 typedef unique_ptr<_Tp> __unique_single;
3095 struct __unique_if<_Tp[]>
3097 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3100 template<class _Tp, size_t _Np>
3101 struct __unique_if<_Tp[_Np]>
3103 typedef void __unique_array_known_bound;
3106 template<class _Tp, class... _Args>
3107 inline _LIBCPP_INLINE_VISIBILITY
3108 typename __unique_if<_Tp>::__unique_single
3109 make_unique(_Args&&... __args)
3111 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3115 inline _LIBCPP_INLINE_VISIBILITY
3116 typename __unique_if<_Tp>::__unique_array_unknown_bound
3117 make_unique(size_t __n)
3119 typedef typename remove_extent<_Tp>::type _Up;
3120 return unique_ptr<_Tp>(new _Up[__n]());
3123 template<class _Tp, class... _Args>
3124 typename __unique_if<_Tp>::__unique_array_known_bound
3125 make_unique(_Args&&...) = delete;
3127 #endif // _LIBCPP_STD_VER > 11
3129 template <class _Tp> struct hash;
3131 template <class _Size>
3132 inline _LIBCPP_INLINE_VISIBILITY
3134 __loadword(const void* __p)
3137 std::memcpy(&__r, __p, sizeof(__r));
3141 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3142 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3143 // multiplication, which can be very slow on 32-bit systems.
3144 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3145 struct __murmur2_or_cityhash;
3147 template <class _Size>
3148 struct __murmur2_or_cityhash<_Size, 32>
3150 _Size operator()(const void* __key, _Size __len);
3154 template <class _Size>
3156 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3158 const _Size __m = 0x5bd1e995;
3159 const _Size __r = 24;
3161 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3162 for (; __len >= 4; __data += 4, __len -= 4)
3164 _Size __k = __loadword<_Size>(__data);
3174 __h ^= __data[2] << 16;
3176 __h ^= __data[1] << 8;
3187 template <class _Size>
3188 struct __murmur2_or_cityhash<_Size, 64>
3190 _Size operator()(const void* __key, _Size __len);
3193 // Some primes between 2^63 and 2^64.
3194 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3195 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3196 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3197 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3199 static _Size __rotate(_Size __val, int __shift) {
3200 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3203 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3204 return (__val >> __shift) | (__val << (64 - __shift));
3207 static _Size __shift_mix(_Size __val) {
3208 return __val ^ (__val >> 47);
3211 static _Size __hash_len_16(_Size __u, _Size __v) {
3212 const _Size __mul = 0x9ddfea08eb382d69ULL;
3213 _Size __a = (__u ^ __v) * __mul;
3215 _Size __b = (__v ^ __a) * __mul;
3221 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3223 const _Size __a = __loadword<_Size>(__s);
3224 const _Size __b = __loadword<_Size>(__s + __len - 8);
3225 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3228 const uint32_t __a = __loadword<uint32_t>(__s);
3229 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3230 return __hash_len_16(__len + (__a << 3), __b);
3233 const unsigned char __a = __s[0];
3234 const unsigned char __b = __s[__len >> 1];
3235 const unsigned char __c = __s[__len - 1];
3236 const uint32_t __y = static_cast<uint32_t>(__a) +
3237 (static_cast<uint32_t>(__b) << 8);
3238 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3239 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3244 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3245 const _Size __a = __loadword<_Size>(__s) * __k1;
3246 const _Size __b = __loadword<_Size>(__s + 8);
3247 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3248 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3249 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3250 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3253 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3254 // Callers do best to use "random-looking" values for a and b.
3255 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3256 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3258 __b = __rotate(__b + __a + __z, 21);
3259 const _Size __c = __a;
3262 __b += __rotate(__a, 44);
3263 return pair<_Size, _Size>(__a + __z, __b + __c);
3266 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3267 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3268 const char* __s, _Size __a, _Size __b) {
3269 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3270 __loadword<_Size>(__s + 8),
3271 __loadword<_Size>(__s + 16),
3272 __loadword<_Size>(__s + 24),
3277 // Return an 8-byte hash for 33 to 64 bytes.
3278 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3279 _Size __z = __loadword<_Size>(__s + 24);
3280 _Size __a = __loadword<_Size>(__s) +
3281 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3282 _Size __b = __rotate(__a + __z, 52);
3283 _Size __c = __rotate(__a, 37);
3284 __a += __loadword<_Size>(__s + 8);
3285 __c += __rotate(__a, 7);
3286 __a += __loadword<_Size>(__s + 16);
3287 _Size __vf = __a + __z;
3288 _Size __vs = __b + __rotate(__a, 31) + __c;
3289 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3290 __z += __loadword<_Size>(__s + __len - 8);
3291 __b = __rotate(__a + __z, 52);
3292 __c = __rotate(__a, 37);
3293 __a += __loadword<_Size>(__s + __len - 24);
3294 __c += __rotate(__a, 7);
3295 __a += __loadword<_Size>(__s + __len - 16);
3296 _Size __wf = __a + __z;
3297 _Size __ws = __b + __rotate(__a, 31) + __c;
3298 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3299 return __shift_mix(__r * __k0 + __vs) * __k2;
3304 template <class _Size>
3306 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3308 const char* __s = static_cast<const char*>(__key);
3311 return __hash_len_0_to_16(__s, __len);
3313 return __hash_len_17_to_32(__s, __len);
3315 } else if (__len <= 64) {
3316 return __hash_len_33_to_64(__s, __len);
3319 // For strings over 64 bytes we hash the end first, and then as we
3320 // loop we keep 56 bytes of state: v, w, x, y, and z.
3321 _Size __x = __loadword<_Size>(__s + __len - 40);
3322 _Size __y = __loadword<_Size>(__s + __len - 16) +
3323 __loadword<_Size>(__s + __len - 56);
3324 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3325 __loadword<_Size>(__s + __len - 24));
3326 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3327 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3328 __x = __x * __k1 + __loadword<_Size>(__s);
3330 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3331 __len = (__len - 1) & ~static_cast<_Size>(63);
3333 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3334 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3336 __y += __v.first + __loadword<_Size>(__s + 40);
3337 __z = __rotate(__z + __w.first, 33) * __k1;
3338 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3339 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3340 __y + __loadword<_Size>(__s + 16));
3341 std::swap(__z, __x);
3344 } while (__len != 0);
3345 return __hash_len_16(
3346 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3347 __hash_len_16(__v.second, __w.second) + __x);
3350 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3351 struct __scalar_hash;
3353 template <class _Tp>
3354 struct __scalar_hash<_Tp, 0>
3355 : public unary_function<_Tp, size_t>
3357 _LIBCPP_INLINE_VISIBILITY
3358 size_t operator()(_Tp __v) const _NOEXCEPT
3371 template <class _Tp>
3372 struct __scalar_hash<_Tp, 1>
3373 : public unary_function<_Tp, size_t>
3375 _LIBCPP_INLINE_VISIBILITY
3376 size_t operator()(_Tp __v) const _NOEXCEPT
3388 template <class _Tp>
3389 struct __scalar_hash<_Tp, 2>
3390 : public unary_function<_Tp, size_t>
3392 _LIBCPP_INLINE_VISIBILITY
3393 size_t operator()(_Tp __v) const _NOEXCEPT
3405 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3409 template <class _Tp>
3410 struct __scalar_hash<_Tp, 3>
3411 : public unary_function<_Tp, size_t>
3413 _LIBCPP_INLINE_VISIBILITY
3414 size_t operator()(_Tp __v) const _NOEXCEPT
3427 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3431 template <class _Tp>
3432 struct __scalar_hash<_Tp, 4>
3433 : public unary_function<_Tp, size_t>
3435 _LIBCPP_INLINE_VISIBILITY
3436 size_t operator()(_Tp __v) const _NOEXCEPT
3450 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3455 struct _LIBCPP_TYPE_VIS hash<_Tp*>
3456 : public unary_function<_Tp*, size_t>
3458 _LIBCPP_INLINE_VISIBILITY
3459 size_t operator()(_Tp* __v) const _NOEXCEPT
3467 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3471 template <class _Tp, class _Dp>
3472 struct _LIBCPP_TYPE_VIS hash<unique_ptr<_Tp, _Dp> >
3474 typedef unique_ptr<_Tp, _Dp> argument_type;
3475 typedef size_t result_type;
3476 _LIBCPP_INLINE_VISIBILITY
3477 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3479 typedef typename argument_type::pointer pointer;
3480 return hash<pointer>()(__ptr.get());
3489 template <class _Tp>
3490 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3491 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3493 template <class _Tp>
3494 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3497 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3499 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3502 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3504 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3507 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3510 template <class _Tp>
3511 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3512 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3514 template <class _Tp>
3515 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3516 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3518 template <class _Tp>
3519 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3520 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3523 template <class _Alloc>
3524 class __allocator_destructor
3526 typedef allocator_traits<_Alloc> __alloc_traits;
3528 typedef typename __alloc_traits::pointer pointer;
3529 typedef typename __alloc_traits::size_type size_type;
3534 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3536 : __alloc_(__a), __s_(__s) {}
3537 _LIBCPP_INLINE_VISIBILITY
3538 void operator()(pointer __p) _NOEXCEPT
3539 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3542 template <class _InputIterator, class _ForwardIterator>
3544 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3546 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3547 #ifndef _LIBCPP_NO_EXCEPTIONS
3548 _ForwardIterator __s = __r;
3552 for (; __f != __l; ++__f, ++__r)
3553 ::new(&*__r) value_type(*__f);
3554 #ifndef _LIBCPP_NO_EXCEPTIONS
3558 for (; __s != __r; ++__s)
3566 template <class _InputIterator, class _Size, class _ForwardIterator>
3568 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3570 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3571 #ifndef _LIBCPP_NO_EXCEPTIONS
3572 _ForwardIterator __s = __r;
3576 for (; __n > 0; ++__f, ++__r, --__n)
3577 ::new(&*__r) value_type(*__f);
3578 #ifndef _LIBCPP_NO_EXCEPTIONS
3582 for (; __s != __r; ++__s)
3590 template <class _ForwardIterator, class _Tp>
3592 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3594 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3595 #ifndef _LIBCPP_NO_EXCEPTIONS
3596 _ForwardIterator __s = __f;
3600 for (; __f != __l; ++__f)
3601 ::new(&*__f) value_type(__x);
3602 #ifndef _LIBCPP_NO_EXCEPTIONS
3606 for (; __s != __f; ++__s)
3613 template <class _ForwardIterator, class _Size, class _Tp>
3615 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3617 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3618 #ifndef _LIBCPP_NO_EXCEPTIONS
3619 _ForwardIterator __s = __f;
3623 for (; __n > 0; ++__f, --__n)
3624 ::new(&*__f) value_type(__x);
3625 #ifndef _LIBCPP_NO_EXCEPTIONS
3629 for (; __s != __f; ++__s)
3637 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3638 : public std::exception
3641 virtual ~bad_weak_ptr() _NOEXCEPT;
3642 virtual const char* what() const _NOEXCEPT;
3645 template<class _Tp> class _LIBCPP_TYPE_VIS weak_ptr;
3647 class __shared_count
3649 __shared_count(const __shared_count&);
3650 __shared_count& operator=(const __shared_count&);
3653 long __shared_owners_;
3654 virtual ~__shared_count();
3656 virtual void __on_zero_shared() _NOEXCEPT = 0;
3659 _LIBCPP_INLINE_VISIBILITY
3660 explicit __shared_count(long __refs = 0) _NOEXCEPT
3661 : __shared_owners_(__refs) {}
3663 void __add_shared() _NOEXCEPT;
3664 bool __release_shared() _NOEXCEPT;
3665 _LIBCPP_INLINE_VISIBILITY
3666 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3669 class __shared_weak_count
3670 : private __shared_count
3672 long __shared_weak_owners_;
3675 _LIBCPP_INLINE_VISIBILITY
3676 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3677 : __shared_count(__refs),
3678 __shared_weak_owners_(__refs) {}
3680 virtual ~__shared_weak_count();
3683 void __add_shared() _NOEXCEPT;
3684 void __add_weak() _NOEXCEPT;
3685 void __release_shared() _NOEXCEPT;
3686 void __release_weak() _NOEXCEPT;
3687 _LIBCPP_INLINE_VISIBILITY
3688 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3689 __shared_weak_count* lock() _NOEXCEPT;
3691 // Define the function out only if we build static libc++ without RTTI.
3692 // Otherwise we may break clients who need to compile their projects with
3693 // -fno-rtti and yet link against a libc++.dylib compiled
3694 // without -fno-rtti.
3695 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3696 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3699 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3702 template <class _Tp, class _Dp, class _Alloc>
3703 class __shared_ptr_pointer
3704 : public __shared_weak_count
3706 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3708 _LIBCPP_INLINE_VISIBILITY
3709 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3710 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3712 #ifndef _LIBCPP_NO_RTTI
3713 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3717 virtual void __on_zero_shared() _NOEXCEPT;
3718 virtual void __on_zero_shared_weak() _NOEXCEPT;
3721 #ifndef _LIBCPP_NO_RTTI
3723 template <class _Tp, class _Dp, class _Alloc>
3725 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3727 return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3730 #endif // _LIBCPP_NO_RTTI
3732 template <class _Tp, class _Dp, class _Alloc>
3734 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3736 __data_.first().second()(__data_.first().first());
3737 __data_.first().second().~_Dp();
3740 template <class _Tp, class _Dp, class _Alloc>
3742 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3744 typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3745 __data_.second().~_Alloc();
3746 __a.deallocate(this, 1);
3749 template <class _Tp, class _Alloc>
3750 class __shared_ptr_emplace
3751 : public __shared_weak_count
3753 __compressed_pair<_Alloc, _Tp> __data_;
3755 #ifndef _LIBCPP_HAS_NO_VARIADICS
3757 _LIBCPP_INLINE_VISIBILITY
3758 __shared_ptr_emplace(_Alloc __a)
3759 : __data_(_VSTD::move(__a)) {}
3761 template <class ..._Args>
3762 _LIBCPP_INLINE_VISIBILITY
3763 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3764 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3765 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3767 #else // _LIBCPP_HAS_NO_VARIADICS
3769 _LIBCPP_INLINE_VISIBILITY
3770 __shared_ptr_emplace(_Alloc __a)
3773 template <class _A0>
3774 _LIBCPP_INLINE_VISIBILITY
3775 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3776 : __data_(__a, _Tp(__a0)) {}
3778 template <class _A0, class _A1>
3779 _LIBCPP_INLINE_VISIBILITY
3780 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3781 : __data_(__a, _Tp(__a0, __a1)) {}
3783 template <class _A0, class _A1, class _A2>
3784 _LIBCPP_INLINE_VISIBILITY
3785 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3786 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3788 #endif // _LIBCPP_HAS_NO_VARIADICS
3791 virtual void __on_zero_shared() _NOEXCEPT;
3792 virtual void __on_zero_shared_weak() _NOEXCEPT;
3794 _LIBCPP_INLINE_VISIBILITY
3795 _Tp* get() _NOEXCEPT {return &__data_.second();}
3798 template <class _Tp, class _Alloc>
3800 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3802 __data_.second().~_Tp();
3805 template <class _Tp, class _Alloc>
3807 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3809 typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3810 __data_.first().~_Alloc();
3811 __a.deallocate(this, 1);
3814 template<class _Tp> class _LIBCPP_TYPE_VIS enable_shared_from_this;
3817 class _LIBCPP_TYPE_VIS shared_ptr
3820 typedef _Tp element_type;
3822 element_type* __ptr_;
3823 __shared_weak_count* __cntrl_;
3825 struct __nat {int __for_bool_;};
3827 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3828 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3830 class = typename enable_if
3832 is_convertible<_Yp*, element_type*>::value
3835 explicit shared_ptr(_Yp* __p);
3836 template<class _Yp, class _Dp,
3837 class = typename enable_if
3839 is_convertible<_Yp*, element_type*>::value
3842 shared_ptr(_Yp* __p, _Dp __d);
3843 template<class _Yp, class _Dp, class _Alloc,
3844 class = typename enable_if
3846 is_convertible<_Yp*, element_type*>::value
3849 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3850 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3851 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3852 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3853 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3855 shared_ptr(const shared_ptr<_Yp>& __r,
3856 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3858 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3859 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3860 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3861 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3863 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3864 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3865 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3866 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3868 class = typename enable_if
3870 is_convertible<_Yp*, element_type*>::value
3873 shared_ptr(auto_ptr<_Yp>&& __r);
3876 class = typename enable_if
3878 is_convertible<_Yp*, element_type*>::value
3881 shared_ptr(auto_ptr<_Yp> __r);
3883 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3884 template <class _Yp, class _Dp,
3885 class = typename enable_if
3887 !is_array<_Yp>::value &&
3888 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3891 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3892 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3893 template <class _Yp, class _Dp,
3894 class = typename enable_if
3896 !is_array<_Yp>::value &&
3897 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3900 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3901 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3902 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3903 template <class _Yp, class _Dp,
3904 class = typename enable_if
3906 !is_array<_Yp>::value &&
3907 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3909 > shared_ptr(unique_ptr<_Yp, _Dp>,
3910 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3911 template <class _Yp, class _Dp,
3912 class = typename enable_if
3914 !is_array<_Yp>::value &&
3915 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3918 shared_ptr(unique_ptr<_Yp, _Dp>,
3919 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3920 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3924 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3928 is_convertible<_Yp*, element_type*>::value,
3931 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3932 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3933 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3937 is_convertible<_Yp*, element_type*>::value,
3940 operator=(shared_ptr<_Yp>&& __r);
3944 !is_array<_Yp>::value &&
3945 is_convertible<_Yp*, element_type*>::value,
3948 operator=(auto_ptr<_Yp>&& __r);
3949 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3953 !is_array<_Yp>::value &&
3954 is_convertible<_Yp*, element_type*>::value,
3957 operator=(auto_ptr<_Yp> __r);
3959 template <class _Yp, class _Dp>
3962 !is_array<_Yp>::value &&
3963 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3966 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3967 operator=(unique_ptr<_Yp, _Dp>&& __r);
3968 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3969 operator=(unique_ptr<_Yp, _Dp> __r);
3972 void swap(shared_ptr& __r) _NOEXCEPT;
3973 void reset() _NOEXCEPT;
3977 is_convertible<_Yp*, element_type*>::value,
3981 template<class _Yp, class _Dp>
3984 is_convertible<_Yp*, element_type*>::value,
3987 reset(_Yp* __p, _Dp __d);
3988 template<class _Yp, class _Dp, class _Alloc>
3991 is_convertible<_Yp*, element_type*>::value,
3994 reset(_Yp* __p, _Dp __d, _Alloc __a);
3996 _LIBCPP_INLINE_VISIBILITY
3997 element_type* get() const _NOEXCEPT {return __ptr_;}
3998 _LIBCPP_INLINE_VISIBILITY
3999 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4001 _LIBCPP_INLINE_VISIBILITY
4002 element_type* operator->() const _NOEXCEPT {return __ptr_;}
4003 _LIBCPP_INLINE_VISIBILITY
4004 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4005 _LIBCPP_INLINE_VISIBILITY
4006 bool unique() const _NOEXCEPT {return use_count() == 1;}
4007 _LIBCPP_INLINE_VISIBILITY
4008 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4009 template <class _Up>
4010 _LIBCPP_INLINE_VISIBILITY
4011 bool owner_before(shared_ptr<_Up> const& __p) const
4012 {return __cntrl_ < __p.__cntrl_;}
4013 template <class _Up>
4014 _LIBCPP_INLINE_VISIBILITY
4015 bool owner_before(weak_ptr<_Up> const& __p) const
4016 {return __cntrl_ < __p.__cntrl_;}
4017 _LIBCPP_INLINE_VISIBILITY
4019 __owner_equivalent(const shared_ptr& __p) const
4020 {return __cntrl_ == __p.__cntrl_;}
4022 #ifndef _LIBCPP_NO_RTTI
4023 template <class _Dp>
4024 _LIBCPP_INLINE_VISIBILITY
4025 _Dp* __get_deleter() const _NOEXCEPT
4026 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4027 #endif // _LIBCPP_NO_RTTI
4029 #ifndef _LIBCPP_HAS_NO_VARIADICS
4031 template<class ..._Args>
4034 make_shared(_Args&& ...__args);
4036 template<class _Alloc, class ..._Args>
4039 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4041 #else // _LIBCPP_HAS_NO_VARIADICS
4043 static shared_ptr<_Tp> make_shared();
4046 static shared_ptr<_Tp> make_shared(_A0&);
4048 template<class _A0, class _A1>
4049 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4051 template<class _A0, class _A1, class _A2>
4052 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4054 template<class _Alloc>
4055 static shared_ptr<_Tp>
4056 allocate_shared(const _Alloc& __a);
4058 template<class _Alloc, class _A0>
4059 static shared_ptr<_Tp>
4060 allocate_shared(const _Alloc& __a, _A0& __a0);
4062 template<class _Alloc, class _A0, class _A1>
4063 static shared_ptr<_Tp>
4064 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4066 template<class _Alloc, class _A0, class _A1, class _A2>
4067 static shared_ptr<_Tp>
4068 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4070 #endif // _LIBCPP_HAS_NO_VARIADICS
4074 template <class _Yp>
4075 _LIBCPP_INLINE_VISIBILITY
4077 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4080 __e->__weak_this_ = *this;
4083 _LIBCPP_INLINE_VISIBILITY
4084 void __enable_weak_this(const void*) _NOEXCEPT {}
4086 template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
4087 template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
4091 inline _LIBCPP_INLINE_VISIBILITY
4093 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4100 inline _LIBCPP_INLINE_VISIBILITY
4102 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4109 template<class _Yp, class>
4110 shared_ptr<_Tp>::shared_ptr(_Yp* __p)
4113 unique_ptr<_Yp> __hold(__p);
4114 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4115 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4117 __enable_weak_this(__p);
4121 template<class _Yp, class _Dp, class>
4122 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4125 #ifndef _LIBCPP_NO_EXCEPTIONS
4128 #endif // _LIBCPP_NO_EXCEPTIONS
4129 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4130 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4131 __enable_weak_this(__p);
4132 #ifndef _LIBCPP_NO_EXCEPTIONS
4139 #endif // _LIBCPP_NO_EXCEPTIONS
4144 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4147 #ifndef _LIBCPP_NO_EXCEPTIONS
4150 #endif // _LIBCPP_NO_EXCEPTIONS
4151 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4152 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4153 #ifndef _LIBCPP_NO_EXCEPTIONS
4160 #endif // _LIBCPP_NO_EXCEPTIONS
4164 template<class _Yp, class _Dp, class _Alloc, class>
4165 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4168 #ifndef _LIBCPP_NO_EXCEPTIONS
4171 #endif // _LIBCPP_NO_EXCEPTIONS
4172 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4173 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4174 typedef __allocator_destructor<_A2> _D2;
4176 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4177 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4178 __cntrl_ = __hold2.release();
4179 __enable_weak_this(__p);
4180 #ifndef _LIBCPP_NO_EXCEPTIONS
4187 #endif // _LIBCPP_NO_EXCEPTIONS
4191 template<class _Dp, class _Alloc>
4192 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4195 #ifndef _LIBCPP_NO_EXCEPTIONS
4198 #endif // _LIBCPP_NO_EXCEPTIONS
4199 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4200 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4201 typedef __allocator_destructor<_A2> _D2;
4203 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4204 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4205 __cntrl_ = __hold2.release();
4206 #ifndef _LIBCPP_NO_EXCEPTIONS
4213 #endif // _LIBCPP_NO_EXCEPTIONS
4218 inline _LIBCPP_INLINE_VISIBILITY
4219 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4221 __cntrl_(__r.__cntrl_)
4224 __cntrl_->__add_shared();
4228 inline _LIBCPP_INLINE_VISIBILITY
4229 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4230 : __ptr_(__r.__ptr_),
4231 __cntrl_(__r.__cntrl_)
4234 __cntrl_->__add_shared();
4239 inline _LIBCPP_INLINE_VISIBILITY
4240 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4241 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4243 : __ptr_(__r.__ptr_),
4244 __cntrl_(__r.__cntrl_)
4247 __cntrl_->__add_shared();
4250 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4253 inline _LIBCPP_INLINE_VISIBILITY
4254 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4255 : __ptr_(__r.__ptr_),
4256 __cntrl_(__r.__cntrl_)
4264 inline _LIBCPP_INLINE_VISIBILITY
4265 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4266 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4268 : __ptr_(__r.__ptr_),
4269 __cntrl_(__r.__cntrl_)
4275 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4278 template<class _Yp, class>
4279 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4280 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4282 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4286 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4287 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4288 __enable_weak_this(__r.get());
4293 template <class _Yp, class _Dp, class>
4294 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4295 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4297 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4299 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4302 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4303 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4304 __enable_weak_this(__r.get());
4309 template <class _Yp, class _Dp, class>
4310 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4311 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4313 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4315 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4318 typedef __shared_ptr_pointer<_Yp*,
4319 reference_wrapper<typename remove_reference<_Dp>::type>,
4320 allocator<_Yp> > _CntrlBlk;
4321 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4322 __enable_weak_this(__r.get());
4326 #ifndef _LIBCPP_HAS_NO_VARIADICS
4329 template<class ..._Args>
4331 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4333 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4334 typedef allocator<_CntrlBlk> _A2;
4335 typedef __allocator_destructor<_A2> _D2;
4337 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4338 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4339 shared_ptr<_Tp> __r;
4340 __r.__ptr_ = __hold2.get()->get();
4341 __r.__cntrl_ = __hold2.release();
4342 __r.__enable_weak_this(__r.__ptr_);
4347 template<class _Alloc, class ..._Args>
4349 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4351 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4352 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4353 typedef __allocator_destructor<_A2> _D2;
4355 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4356 ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4357 shared_ptr<_Tp> __r;
4358 __r.__ptr_ = __hold2.get()->get();
4359 __r.__cntrl_ = __hold2.release();
4360 __r.__enable_weak_this(__r.__ptr_);
4364 #else // _LIBCPP_HAS_NO_VARIADICS
4368 shared_ptr<_Tp>::make_shared()
4370 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4371 typedef allocator<_CntrlBlk> _Alloc2;
4372 typedef __allocator_destructor<_Alloc2> _D2;
4374 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4375 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4376 shared_ptr<_Tp> __r;
4377 __r.__ptr_ = __hold2.get()->get();
4378 __r.__cntrl_ = __hold2.release();
4379 __r.__enable_weak_this(__r.__ptr_);
4386 shared_ptr<_Tp>::make_shared(_A0& __a0)
4388 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4389 typedef allocator<_CntrlBlk> _Alloc2;
4390 typedef __allocator_destructor<_Alloc2> _D2;
4392 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4393 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4394 shared_ptr<_Tp> __r;
4395 __r.__ptr_ = __hold2.get()->get();
4396 __r.__cntrl_ = __hold2.release();
4397 __r.__enable_weak_this(__r.__ptr_);
4402 template<class _A0, class _A1>
4404 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4406 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4407 typedef allocator<_CntrlBlk> _Alloc2;
4408 typedef __allocator_destructor<_Alloc2> _D2;
4410 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4411 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4412 shared_ptr<_Tp> __r;
4413 __r.__ptr_ = __hold2.get()->get();
4414 __r.__cntrl_ = __hold2.release();
4415 __r.__enable_weak_this(__r.__ptr_);
4420 template<class _A0, class _A1, class _A2>
4422 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4424 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4425 typedef allocator<_CntrlBlk> _Alloc2;
4426 typedef __allocator_destructor<_Alloc2> _D2;
4428 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4429 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4430 shared_ptr<_Tp> __r;
4431 __r.__ptr_ = __hold2.get()->get();
4432 __r.__cntrl_ = __hold2.release();
4433 __r.__enable_weak_this(__r.__ptr_);
4438 template<class _Alloc>
4440 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4442 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4443 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4444 typedef __allocator_destructor<_Alloc2> _D2;
4445 _Alloc2 __alloc2(__a);
4446 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4447 ::new(__hold2.get()) _CntrlBlk(__a);
4448 shared_ptr<_Tp> __r;
4449 __r.__ptr_ = __hold2.get()->get();
4450 __r.__cntrl_ = __hold2.release();
4451 __r.__enable_weak_this(__r.__ptr_);
4456 template<class _Alloc, class _A0>
4458 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4460 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4461 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4462 typedef __allocator_destructor<_Alloc2> _D2;
4463 _Alloc2 __alloc2(__a);
4464 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4465 ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4466 shared_ptr<_Tp> __r;
4467 __r.__ptr_ = __hold2.get()->get();
4468 __r.__cntrl_ = __hold2.release();
4469 __r.__enable_weak_this(__r.__ptr_);
4474 template<class _Alloc, class _A0, class _A1>
4476 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4478 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4479 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4480 typedef __allocator_destructor<_Alloc2> _D2;
4481 _Alloc2 __alloc2(__a);
4482 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4483 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4484 shared_ptr<_Tp> __r;
4485 __r.__ptr_ = __hold2.get()->get();
4486 __r.__cntrl_ = __hold2.release();
4487 __r.__enable_weak_this(__r.__ptr_);
4492 template<class _Alloc, class _A0, class _A1, class _A2>
4494 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4496 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4497 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4498 typedef __allocator_destructor<_Alloc2> _D2;
4499 _Alloc2 __alloc2(__a);
4500 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4501 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4502 shared_ptr<_Tp> __r;
4503 __r.__ptr_ = __hold2.get()->get();
4504 __r.__cntrl_ = __hold2.release();
4505 __r.__enable_weak_this(__r.__ptr_);
4509 #endif // _LIBCPP_HAS_NO_VARIADICS
4512 shared_ptr<_Tp>::~shared_ptr()
4515 __cntrl_->__release_shared();
4519 inline _LIBCPP_INLINE_VISIBILITY
4521 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4523 shared_ptr(__r).swap(*this);
4529 inline _LIBCPP_INLINE_VISIBILITY
4532 is_convertible<_Yp*, _Tp*>::value,
4535 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4537 shared_ptr(__r).swap(*this);
4541 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4544 inline _LIBCPP_INLINE_VISIBILITY
4546 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4548 shared_ptr(_VSTD::move(__r)).swap(*this);
4554 inline _LIBCPP_INLINE_VISIBILITY
4557 is_convertible<_Yp*, _Tp*>::value,
4560 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4562 shared_ptr(_VSTD::move(__r)).swap(*this);
4568 inline _LIBCPP_INLINE_VISIBILITY
4571 !is_array<_Yp>::value &&
4572 is_convertible<_Yp*, _Tp*>::value,
4575 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4577 shared_ptr(_VSTD::move(__r)).swap(*this);
4582 template <class _Yp, class _Dp>
4583 inline _LIBCPP_INLINE_VISIBILITY
4586 !is_array<_Yp>::value &&
4587 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4590 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4592 shared_ptr(_VSTD::move(__r)).swap(*this);
4596 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4600 inline _LIBCPP_INLINE_VISIBILITY
4603 !is_array<_Yp>::value &&
4604 is_convertible<_Yp*, _Tp*>::value,
4607 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4609 shared_ptr(__r).swap(*this);
4614 template <class _Yp, class _Dp>
4615 inline _LIBCPP_INLINE_VISIBILITY
4618 !is_array<_Yp>::value &&
4619 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4622 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4624 shared_ptr(_VSTD::move(__r)).swap(*this);
4628 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4631 inline _LIBCPP_INLINE_VISIBILITY
4633 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4635 _VSTD::swap(__ptr_, __r.__ptr_);
4636 _VSTD::swap(__cntrl_, __r.__cntrl_);
4640 inline _LIBCPP_INLINE_VISIBILITY
4642 shared_ptr<_Tp>::reset() _NOEXCEPT
4644 shared_ptr().swap(*this);
4649 inline _LIBCPP_INLINE_VISIBILITY
4652 is_convertible<_Yp*, _Tp*>::value,
4655 shared_ptr<_Tp>::reset(_Yp* __p)
4657 shared_ptr(__p).swap(*this);
4661 template<class _Yp, class _Dp>
4662 inline _LIBCPP_INLINE_VISIBILITY
4665 is_convertible<_Yp*, _Tp*>::value,
4668 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4670 shared_ptr(__p, __d).swap(*this);
4674 template<class _Yp, class _Dp, class _Alloc>
4675 inline _LIBCPP_INLINE_VISIBILITY
4678 is_convertible<_Yp*, _Tp*>::value,
4681 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4683 shared_ptr(__p, __d, __a).swap(*this);
4686 #ifndef _LIBCPP_HAS_NO_VARIADICS
4688 template<class _Tp, class ..._Args>
4689 inline _LIBCPP_INLINE_VISIBILITY
4692 !is_array<_Tp>::value,
4695 make_shared(_Args&& ...__args)
4697 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4700 template<class _Tp, class _Alloc, class ..._Args>
4701 inline _LIBCPP_INLINE_VISIBILITY
4704 !is_array<_Tp>::value,
4707 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4709 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4712 #else // _LIBCPP_HAS_NO_VARIADICS
4715 inline _LIBCPP_INLINE_VISIBILITY
4719 return shared_ptr<_Tp>::make_shared();
4722 template<class _Tp, class _A0>
4723 inline _LIBCPP_INLINE_VISIBILITY
4725 make_shared(_A0& __a0)
4727 return shared_ptr<_Tp>::make_shared(__a0);
4730 template<class _Tp, class _A0, class _A1>
4731 inline _LIBCPP_INLINE_VISIBILITY
4733 make_shared(_A0& __a0, _A1& __a1)
4735 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4738 template<class _Tp, class _A0, class _A1, class _A2>
4739 inline _LIBCPP_INLINE_VISIBILITY
4741 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4743 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4746 template<class _Tp, class _Alloc>
4747 inline _LIBCPP_INLINE_VISIBILITY
4749 allocate_shared(const _Alloc& __a)
4751 return shared_ptr<_Tp>::allocate_shared(__a);
4754 template<class _Tp, class _Alloc, class _A0>
4755 inline _LIBCPP_INLINE_VISIBILITY
4757 allocate_shared(const _Alloc& __a, _A0& __a0)
4759 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4762 template<class _Tp, class _Alloc, class _A0, class _A1>
4763 inline _LIBCPP_INLINE_VISIBILITY
4765 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4767 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4770 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4771 inline _LIBCPP_INLINE_VISIBILITY
4773 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4775 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4778 #endif // _LIBCPP_HAS_NO_VARIADICS
4780 template<class _Tp, class _Up>
4781 inline _LIBCPP_INLINE_VISIBILITY
4783 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4785 return __x.get() == __y.get();
4788 template<class _Tp, class _Up>
4789 inline _LIBCPP_INLINE_VISIBILITY
4791 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4793 return !(__x == __y);
4796 template<class _Tp, class _Up>
4797 inline _LIBCPP_INLINE_VISIBILITY
4799 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4801 typedef typename common_type<_Tp*, _Up*>::type _V;
4802 return less<_V>()(__x.get(), __y.get());
4805 template<class _Tp, class _Up>
4806 inline _LIBCPP_INLINE_VISIBILITY
4808 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4813 template<class _Tp, class _Up>
4814 inline _LIBCPP_INLINE_VISIBILITY
4816 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4818 return !(__y < __x);
4821 template<class _Tp, class _Up>
4822 inline _LIBCPP_INLINE_VISIBILITY
4824 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4826 return !(__x < __y);
4830 inline _LIBCPP_INLINE_VISIBILITY
4832 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4838 inline _LIBCPP_INLINE_VISIBILITY
4840 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4846 inline _LIBCPP_INLINE_VISIBILITY
4848 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4850 return static_cast<bool>(__x);
4854 inline _LIBCPP_INLINE_VISIBILITY
4856 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4858 return static_cast<bool>(__x);
4862 inline _LIBCPP_INLINE_VISIBILITY
4864 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4866 return less<_Tp*>()(__x.get(), nullptr);
4870 inline _LIBCPP_INLINE_VISIBILITY
4872 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4874 return less<_Tp*>()(nullptr, __x.get());
4878 inline _LIBCPP_INLINE_VISIBILITY
4880 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4882 return nullptr < __x;
4886 inline _LIBCPP_INLINE_VISIBILITY
4888 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4890 return __x < nullptr;
4894 inline _LIBCPP_INLINE_VISIBILITY
4896 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4898 return !(nullptr < __x);
4902 inline _LIBCPP_INLINE_VISIBILITY
4904 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4906 return !(__x < nullptr);
4910 inline _LIBCPP_INLINE_VISIBILITY
4912 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4914 return !(__x < nullptr);
4918 inline _LIBCPP_INLINE_VISIBILITY
4920 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4922 return !(nullptr < __x);
4926 inline _LIBCPP_INLINE_VISIBILITY
4928 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4933 template<class _Tp, class _Up>
4934 inline _LIBCPP_INLINE_VISIBILITY
4937 !is_array<_Tp>::value && !is_array<_Up>::value,
4940 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4942 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4945 template<class _Tp, class _Up>
4946 inline _LIBCPP_INLINE_VISIBILITY
4949 !is_array<_Tp>::value && !is_array<_Up>::value,
4952 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4954 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4955 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4958 template<class _Tp, class _Up>
4961 is_array<_Tp>::value == is_array<_Up>::value,
4964 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4966 typedef typename remove_extent<_Tp>::type _RTp;
4967 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4970 #ifndef _LIBCPP_NO_RTTI
4972 template<class _Dp, class _Tp>
4973 inline _LIBCPP_INLINE_VISIBILITY
4975 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4977 return __p.template __get_deleter<_Dp>();
4980 #endif // _LIBCPP_NO_RTTI
4983 class _LIBCPP_TYPE_VIS weak_ptr
4986 typedef _Tp element_type;
4988 element_type* __ptr_;
4989 __shared_weak_count* __cntrl_;
4992 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4993 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4994 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4996 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4997 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4998 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5001 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5002 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5003 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
5004 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5006 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5009 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5013 is_convertible<_Yp*, element_type*>::value,
5016 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5018 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5020 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5024 is_convertible<_Yp*, element_type*>::value,
5027 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5029 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5034 is_convertible<_Yp*, element_type*>::value,
5037 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5039 void swap(weak_ptr& __r) _NOEXCEPT;
5040 void reset() _NOEXCEPT;
5042 _LIBCPP_INLINE_VISIBILITY
5043 long use_count() const _NOEXCEPT
5044 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5045 _LIBCPP_INLINE_VISIBILITY
5046 bool expired() const _NOEXCEPT
5047 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5048 shared_ptr<_Tp> lock() const _NOEXCEPT;
5050 _LIBCPP_INLINE_VISIBILITY
5051 bool owner_before(const shared_ptr<_Up>& __r) const
5052 {return __cntrl_ < __r.__cntrl_;}
5054 _LIBCPP_INLINE_VISIBILITY
5055 bool owner_before(const weak_ptr<_Up>& __r) const
5056 {return __cntrl_ < __r.__cntrl_;}
5058 template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
5059 template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
5063 inline _LIBCPP_INLINE_VISIBILITY
5065 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5072 inline _LIBCPP_INLINE_VISIBILITY
5073 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5074 : __ptr_(__r.__ptr_),
5075 __cntrl_(__r.__cntrl_)
5078 __cntrl_->__add_weak();
5083 inline _LIBCPP_INLINE_VISIBILITY
5084 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5085 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5087 : __ptr_(__r.__ptr_),
5088 __cntrl_(__r.__cntrl_)
5091 __cntrl_->__add_weak();
5096 inline _LIBCPP_INLINE_VISIBILITY
5097 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5098 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5100 : __ptr_(__r.__ptr_),
5101 __cntrl_(__r.__cntrl_)
5104 __cntrl_->__add_weak();
5107 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5110 inline _LIBCPP_INLINE_VISIBILITY
5111 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5112 : __ptr_(__r.__ptr_),
5113 __cntrl_(__r.__cntrl_)
5121 inline _LIBCPP_INLINE_VISIBILITY
5122 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5123 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5125 : __ptr_(__r.__ptr_),
5126 __cntrl_(__r.__cntrl_)
5132 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5135 weak_ptr<_Tp>::~weak_ptr()
5138 __cntrl_->__release_weak();
5142 inline _LIBCPP_INLINE_VISIBILITY
5144 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5146 weak_ptr(__r).swap(*this);
5152 inline _LIBCPP_INLINE_VISIBILITY
5155 is_convertible<_Yp*, _Tp*>::value,
5158 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5160 weak_ptr(__r).swap(*this);
5164 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5167 inline _LIBCPP_INLINE_VISIBILITY
5169 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5171 weak_ptr(_VSTD::move(__r)).swap(*this);
5177 inline _LIBCPP_INLINE_VISIBILITY
5180 is_convertible<_Yp*, _Tp*>::value,
5183 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5185 weak_ptr(_VSTD::move(__r)).swap(*this);
5189 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5193 inline _LIBCPP_INLINE_VISIBILITY
5196 is_convertible<_Yp*, _Tp*>::value,
5199 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5201 weak_ptr(__r).swap(*this);
5206 inline _LIBCPP_INLINE_VISIBILITY
5208 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5210 _VSTD::swap(__ptr_, __r.__ptr_);
5211 _VSTD::swap(__cntrl_, __r.__cntrl_);
5215 inline _LIBCPP_INLINE_VISIBILITY
5217 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5223 inline _LIBCPP_INLINE_VISIBILITY
5225 weak_ptr<_Tp>::reset() _NOEXCEPT
5227 weak_ptr().swap(*this);
5232 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5233 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5234 : __ptr_(__r.__ptr_),
5235 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5238 #ifndef _LIBCPP_NO_EXCEPTIONS
5239 throw bad_weak_ptr();
5241 assert(!"bad_weak_ptr");
5247 weak_ptr<_Tp>::lock() const _NOEXCEPT
5249 shared_ptr<_Tp> __r;
5250 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5252 __r.__ptr_ = __ptr_;
5256 template <class _Tp> struct owner_less;
5258 template <class _Tp>
5259 struct _LIBCPP_TYPE_VIS owner_less<shared_ptr<_Tp> >
5260 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5262 typedef bool result_type;
5263 _LIBCPP_INLINE_VISIBILITY
5264 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5265 {return __x.owner_before(__y);}
5266 _LIBCPP_INLINE_VISIBILITY
5267 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5268 {return __x.owner_before(__y);}
5269 _LIBCPP_INLINE_VISIBILITY
5270 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5271 {return __x.owner_before(__y);}
5274 template <class _Tp>
5275 struct _LIBCPP_TYPE_VIS owner_less<weak_ptr<_Tp> >
5276 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5278 typedef bool result_type;
5279 _LIBCPP_INLINE_VISIBILITY
5280 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5281 {return __x.owner_before(__y);}
5282 _LIBCPP_INLINE_VISIBILITY
5283 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5284 {return __x.owner_before(__y);}
5285 _LIBCPP_INLINE_VISIBILITY
5286 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5287 {return __x.owner_before(__y);}
5291 class _LIBCPP_TYPE_VIS enable_shared_from_this
5293 mutable weak_ptr<_Tp> __weak_this_;
5295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5296 enable_shared_from_this() _NOEXCEPT {}
5297 _LIBCPP_INLINE_VISIBILITY
5298 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5299 _LIBCPP_INLINE_VISIBILITY
5300 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5302 _LIBCPP_INLINE_VISIBILITY
5303 ~enable_shared_from_this() {}
5305 _LIBCPP_INLINE_VISIBILITY
5306 shared_ptr<_Tp> shared_from_this()
5307 {return shared_ptr<_Tp>(__weak_this_);}
5308 _LIBCPP_INLINE_VISIBILITY
5309 shared_ptr<_Tp const> shared_from_this() const
5310 {return shared_ptr<const _Tp>(__weak_this_);}
5312 template <class _Up> friend class shared_ptr;
5315 template <class _Tp>
5316 struct _LIBCPP_TYPE_VIS hash<shared_ptr<_Tp> >
5318 typedef shared_ptr<_Tp> argument_type;
5319 typedef size_t result_type;
5320 _LIBCPP_INLINE_VISIBILITY
5321 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5323 return hash<_Tp*>()(__ptr.get());
5327 template<class _CharT, class _Traits, class _Yp>
5328 inline _LIBCPP_INLINE_VISIBILITY
5329 basic_ostream<_CharT, _Traits>&
5330 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5332 #if __has_feature(cxx_atomic)
5338 void lock() _NOEXCEPT;
5339 void unlock() _NOEXCEPT;
5342 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5343 __sp_mut(const __sp_mut&);
5344 __sp_mut& operator=(const __sp_mut&);
5346 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5349 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5351 template <class _Tp>
5352 inline _LIBCPP_INLINE_VISIBILITY
5354 atomic_is_lock_free(const shared_ptr<_Tp>*)
5359 template <class _Tp>
5361 atomic_load(const shared_ptr<_Tp>* __p)
5363 __sp_mut& __m = __get_sp_mut(__p);
5365 shared_ptr<_Tp> __q = *__p;
5370 template <class _Tp>
5371 inline _LIBCPP_INLINE_VISIBILITY
5373 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5375 return atomic_load(__p);
5378 template <class _Tp>
5380 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5382 __sp_mut& __m = __get_sp_mut(__p);
5388 template <class _Tp>
5389 inline _LIBCPP_INLINE_VISIBILITY
5391 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5393 atomic_store(__p, __r);
5396 template <class _Tp>
5398 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5400 __sp_mut& __m = __get_sp_mut(__p);
5407 template <class _Tp>
5408 inline _LIBCPP_INLINE_VISIBILITY
5410 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5412 return atomic_exchange(__p, __r);
5415 template <class _Tp>
5417 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5419 __sp_mut& __m = __get_sp_mut(__p);
5421 if (__p->__owner_equivalent(*__v))
5432 template <class _Tp>
5433 inline _LIBCPP_INLINE_VISIBILITY
5435 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5437 return atomic_compare_exchange_strong(__p, __v, __w);
5440 template <class _Tp>
5441 inline _LIBCPP_INLINE_VISIBILITY
5443 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5444 shared_ptr<_Tp> __w, memory_order, memory_order)
5446 return atomic_compare_exchange_strong(__p, __v, __w);
5449 template <class _Tp>
5450 inline _LIBCPP_INLINE_VISIBILITY
5452 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5453 shared_ptr<_Tp> __w, memory_order, memory_order)
5455 return atomic_compare_exchange_weak(__p, __v, __w);
5458 #endif // __has_feature(cxx_atomic)
5461 struct _LIBCPP_TYPE_VIS pointer_safety
5472 _LIBCPP_INLINE_VISIBILITY
5473 pointer_safety(__lx __v) : __v_(__v) {}
5474 _LIBCPP_INLINE_VISIBILITY
5475 operator int() const {return __v_;}
5478 void declare_reachable(void* __p);
5479 void declare_no_pointers(char* __p, size_t __n);
5480 void undeclare_no_pointers(char* __p, size_t __n);
5481 pointer_safety get_pointer_safety() _NOEXCEPT;
5482 void* __undeclare_reachable(void* __p);
5484 template <class _Tp>
5485 inline _LIBCPP_INLINE_VISIBILITY
5487 undeclare_reachable(_Tp* __p)
5489 return static_cast<_Tp*>(__undeclare_reachable(__p));
5492 void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5494 _LIBCPP_END_NAMESPACE_STD
5496 #endif // _LIBCPP_MEMORY