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); // noexcept in C++14
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) const;
500 template<class U> bool owner_before(weak_ptr<U> const& b) const;
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
621 // addressof moved to <__functional_base>
623 template <class _Tp> class allocator;
626 class _LIBCPP_TYPE_VIS_ONLY allocator<void>
629 typedef void* pointer;
630 typedef const void* const_pointer;
631 typedef void value_type;
633 template <class _Up> struct rebind {typedef allocator<_Up> other;};
637 class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
640 typedef const void* pointer;
641 typedef const void* const_pointer;
642 typedef const void value_type;
644 template <class _Up> struct rebind {typedef allocator<_Up> other;};
650 struct __has_element_type
653 struct __two {char __lx; char __lxx;};
654 template <class _Up> static __two __test(...);
655 template <class _Up> static char __test(typename _Up::element_type* = 0);
657 static const bool value = sizeof(__test<_Tp>(0)) == 1;
660 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
661 struct __pointer_traits_element_type;
663 template <class _Ptr>
664 struct __pointer_traits_element_type<_Ptr, true>
666 typedef typename _Ptr::element_type type;
669 #ifndef _LIBCPP_HAS_NO_VARIADICS
671 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
672 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
674 typedef typename _Sp<_Tp, _Args...>::element_type type;
677 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
678 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
683 #else // _LIBCPP_HAS_NO_VARIADICS
685 template <template <class> class _Sp, class _Tp>
686 struct __pointer_traits_element_type<_Sp<_Tp>, true>
688 typedef typename _Sp<_Tp>::element_type type;
691 template <template <class> class _Sp, class _Tp>
692 struct __pointer_traits_element_type<_Sp<_Tp>, false>
697 template <template <class, class> class _Sp, class _Tp, class _A0>
698 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
700 typedef typename _Sp<_Tp, _A0>::element_type type;
703 template <template <class, class> class _Sp, class _Tp, class _A0>
704 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
709 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
710 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
712 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
715 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
716 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
721 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
722 class _A1, class _A2>
723 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
725 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
728 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
729 class _A1, class _A2>
730 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
735 #endif // _LIBCPP_HAS_NO_VARIADICS
738 struct __has_difference_type
741 struct __two {char __lx; char __lxx;};
742 template <class _Up> static __two __test(...);
743 template <class _Up> static char __test(typename _Up::difference_type* = 0);
745 static const bool value = sizeof(__test<_Tp>(0)) == 1;
748 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
749 struct __pointer_traits_difference_type
751 typedef ptrdiff_t type;
754 template <class _Ptr>
755 struct __pointer_traits_difference_type<_Ptr, true>
757 typedef typename _Ptr::difference_type type;
760 template <class _Tp, class _Up>
764 struct __two {char __lx; char __lxx;};
765 template <class _Xp> static __two __test(...);
766 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
768 static const bool value = sizeof(__test<_Tp>(0)) == 1;
771 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
772 struct __pointer_traits_rebind
774 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
775 typedef typename _Tp::template rebind<_Up> type;
777 typedef typename _Tp::template rebind<_Up>::other type;
781 #ifndef _LIBCPP_HAS_NO_VARIADICS
783 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
784 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
786 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
787 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
789 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
793 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
794 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
796 typedef _Sp<_Up, _Args...> type;
799 #else // _LIBCPP_HAS_NO_VARIADICS
801 template <template <class> class _Sp, class _Tp, class _Up>
802 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
804 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
805 typedef typename _Sp<_Tp>::template rebind<_Up> type;
807 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
811 template <template <class> class _Sp, class _Tp, class _Up>
812 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
814 typedef _Sp<_Up> type;
817 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
818 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
820 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
821 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
823 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
827 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
828 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
830 typedef _Sp<_Up, _A0> type;
833 template <template <class, class, class> class _Sp, class _Tp, class _A0,
834 class _A1, class _Up>
835 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
837 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
838 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
840 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
844 template <template <class, class, class> class _Sp, class _Tp, class _A0,
845 class _A1, class _Up>
846 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
848 typedef _Sp<_Up, _A0, _A1> type;
851 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
852 class _A1, class _A2, class _Up>
853 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
855 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
856 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
858 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
862 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
863 class _A1, class _A2, class _Up>
864 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
866 typedef _Sp<_Up, _A0, _A1, _A2> type;
869 #endif // _LIBCPP_HAS_NO_VARIADICS
871 template <class _Ptr>
872 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
874 typedef _Ptr pointer;
875 typedef typename __pointer_traits_element_type<pointer>::type element_type;
876 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
878 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
879 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
881 template <class _Up> struct rebind
882 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
883 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
888 _LIBCPP_INLINE_VISIBILITY
889 static pointer pointer_to(typename conditional<is_void<element_type>::value,
890 __nat, element_type>::type& __r)
891 {return pointer::pointer_to(__r);}
895 struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
897 typedef _Tp* pointer;
898 typedef _Tp element_type;
899 typedef ptrdiff_t difference_type;
901 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
902 template <class _Up> using rebind = _Up*;
904 template <class _Up> struct rebind {typedef _Up* other;};
910 _LIBCPP_INLINE_VISIBILITY
911 static pointer pointer_to(typename conditional<is_void<element_type>::value,
912 __nat, element_type>::type& __r) _NOEXCEPT
913 {return _VSTD::addressof(__r);}
918 namespace __has_pointer_type_imp
920 template <class _Up> static __two __test(...);
921 template <class _Up> static char __test(typename _Up::pointer* = 0);
925 struct __has_pointer_type
926 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
930 namespace __pointer_type_imp
933 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
934 struct __pointer_type
936 typedef typename _Dp::pointer type;
939 template <class _Tp, class _Dp>
940 struct __pointer_type<_Tp, _Dp, false>
945 } // __pointer_type_imp
947 template <class _Tp, class _Dp>
948 struct __pointer_type
950 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
954 struct __has_const_pointer
957 struct __two {char __lx; char __lxx;};
958 template <class _Up> static __two __test(...);
959 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
961 static const bool value = sizeof(__test<_Tp>(0)) == 1;
964 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
965 struct __const_pointer
967 typedef typename _Alloc::const_pointer type;
970 template <class _Tp, class _Ptr, class _Alloc>
971 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
973 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
974 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
976 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
981 struct __has_void_pointer
984 struct __two {char __lx; char __lxx;};
985 template <class _Up> static __two __test(...);
986 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
988 static const bool value = sizeof(__test<_Tp>(0)) == 1;
991 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
992 struct __void_pointer
994 typedef typename _Alloc::void_pointer type;
997 template <class _Ptr, class _Alloc>
998 struct __void_pointer<_Ptr, _Alloc, false>
1000 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1001 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1003 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1007 template <class _Tp>
1008 struct __has_const_void_pointer
1011 struct __two {char __lx; char __lxx;};
1012 template <class _Up> static __two __test(...);
1013 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1015 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1018 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1019 struct __const_void_pointer
1021 typedef typename _Alloc::const_void_pointer type;
1024 template <class _Ptr, class _Alloc>
1025 struct __const_void_pointer<_Ptr, _Alloc, false>
1027 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1028 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1030 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1034 template <class _Tp>
1035 inline _LIBCPP_INLINE_VISIBILITY
1037 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1042 template <class _Pointer>
1043 inline _LIBCPP_INLINE_VISIBILITY
1044 typename pointer_traits<_Pointer>::element_type*
1045 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1047 return _VSTD::__to_raw_pointer(__p.operator->());
1050 template <class _Tp>
1051 struct __has_size_type
1054 struct __two {char __lx; char __lxx;};
1055 template <class _Up> static __two __test(...);
1056 template <class _Up> static char __test(typename _Up::size_type* = 0);
1058 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1061 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1064 typedef typename make_unsigned<_DiffType>::type type;
1067 template <class _Alloc, class _DiffType>
1068 struct __size_type<_Alloc, _DiffType, true>
1070 typedef typename _Alloc::size_type type;
1073 template <class _Tp>
1074 struct __has_propagate_on_container_copy_assignment
1077 struct __two {char __lx; char __lxx;};
1078 template <class _Up> static __two __test(...);
1079 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1081 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1084 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1085 struct __propagate_on_container_copy_assignment
1087 typedef false_type type;
1090 template <class _Alloc>
1091 struct __propagate_on_container_copy_assignment<_Alloc, true>
1093 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1096 template <class _Tp>
1097 struct __has_propagate_on_container_move_assignment
1100 struct __two {char __lx; char __lxx;};
1101 template <class _Up> static __two __test(...);
1102 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1104 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1107 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1108 struct __propagate_on_container_move_assignment
1110 typedef false_type type;
1113 template <class _Alloc>
1114 struct __propagate_on_container_move_assignment<_Alloc, true>
1116 typedef typename _Alloc::propagate_on_container_move_assignment type;
1119 template <class _Tp>
1120 struct __has_propagate_on_container_swap
1123 struct __two {char __lx; char __lxx;};
1124 template <class _Up> static __two __test(...);
1125 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1127 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1130 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1131 struct __propagate_on_container_swap
1133 typedef false_type type;
1136 template <class _Alloc>
1137 struct __propagate_on_container_swap<_Alloc, true>
1139 typedef typename _Alloc::propagate_on_container_swap type;
1142 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1143 struct __has_rebind_other
1146 struct __two {char __lx; char __lxx;};
1147 template <class _Xp> static __two __test(...);
1148 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1150 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1153 template <class _Tp, class _Up>
1154 struct __has_rebind_other<_Tp, _Up, false>
1156 static const bool value = false;
1159 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1160 struct __allocator_traits_rebind
1162 typedef typename _Tp::template rebind<_Up>::other type;
1165 #ifndef _LIBCPP_HAS_NO_VARIADICS
1167 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1168 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1170 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1173 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1174 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1176 typedef _Alloc<_Up, _Args...> type;
1179 #else // _LIBCPP_HAS_NO_VARIADICS
1181 template <template <class> class _Alloc, class _Tp, class _Up>
1182 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1184 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1187 template <template <class> class _Alloc, class _Tp, class _Up>
1188 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1190 typedef _Alloc<_Up> type;
1193 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1194 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1196 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1199 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1200 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1202 typedef _Alloc<_Up, _A0> type;
1205 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1206 class _A1, class _Up>
1207 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1209 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1212 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1213 class _A1, class _Up>
1214 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1216 typedef _Alloc<_Up, _A0, _A1> type;
1219 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1220 class _A1, class _A2, class _Up>
1221 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1223 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1226 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1227 class _A1, class _A2, class _Up>
1228 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1230 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1233 #endif // _LIBCPP_HAS_NO_VARIADICS
1235 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1237 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1239 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1240 -> decltype(__a.allocate(__sz, __p), true_type());
1242 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1244 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1247 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1248 struct __has_allocate_hint
1249 : integral_constant<bool,
1251 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1252 declval<_SizeType>(),
1253 declval<_ConstVoidPtr>())),
1258 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1260 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1261 struct __has_allocate_hint
1266 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1268 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1270 template <class _Alloc, class _Tp, class ..._Args>
1271 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1272 _VSTD::declval<_Args>()...),
1274 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1276 template <class _Alloc, class _Pointer, class ..._Args>
1278 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1280 template <class _Alloc, class _Pointer, class ..._Args>
1281 struct __has_construct
1282 : integral_constant<bool,
1284 decltype(__has_construct_test(declval<_Alloc>(),
1285 declval<_Pointer>(),
1286 declval<_Args>()...)),
1291 template <class _Alloc, class _Pointer>
1293 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1294 -> decltype(__a.destroy(__p), true_type());
1296 template <class _Alloc, class _Pointer>
1298 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1301 template <class _Alloc, class _Pointer>
1302 struct __has_destroy
1303 : integral_constant<bool,
1305 decltype(__has_destroy_test(declval<_Alloc>(),
1306 declval<_Pointer>())),
1311 template <class _Alloc>
1313 __has_max_size_test(_Alloc&& __a)
1314 -> decltype(__a.max_size(), true_type());
1316 template <class _Alloc>
1318 __has_max_size_test(const volatile _Alloc& __a)
1321 template <class _Alloc>
1322 struct __has_max_size
1323 : integral_constant<bool,
1325 decltype(__has_max_size_test(declval<_Alloc&>())),
1330 template <class _Alloc>
1332 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1333 -> decltype(__a.select_on_container_copy_construction(), true_type());
1335 template <class _Alloc>
1337 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1340 template <class _Alloc>
1341 struct __has_select_on_container_copy_construction
1342 : integral_constant<bool,
1344 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1349 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1351 #ifndef _LIBCPP_HAS_NO_VARIADICS
1353 template <class _Alloc, class _Pointer, class ..._Args>
1354 struct __has_construct
1359 #else // _LIBCPP_HAS_NO_VARIADICS
1361 template <class _Alloc, class _Pointer, class _Args>
1362 struct __has_construct
1367 #endif // _LIBCPP_HAS_NO_VARIADICS
1369 template <class _Alloc, class _Pointer>
1370 struct __has_destroy
1375 template <class _Alloc>
1376 struct __has_max_size
1381 template <class _Alloc>
1382 struct __has_select_on_container_copy_construction
1387 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1389 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1390 struct __alloc_traits_difference_type
1392 typedef typename pointer_traits<_Ptr>::difference_type type;
1395 template <class _Alloc, class _Ptr>
1396 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1398 typedef typename _Alloc::difference_type type;
1401 template <class _Alloc>
1402 struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
1404 typedef _Alloc allocator_type;
1405 typedef typename allocator_type::value_type value_type;
1407 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1408 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1409 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1410 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1412 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1413 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1415 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1416 propagate_on_container_copy_assignment;
1417 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1418 propagate_on_container_move_assignment;
1419 typedef typename __propagate_on_container_swap<allocator_type>::type
1420 propagate_on_container_swap;
1422 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1423 template <class _Tp> using rebind_alloc =
1424 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1425 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1426 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1427 template <class _Tp> struct rebind_alloc
1428 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1429 template <class _Tp> struct rebind_traits
1430 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1431 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1433 _LIBCPP_INLINE_VISIBILITY
1434 static pointer allocate(allocator_type& __a, size_type __n)
1435 {return __a.allocate(__n);}
1436 _LIBCPP_INLINE_VISIBILITY
1437 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1438 {return allocate(__a, __n, __hint,
1439 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1441 _LIBCPP_INLINE_VISIBILITY
1442 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1443 {__a.deallocate(__p, __n);}
1445 #ifndef _LIBCPP_HAS_NO_VARIADICS
1446 template <class _Tp, class... _Args>
1447 _LIBCPP_INLINE_VISIBILITY
1448 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1449 {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1450 __a, __p, _VSTD::forward<_Args>(__args)...);}
1451 #else // _LIBCPP_HAS_NO_VARIADICS
1452 template <class _Tp>
1453 _LIBCPP_INLINE_VISIBILITY
1454 static void construct(allocator_type& __a, _Tp* __p)
1456 ::new ((void*)__p) _Tp();
1458 template <class _Tp, class _A0>
1459 _LIBCPP_INLINE_VISIBILITY
1460 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1462 ::new ((void*)__p) _Tp(__a0);
1464 template <class _Tp, class _A0, class _A1>
1465 _LIBCPP_INLINE_VISIBILITY
1466 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1469 ::new ((void*)__p) _Tp(__a0, __a1);
1471 template <class _Tp, class _A0, class _A1, class _A2>
1472 _LIBCPP_INLINE_VISIBILITY
1473 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1474 const _A1& __a1, const _A2& __a2)
1476 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1478 #endif // _LIBCPP_HAS_NO_VARIADICS
1480 template <class _Tp>
1481 _LIBCPP_INLINE_VISIBILITY
1482 static void destroy(allocator_type& __a, _Tp* __p)
1483 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1485 _LIBCPP_INLINE_VISIBILITY
1486 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1487 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1489 _LIBCPP_INLINE_VISIBILITY
1490 static allocator_type
1491 select_on_container_copy_construction(const allocator_type& __a)
1492 {return select_on_container_copy_construction(
1493 __has_select_on_container_copy_construction<const allocator_type>(),
1496 template <class _Ptr>
1497 _LIBCPP_INLINE_VISIBILITY
1500 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1502 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1503 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1506 template <class _Tp>
1507 _LIBCPP_INLINE_VISIBILITY
1511 (is_same<allocator_type, allocator<_Tp> >::value
1512 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1513 is_trivially_move_constructible<_Tp>::value,
1516 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1518 ptrdiff_t _Np = __end1 - __begin1;
1519 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1523 template <class _Ptr>
1524 _LIBCPP_INLINE_VISIBILITY
1527 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1529 while (__end1 != __begin1)
1531 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1536 template <class _Tp>
1537 _LIBCPP_INLINE_VISIBILITY
1541 (is_same<allocator_type, allocator<_Tp> >::value
1542 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1543 is_trivially_move_constructible<_Tp>::value,
1546 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1548 ptrdiff_t _Np = __end1 - __begin1;
1550 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1555 _LIBCPP_INLINE_VISIBILITY
1556 static pointer allocate(allocator_type& __a, size_type __n,
1557 const_void_pointer __hint, true_type)
1558 {return __a.allocate(__n, __hint);}
1559 _LIBCPP_INLINE_VISIBILITY
1560 static pointer allocate(allocator_type& __a, size_type __n,
1561 const_void_pointer, false_type)
1562 {return __a.allocate(__n);}
1564 #ifndef _LIBCPP_HAS_NO_VARIADICS
1565 template <class _Tp, class... _Args>
1566 _LIBCPP_INLINE_VISIBILITY
1567 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1568 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1569 template <class _Tp, class... _Args>
1570 _LIBCPP_INLINE_VISIBILITY
1571 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1573 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1575 #endif // _LIBCPP_HAS_NO_VARIADICS
1577 template <class _Tp>
1578 _LIBCPP_INLINE_VISIBILITY
1579 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1581 template <class _Tp>
1582 _LIBCPP_INLINE_VISIBILITY
1583 static void __destroy(false_type, allocator_type&, _Tp* __p)
1588 _LIBCPP_INLINE_VISIBILITY
1589 static size_type __max_size(true_type, const allocator_type& __a)
1590 {return __a.max_size();}
1591 _LIBCPP_INLINE_VISIBILITY
1592 static size_type __max_size(false_type, const allocator_type&)
1593 {return numeric_limits<size_type>::max();}
1595 _LIBCPP_INLINE_VISIBILITY
1596 static allocator_type
1597 select_on_container_copy_construction(true_type, const allocator_type& __a)
1598 {return __a.select_on_container_copy_construction();}
1599 _LIBCPP_INLINE_VISIBILITY
1600 static allocator_type
1601 select_on_container_copy_construction(false_type, const allocator_type& __a)
1607 template <class _Tp>
1608 class _LIBCPP_TYPE_VIS_ONLY allocator
1611 typedef size_t size_type;
1612 typedef ptrdiff_t difference_type;
1613 typedef _Tp* pointer;
1614 typedef const _Tp* const_pointer;
1615 typedef _Tp& reference;
1616 typedef const _Tp& const_reference;
1617 typedef _Tp value_type;
1619 typedef true_type propagate_on_container_move_assignment;
1621 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1623 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1624 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1625 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1626 {return _VSTD::addressof(__x);}
1627 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1628 {return _VSTD::addressof(__x);}
1629 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1630 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1631 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1632 {::operator delete((void*)__p);}
1633 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1634 {return size_type(~0) / sizeof(_Tp);}
1635 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1636 template <class _Up, class... _Args>
1637 _LIBCPP_INLINE_VISIBILITY
1639 construct(_Up* __p, _Args&&... __args)
1641 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1643 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1644 _LIBCPP_INLINE_VISIBILITY
1646 construct(pointer __p)
1648 ::new((void*)__p) _Tp();
1650 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1652 template <class _A0>
1653 _LIBCPP_INLINE_VISIBILITY
1655 construct(pointer __p, _A0& __a0)
1657 ::new((void*)__p) _Tp(__a0);
1659 template <class _A0>
1660 _LIBCPP_INLINE_VISIBILITY
1662 construct(pointer __p, const _A0& __a0)
1664 ::new((void*)__p) _Tp(__a0);
1666 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1667 template <class _A0, class _A1>
1668 _LIBCPP_INLINE_VISIBILITY
1670 construct(pointer __p, _A0& __a0, _A1& __a1)
1672 ::new((void*)__p) _Tp(__a0, __a1);
1674 template <class _A0, class _A1>
1675 _LIBCPP_INLINE_VISIBILITY
1677 construct(pointer __p, const _A0& __a0, _A1& __a1)
1679 ::new((void*)__p) _Tp(__a0, __a1);
1681 template <class _A0, class _A1>
1682 _LIBCPP_INLINE_VISIBILITY
1684 construct(pointer __p, _A0& __a0, const _A1& __a1)
1686 ::new((void*)__p) _Tp(__a0, __a1);
1688 template <class _A0, class _A1>
1689 _LIBCPP_INLINE_VISIBILITY
1691 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1693 ::new((void*)__p) _Tp(__a0, __a1);
1695 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1696 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1699 template <class _Tp>
1700 class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1703 typedef size_t size_type;
1704 typedef ptrdiff_t difference_type;
1705 typedef const _Tp* pointer;
1706 typedef const _Tp* const_pointer;
1707 typedef const _Tp& reference;
1708 typedef const _Tp& const_reference;
1709 typedef const _Tp value_type;
1711 typedef true_type propagate_on_container_move_assignment;
1713 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1715 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1716 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1717 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1718 {return _VSTD::addressof(__x);}
1719 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1720 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1721 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1722 {::operator delete((void*)__p);}
1723 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1724 {return size_type(~0) / sizeof(_Tp);}
1725 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1726 template <class _Up, class... _Args>
1727 _LIBCPP_INLINE_VISIBILITY
1729 construct(_Up* __p, _Args&&... __args)
1731 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1733 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1734 _LIBCPP_INLINE_VISIBILITY
1736 construct(pointer __p)
1738 ::new((void*)__p) _Tp();
1740 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1742 template <class _A0>
1743 _LIBCPP_INLINE_VISIBILITY
1745 construct(pointer __p, _A0& __a0)
1747 ::new((void*)__p) _Tp(__a0);
1749 template <class _A0>
1750 _LIBCPP_INLINE_VISIBILITY
1752 construct(pointer __p, const _A0& __a0)
1754 ::new((void*)__p) _Tp(__a0);
1756 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1757 template <class _A0, class _A1>
1758 _LIBCPP_INLINE_VISIBILITY
1760 construct(pointer __p, _A0& __a0, _A1& __a1)
1762 ::new((void*)__p) _Tp(__a0, __a1);
1764 template <class _A0, class _A1>
1765 _LIBCPP_INLINE_VISIBILITY
1767 construct(pointer __p, const _A0& __a0, _A1& __a1)
1769 ::new((void*)__p) _Tp(__a0, __a1);
1771 template <class _A0, class _A1>
1772 _LIBCPP_INLINE_VISIBILITY
1774 construct(pointer __p, _A0& __a0, const _A1& __a1)
1776 ::new((void*)__p) _Tp(__a0, __a1);
1778 template <class _A0, class _A1>
1779 _LIBCPP_INLINE_VISIBILITY
1781 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1783 ::new((void*)__p) _Tp(__a0, __a1);
1785 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1786 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1789 template <class _Tp, class _Up>
1790 inline _LIBCPP_INLINE_VISIBILITY
1791 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1793 template <class _Tp, class _Up>
1794 inline _LIBCPP_INLINE_VISIBILITY
1795 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1797 template <class _OutputIterator, class _Tp>
1798 class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
1799 : public iterator<output_iterator_tag,
1800 _Tp, // purposefully not C++03
1801 ptrdiff_t, // purposefully not C++03
1802 _Tp*, // purposefully not C++03
1803 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1806 _OutputIterator __x_;
1808 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1809 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1810 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1811 {::new(&*__x_) _Tp(__element); return *this;}
1812 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1813 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1814 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1817 template <class _Tp>
1818 pair<_Tp*, ptrdiff_t>
1819 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1821 pair<_Tp*, ptrdiff_t> __r(0, 0);
1822 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1823 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1829 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1840 template <class _Tp>
1841 inline _LIBCPP_INLINE_VISIBILITY
1842 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1844 template <class _Tp>
1851 class _LIBCPP_TYPE_VIS_ONLY auto_ptr
1856 typedef _Tp element_type;
1858 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1859 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1860 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1861 : __ptr_(__p.release()) {}
1862 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1863 {reset(__p.release()); return *this;}
1864 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1865 {reset(__p.release()); return *this;}
1866 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1867 {reset(__p.__ptr_); return *this;}
1868 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1870 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1872 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1873 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1874 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1880 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1887 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1888 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1889 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1890 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1891 {return auto_ptr<_Up>(release());}
1895 class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
1898 typedef void element_type;
1901 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1902 typename remove_cv<_T2>::type>::value,
1903 bool = is_empty<_T1>::value
1904 #if __has_feature(is_final)
1908 bool = is_empty<_T2>::value
1909 #if __has_feature(is_final)
1913 struct __libcpp_compressed_pair_switch;
1915 template <class _T1, class _T2, bool IsSame>
1916 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1918 template <class _T1, class _T2, bool IsSame>
1919 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1921 template <class _T1, class _T2, bool IsSame>
1922 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1924 template <class _T1, class _T2>
1925 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1927 template <class _T1, class _T2>
1928 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1930 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1931 class __libcpp_compressed_pair_imp;
1933 template <class _T1, class _T2>
1934 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1940 typedef _T1 _T1_param;
1941 typedef _T2 _T2_param;
1943 typedef typename remove_reference<_T1>::type& _T1_reference;
1944 typedef typename remove_reference<_T2>::type& _T2_reference;
1946 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1947 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1949 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1950 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1951 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1952 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
1953 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
1954 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
1955 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
1957 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1959 _LIBCPP_INLINE_VISIBILITY
1960 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
1961 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
1962 is_nothrow_copy_constructible<_T2>::value)
1963 : __first_(__p.first()),
1964 __second_(__p.second()) {}
1966 _LIBCPP_INLINE_VISIBILITY
1967 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
1968 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
1969 is_nothrow_copy_assignable<_T2>::value)
1971 __first_ = __p.first();
1972 __second_ = __p.second();
1976 _LIBCPP_INLINE_VISIBILITY
1977 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
1978 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
1979 is_nothrow_move_constructible<_T2>::value)
1980 : __first_(_VSTD::forward<_T1>(__p.first())),
1981 __second_(_VSTD::forward<_T2>(__p.second())) {}
1983 _LIBCPP_INLINE_VISIBILITY
1984 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
1985 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
1986 is_nothrow_move_assignable<_T2>::value)
1988 __first_ = _VSTD::forward<_T1>(__p.first());
1989 __second_ = _VSTD::forward<_T2>(__p.second());
1993 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1995 #ifndef _LIBCPP_HAS_NO_VARIADICS
1997 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
1998 _LIBCPP_INLINE_VISIBILITY
1999 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2000 tuple<_Args1...> __first_args,
2001 tuple<_Args2...> __second_args,
2002 __tuple_indices<_I1...>,
2003 __tuple_indices<_I2...>)
2004 : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2005 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2008 #endif // _LIBCPP_HAS_NO_VARIADICS
2010 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2011 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2013 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2014 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2016 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2017 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2018 __is_nothrow_swappable<_T1>::value)
2021 swap(__first_, __x.__first_);
2022 swap(__second_, __x.__second_);
2026 template <class _T1, class _T2>
2027 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2033 typedef _T1 _T1_param;
2034 typedef _T2 _T2_param;
2036 typedef _T1& _T1_reference;
2037 typedef typename remove_reference<_T2>::type& _T2_reference;
2039 typedef const _T1& _T1_const_reference;
2040 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2042 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2043 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2044 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2045 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2046 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2047 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2048 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2050 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2052 _LIBCPP_INLINE_VISIBILITY
2053 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2054 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2055 is_nothrow_copy_constructible<_T2>::value)
2056 : _T1(__p.first()), __second_(__p.second()) {}
2058 _LIBCPP_INLINE_VISIBILITY
2059 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2060 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2061 is_nothrow_copy_assignable<_T2>::value)
2063 _T1::operator=(__p.first());
2064 __second_ = __p.second();
2068 _LIBCPP_INLINE_VISIBILITY
2069 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2070 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2071 is_nothrow_move_constructible<_T2>::value)
2072 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2074 _LIBCPP_INLINE_VISIBILITY
2075 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2076 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2077 is_nothrow_move_assignable<_T2>::value)
2079 _T1::operator=(_VSTD::move(__p.first()));
2080 __second_ = _VSTD::forward<_T2>(__p.second());
2084 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2086 #ifndef _LIBCPP_HAS_NO_VARIADICS
2088 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2089 _LIBCPP_INLINE_VISIBILITY
2090 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2091 tuple<_Args1...> __first_args,
2092 tuple<_Args2...> __second_args,
2093 __tuple_indices<_I1...>,
2094 __tuple_indices<_I2...>)
2095 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2096 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2099 #endif // _LIBCPP_HAS_NO_VARIADICS
2101 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2102 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2104 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2105 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2107 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2108 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2109 __is_nothrow_swappable<_T1>::value)
2112 swap(__second_, __x.__second_);
2116 template <class _T1, class _T2>
2117 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2123 typedef _T1 _T1_param;
2124 typedef _T2 _T2_param;
2126 typedef typename remove_reference<_T1>::type& _T1_reference;
2127 typedef _T2& _T2_reference;
2129 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2130 typedef const _T2& _T2_const_reference;
2132 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2133 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2134 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2135 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2136 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2137 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2138 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2139 is_nothrow_move_constructible<_T2>::value)
2140 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2142 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2144 _LIBCPP_INLINE_VISIBILITY
2145 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2146 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2147 is_nothrow_copy_constructible<_T2>::value)
2148 : _T2(__p.second()), __first_(__p.first()) {}
2150 _LIBCPP_INLINE_VISIBILITY
2151 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2152 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2153 is_nothrow_copy_assignable<_T2>::value)
2155 _T2::operator=(__p.second());
2156 __first_ = __p.first();
2160 _LIBCPP_INLINE_VISIBILITY
2161 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2162 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2163 is_nothrow_move_constructible<_T2>::value)
2164 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2166 _LIBCPP_INLINE_VISIBILITY
2167 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2168 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2169 is_nothrow_move_assignable<_T2>::value)
2171 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2172 __first_ = _VSTD::move(__p.first());
2176 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2178 #ifndef _LIBCPP_HAS_NO_VARIADICS
2180 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2181 _LIBCPP_INLINE_VISIBILITY
2182 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2183 tuple<_Args1...> __first_args,
2184 tuple<_Args2...> __second_args,
2185 __tuple_indices<_I1...>,
2186 __tuple_indices<_I2...>)
2187 : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2188 __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2192 #endif // _LIBCPP_HAS_NO_VARIADICS
2194 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2195 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2197 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2198 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2200 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2201 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2202 __is_nothrow_swappable<_T1>::value)
2205 swap(__first_, __x.__first_);
2209 template <class _T1, class _T2>
2210 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2215 typedef _T1 _T1_param;
2216 typedef _T2 _T2_param;
2218 typedef _T1& _T1_reference;
2219 typedef _T2& _T2_reference;
2221 typedef const _T1& _T1_const_reference;
2222 typedef const _T2& _T2_const_reference;
2224 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2225 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2226 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2227 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2228 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2229 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2230 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2232 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2234 _LIBCPP_INLINE_VISIBILITY
2235 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2236 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2237 is_nothrow_copy_constructible<_T2>::value)
2238 : _T1(__p.first()), _T2(__p.second()) {}
2240 _LIBCPP_INLINE_VISIBILITY
2241 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2242 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2243 is_nothrow_copy_assignable<_T2>::value)
2245 _T1::operator=(__p.first());
2246 _T2::operator=(__p.second());
2250 _LIBCPP_INLINE_VISIBILITY
2251 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2252 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2253 is_nothrow_move_constructible<_T2>::value)
2254 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2256 _LIBCPP_INLINE_VISIBILITY
2257 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2258 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2259 is_nothrow_move_assignable<_T2>::value)
2261 _T1::operator=(_VSTD::move(__p.first()));
2262 _T2::operator=(_VSTD::move(__p.second()));
2266 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2268 #ifndef _LIBCPP_HAS_NO_VARIADICS
2270 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2271 _LIBCPP_INLINE_VISIBILITY
2272 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2273 tuple<_Args1...> __first_args,
2274 tuple<_Args2...> __second_args,
2275 __tuple_indices<_I1...>,
2276 __tuple_indices<_I2...>)
2277 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2278 _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2281 #endif // _LIBCPP_HAS_NO_VARIADICS
2283 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2284 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2286 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2287 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2289 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2290 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2291 __is_nothrow_swappable<_T1>::value)
2296 template <class _T1, class _T2>
2297 class __compressed_pair
2298 : private __libcpp_compressed_pair_imp<_T1, _T2>
2300 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2302 typedef typename base::_T1_param _T1_param;
2303 typedef typename base::_T2_param _T2_param;
2305 typedef typename base::_T1_reference _T1_reference;
2306 typedef typename base::_T2_reference _T2_reference;
2308 typedef typename base::_T1_const_reference _T1_const_reference;
2309 typedef typename base::_T2_const_reference _T2_const_reference;
2311 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2312 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2313 : base(_VSTD::forward<_T1_param>(__t1)) {}
2314 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2315 : base(_VSTD::forward<_T2_param>(__t2)) {}
2316 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2317 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2319 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2321 _LIBCPP_INLINE_VISIBILITY
2322 __compressed_pair(const __compressed_pair& __p)
2323 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2324 is_nothrow_copy_constructible<_T2>::value)
2327 _LIBCPP_INLINE_VISIBILITY
2328 __compressed_pair& operator=(const __compressed_pair& __p)
2329 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2330 is_nothrow_copy_assignable<_T2>::value)
2332 base::operator=(__p);
2336 _LIBCPP_INLINE_VISIBILITY
2337 __compressed_pair(__compressed_pair&& __p)
2338 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2339 is_nothrow_move_constructible<_T2>::value)
2340 : base(_VSTD::move(__p)) {}
2342 _LIBCPP_INLINE_VISIBILITY
2343 __compressed_pair& operator=(__compressed_pair&& __p)
2344 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2345 is_nothrow_move_assignable<_T2>::value)
2347 base::operator=(_VSTD::move(__p));
2351 #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2353 #ifndef _LIBCPP_HAS_NO_VARIADICS
2355 template <class... _Args1, class... _Args2>
2356 _LIBCPP_INLINE_VISIBILITY
2357 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2358 tuple<_Args2...> __second_args)
2359 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2360 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2361 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2364 #endif // _LIBCPP_HAS_NO_VARIADICS
2366 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2367 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2369 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2370 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2372 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2373 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2374 __is_nothrow_swappable<_T1>::value)
2378 template <class _T1, class _T2>
2379 inline _LIBCPP_INLINE_VISIBILITY
2381 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2382 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2383 __is_nothrow_swappable<_T1>::value)
2386 // __same_or_less_cv_qualified
2388 template <class _Ptr1, class _Ptr2,
2389 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2390 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2393 struct __same_or_less_cv_qualified_imp
2394 : is_convertible<_Ptr1, _Ptr2> {};
2396 template <class _Ptr1, class _Ptr2>
2397 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2400 template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2401 !is_pointer<_Ptr1>::value>
2402 struct __same_or_less_cv_qualified
2403 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2405 template <class _Ptr1, class _Ptr2>
2406 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2411 template <class _Tp>
2412 struct _LIBCPP_TYPE_VIS_ONLY default_delete
2414 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2415 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2419 template <class _Up>
2420 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2421 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2422 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2424 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2425 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2430 template <class _Tp>
2431 struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2434 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2435 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2439 template <class _Up>
2440 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2441 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2442 template <class _Up>
2443 _LIBCPP_INLINE_VISIBILITY
2444 void operator() (_Up* __ptr,
2445 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2447 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2448 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2453 template <class _Tp, class _Dp = default_delete<_Tp> >
2454 class _LIBCPP_TYPE_VIS_ONLY unique_ptr
2457 typedef _Tp element_type;
2458 typedef _Dp deleter_type;
2459 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2461 __compressed_pair<pointer, deleter_type> __ptr_;
2463 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2464 unique_ptr(unique_ptr&);
2465 template <class _Up, class _Ep>
2466 unique_ptr(unique_ptr<_Up, _Ep>&);
2467 unique_ptr& operator=(unique_ptr&);
2468 template <class _Up, class _Ep>
2469 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2470 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2472 struct __nat {int __for_bool_;};
2474 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2475 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2477 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2480 static_assert(!is_pointer<deleter_type>::value,
2481 "unique_ptr constructed with null function pointer deleter");
2483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2486 static_assert(!is_pointer<deleter_type>::value,
2487 "unique_ptr constructed with null function pointer deleter");
2489 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2490 : __ptr_(_VSTD::move(__p))
2492 static_assert(!is_pointer<deleter_type>::value,
2493 "unique_ptr constructed with null function pointer deleter");
2496 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2497 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2498 is_reference<deleter_type>::value,
2500 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2502 : __ptr_(__p, __d) {}
2504 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2506 : __ptr_(__p, _VSTD::move(__d))
2508 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2510 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2511 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2512 template <class _Up, class _Ep>
2513 _LIBCPP_INLINE_VISIBILITY
2514 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2517 !is_array<_Up>::value &&
2518 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2519 is_convertible<_Ep, deleter_type>::value &&
2521 !is_reference<deleter_type>::value ||
2522 is_same<deleter_type, _Ep>::value
2525 >::type = __nat()) _NOEXCEPT
2526 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2528 template <class _Up>
2529 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2531 is_convertible<_Up*, _Tp*>::value &&
2532 is_same<_Dp, default_delete<_Tp> >::value,
2534 >::type = __nat()) _NOEXCEPT
2535 : __ptr_(__p.release())
2539 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2541 reset(__u.release());
2542 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2546 template <class _Up, class _Ep>
2547 _LIBCPP_INLINE_VISIBILITY
2550 !is_array<_Up>::value &&
2551 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2552 is_assignable<deleter_type&, _Ep&&>::value,
2555 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2557 reset(__u.release());
2558 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2561 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2563 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2565 return __rv<unique_ptr>(*this);
2568 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2569 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2571 template <class _Up, class _Ep>
2572 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2574 reset(__u.release());
2575 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2579 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2580 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2582 template <class _Up>
2583 _LIBCPP_INLINE_VISIBILITY
2585 is_convertible<_Up*, _Tp*>::value &&
2586 is_same<_Dp, default_delete<_Tp> >::value,
2589 operator=(auto_ptr<_Up> __p)
2590 {reset(__p.release()); return *this;}
2592 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2593 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2595 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2601 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2602 {return *__ptr_.first();}
2603 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2604 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2605 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2606 {return __ptr_.second();}
2607 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2608 {return __ptr_.second();}
2609 _LIBCPP_INLINE_VISIBILITY
2610 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2611 {return __ptr_.first() != nullptr;}
2613 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2615 pointer __t = __ptr_.first();
2616 __ptr_.first() = pointer();
2620 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2622 pointer __tmp = __ptr_.first();
2623 __ptr_.first() = __p;
2625 __ptr_.second()(__tmp);
2628 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2629 {__ptr_.swap(__u.__ptr_);}
2632 template <class _Tp, class _Dp>
2633 class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
2636 typedef _Tp element_type;
2637 typedef _Dp deleter_type;
2638 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2640 __compressed_pair<pointer, deleter_type> __ptr_;
2642 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2643 unique_ptr(unique_ptr&);
2644 template <class _Up>
2645 unique_ptr(unique_ptr<_Up>&);
2646 unique_ptr& operator=(unique_ptr&);
2647 template <class _Up>
2648 unique_ptr& operator=(unique_ptr<_Up>&);
2649 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2651 struct __nat {int __for_bool_;};
2653 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2654 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2659 static_assert(!is_pointer<deleter_type>::value,
2660 "unique_ptr constructed with null function pointer deleter");
2662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2665 static_assert(!is_pointer<deleter_type>::value,
2666 "unique_ptr constructed with null function pointer deleter");
2668 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2669 template <class _Pp,
2670 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2672 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2675 static_assert(!is_pointer<deleter_type>::value,
2676 "unique_ptr constructed with null function pointer deleter");
2679 template <class _Pp,
2680 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2682 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2683 is_reference<deleter_type>::value,
2685 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2687 : __ptr_(__p, __d) {}
2689 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2690 is_reference<deleter_type>::value,
2692 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2694 : __ptr_(pointer(), __d) {}
2696 template <class _Pp,
2697 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2699 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2701 : __ptr_(__p, _VSTD::move(__d))
2703 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2706 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2708 : __ptr_(pointer(), _VSTD::move(__d))
2710 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2713 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2714 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2716 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2718 reset(__u.release());
2719 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2723 template <class _Up, class _Ep>
2724 _LIBCPP_INLINE_VISIBILITY
2725 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2728 is_array<_Up>::value &&
2729 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2730 && is_convertible<_Ep, deleter_type>::value &&
2732 !is_reference<deleter_type>::value ||
2733 is_same<deleter_type, _Ep>::value
2738 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2741 template <class _Up, class _Ep>
2742 _LIBCPP_INLINE_VISIBILITY
2745 is_array<_Up>::value &&
2746 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2747 is_assignable<deleter_type&, _Ep&&>::value,
2750 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2752 reset(__u.release());
2753 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2756 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2758 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2761 static_assert(!is_pointer<deleter_type>::value,
2762 "unique_ptr constructed with null function pointer deleter");
2765 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2766 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2768 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2769 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2771 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2773 return __rv<unique_ptr>(*this);
2776 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2777 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2779 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2781 reset(__u->release());
2782 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2786 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2787 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2789 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2795 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2796 {return __ptr_.first()[__i];}
2797 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2798 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2799 {return __ptr_.second();}
2800 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2801 {return __ptr_.second();}
2802 _LIBCPP_INLINE_VISIBILITY
2803 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2804 {return __ptr_.first() != nullptr;}
2806 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2808 pointer __t = __ptr_.first();
2809 __ptr_.first() = pointer();
2813 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2814 template <class _Pp,
2815 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2817 _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2819 pointer __tmp = __ptr_.first();
2820 __ptr_.first() = __p;
2822 __ptr_.second()(__tmp);
2824 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2826 pointer __tmp = __ptr_.first();
2827 __ptr_.first() = nullptr;
2829 __ptr_.second()(__tmp);
2831 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2833 pointer __tmp = __ptr_.first();
2834 __ptr_.first() = nullptr;
2836 __ptr_.second()(__tmp);
2838 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2839 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2841 pointer __tmp = __ptr_.first();
2842 __ptr_.first() = __p;
2844 __ptr_.second()(__tmp);
2846 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2848 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2851 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2852 template <class _Up>
2853 explicit unique_ptr(_Up);
2854 template <class _Up>
2856 typename conditional<
2857 is_reference<deleter_type>::value,
2859 typename add_lvalue_reference<const deleter_type>::type>::type,
2862 is_convertible<_Up, pointer>::value,
2865 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2868 template <class _Tp, class _Dp>
2869 inline _LIBCPP_INLINE_VISIBILITY
2871 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2873 template <class _T1, class _D1, class _T2, class _D2>
2874 inline _LIBCPP_INLINE_VISIBILITY
2876 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2878 template <class _T1, class _D1, class _T2, class _D2>
2879 inline _LIBCPP_INLINE_VISIBILITY
2881 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2883 template <class _T1, class _D1, class _T2, class _D2>
2884 inline _LIBCPP_INLINE_VISIBILITY
2886 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2888 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2889 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2890 typedef typename common_type<_P1, _P2>::type _V;
2891 return less<_V>()(__x.get(), __y.get());
2894 template <class _T1, class _D1, class _T2, class _D2>
2895 inline _LIBCPP_INLINE_VISIBILITY
2897 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2899 template <class _T1, class _D1, class _T2, class _D2>
2900 inline _LIBCPP_INLINE_VISIBILITY
2902 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2904 template <class _T1, class _D1, class _T2, class _D2>
2905 inline _LIBCPP_INLINE_VISIBILITY
2907 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2909 template <class _T1, class _D1>
2910 inline _LIBCPP_INLINE_VISIBILITY
2912 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2917 template <class _T1, class _D1>
2918 inline _LIBCPP_INLINE_VISIBILITY
2920 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2925 template <class _T1, class _D1>
2926 inline _LIBCPP_INLINE_VISIBILITY
2928 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2930 return static_cast<bool>(__x);
2933 template <class _T1, class _D1>
2934 inline _LIBCPP_INLINE_VISIBILITY
2936 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2938 return static_cast<bool>(__x);
2941 template <class _T1, class _D1>
2942 inline _LIBCPP_INLINE_VISIBILITY
2944 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2946 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2947 return less<_P1>()(__x.get(), nullptr);
2950 template <class _T1, class _D1>
2951 inline _LIBCPP_INLINE_VISIBILITY
2953 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2955 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2956 return less<_P1>()(nullptr, __x.get());
2959 template <class _T1, class _D1>
2960 inline _LIBCPP_INLINE_VISIBILITY
2962 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2964 return nullptr < __x;
2967 template <class _T1, class _D1>
2968 inline _LIBCPP_INLINE_VISIBILITY
2970 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2972 return __x < nullptr;
2975 template <class _T1, class _D1>
2976 inline _LIBCPP_INLINE_VISIBILITY
2978 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2980 return !(nullptr < __x);
2983 template <class _T1, class _D1>
2984 inline _LIBCPP_INLINE_VISIBILITY
2986 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2988 return !(__x < nullptr);
2991 template <class _T1, class _D1>
2992 inline _LIBCPP_INLINE_VISIBILITY
2994 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2996 return !(__x < nullptr);
2999 template <class _T1, class _D1>
3000 inline _LIBCPP_INLINE_VISIBILITY
3002 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3004 return !(nullptr < __x);
3007 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3009 template <class _Tp, class _Dp>
3010 inline _LIBCPP_INLINE_VISIBILITY
3011 unique_ptr<_Tp, _Dp>
3012 move(unique_ptr<_Tp, _Dp>& __t)
3014 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3019 #if _LIBCPP_STD_VER > 11
3024 typedef unique_ptr<_Tp> __unique_single;
3028 struct __unique_if<_Tp[]>
3030 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3033 template<class _Tp, size_t _Np>
3034 struct __unique_if<_Tp[_Np]>
3036 typedef void __unique_array_known_bound;
3039 template<class _Tp, class... _Args>
3040 inline _LIBCPP_INLINE_VISIBILITY
3041 typename __unique_if<_Tp>::__unique_single
3042 make_unique(_Args&&... __args)
3044 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3048 inline _LIBCPP_INLINE_VISIBILITY
3049 typename __unique_if<_Tp>::__unique_array_unknown_bound
3050 make_unique(size_t __n)
3052 typedef typename remove_extent<_Tp>::type _Up;
3053 return unique_ptr<_Tp>(new _Up[__n]());
3056 template<class _Tp, class... _Args>
3057 typename __unique_if<_Tp>::__unique_array_known_bound
3058 make_unique(_Args&&...) = delete;
3060 #endif // _LIBCPP_STD_VER > 11
3062 template <class _Tp> struct hash;
3064 template <class _Size>
3065 inline _LIBCPP_INLINE_VISIBILITY
3067 __loadword(const void* __p)
3070 std::memcpy(&__r, __p, sizeof(__r));
3074 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3075 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3076 // multiplication, which can be very slow on 32-bit systems.
3077 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3078 struct __murmur2_or_cityhash;
3080 template <class _Size>
3081 struct __murmur2_or_cityhash<_Size, 32>
3083 _Size operator()(const void* __key, _Size __len);
3087 template <class _Size>
3089 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3091 const _Size __m = 0x5bd1e995;
3092 const _Size __r = 24;
3094 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3095 for (; __len >= 4; __data += 4, __len -= 4)
3097 _Size __k = __loadword<_Size>(__data);
3107 __h ^= __data[2] << 16;
3109 __h ^= __data[1] << 8;
3120 template <class _Size>
3121 struct __murmur2_or_cityhash<_Size, 64>
3123 _Size operator()(const void* __key, _Size __len);
3126 // Some primes between 2^63 and 2^64.
3127 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3128 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3129 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3130 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3132 static _Size __rotate(_Size __val, int __shift) {
3133 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3136 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3137 return (__val >> __shift) | (__val << (64 - __shift));
3140 static _Size __shift_mix(_Size __val) {
3141 return __val ^ (__val >> 47);
3144 static _Size __hash_len_16(_Size __u, _Size __v) {
3145 const _Size __mul = 0x9ddfea08eb382d69ULL;
3146 _Size __a = (__u ^ __v) * __mul;
3148 _Size __b = (__v ^ __a) * __mul;
3154 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3156 const _Size __a = __loadword<_Size>(__s);
3157 const _Size __b = __loadword<_Size>(__s + __len - 8);
3158 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3161 const uint32_t __a = __loadword<uint32_t>(__s);
3162 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3163 return __hash_len_16(__len + (__a << 3), __b);
3166 const unsigned char __a = __s[0];
3167 const unsigned char __b = __s[__len >> 1];
3168 const unsigned char __c = __s[__len - 1];
3169 const uint32_t __y = static_cast<uint32_t>(__a) +
3170 (static_cast<uint32_t>(__b) << 8);
3171 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3172 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3177 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3178 const _Size __a = __loadword<_Size>(__s) * __k1;
3179 const _Size __b = __loadword<_Size>(__s + 8);
3180 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3181 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3182 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3183 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3186 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3187 // Callers do best to use "random-looking" values for a and b.
3188 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3189 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3191 __b = __rotate(__b + __a + __z, 21);
3192 const _Size __c = __a;
3195 __b += __rotate(__a, 44);
3196 return pair<_Size, _Size>(__a + __z, __b + __c);
3199 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3200 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3201 const char* __s, _Size __a, _Size __b) {
3202 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3203 __loadword<_Size>(__s + 8),
3204 __loadword<_Size>(__s + 16),
3205 __loadword<_Size>(__s + 24),
3210 // Return an 8-byte hash for 33 to 64 bytes.
3211 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3212 _Size __z = __loadword<_Size>(__s + 24);
3213 _Size __a = __loadword<_Size>(__s) +
3214 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3215 _Size __b = __rotate(__a + __z, 52);
3216 _Size __c = __rotate(__a, 37);
3217 __a += __loadword<_Size>(__s + 8);
3218 __c += __rotate(__a, 7);
3219 __a += __loadword<_Size>(__s + 16);
3220 _Size __vf = __a + __z;
3221 _Size __vs = __b + __rotate(__a, 31) + __c;
3222 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3223 __z += __loadword<_Size>(__s + __len - 8);
3224 __b = __rotate(__a + __z, 52);
3225 __c = __rotate(__a, 37);
3226 __a += __loadword<_Size>(__s + __len - 24);
3227 __c += __rotate(__a, 7);
3228 __a += __loadword<_Size>(__s + __len - 16);
3229 _Size __wf = __a + __z;
3230 _Size __ws = __b + __rotate(__a, 31) + __c;
3231 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3232 return __shift_mix(__r * __k0 + __vs) * __k2;
3237 template <class _Size>
3239 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3241 const char* __s = static_cast<const char*>(__key);
3244 return __hash_len_0_to_16(__s, __len);
3246 return __hash_len_17_to_32(__s, __len);
3248 } else if (__len <= 64) {
3249 return __hash_len_33_to_64(__s, __len);
3252 // For strings over 64 bytes we hash the end first, and then as we
3253 // loop we keep 56 bytes of state: v, w, x, y, and z.
3254 _Size __x = __loadword<_Size>(__s + __len - 40);
3255 _Size __y = __loadword<_Size>(__s + __len - 16) +
3256 __loadword<_Size>(__s + __len - 56);
3257 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3258 __loadword<_Size>(__s + __len - 24));
3259 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3260 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3261 __x = __x * __k1 + __loadword<_Size>(__s);
3263 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3264 __len = (__len - 1) & ~static_cast<_Size>(63);
3266 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3267 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3269 __y += __v.first + __loadword<_Size>(__s + 40);
3270 __z = __rotate(__z + __w.first, 33) * __k1;
3271 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3272 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3273 __y + __loadword<_Size>(__s + 16));
3274 std::swap(__z, __x);
3277 } while (__len != 0);
3278 return __hash_len_16(
3279 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3280 __hash_len_16(__v.second, __w.second) + __x);
3283 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3284 struct __scalar_hash;
3286 template <class _Tp>
3287 struct __scalar_hash<_Tp, 0>
3288 : public unary_function<_Tp, size_t>
3290 _LIBCPP_INLINE_VISIBILITY
3291 size_t operator()(_Tp __v) const _NOEXCEPT
3304 template <class _Tp>
3305 struct __scalar_hash<_Tp, 1>
3306 : public unary_function<_Tp, size_t>
3308 _LIBCPP_INLINE_VISIBILITY
3309 size_t operator()(_Tp __v) const _NOEXCEPT
3321 template <class _Tp>
3322 struct __scalar_hash<_Tp, 2>
3323 : public unary_function<_Tp, size_t>
3325 _LIBCPP_INLINE_VISIBILITY
3326 size_t operator()(_Tp __v) const _NOEXCEPT
3338 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3342 template <class _Tp>
3343 struct __scalar_hash<_Tp, 3>
3344 : public unary_function<_Tp, size_t>
3346 _LIBCPP_INLINE_VISIBILITY
3347 size_t operator()(_Tp __v) const _NOEXCEPT
3360 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3364 template <class _Tp>
3365 struct __scalar_hash<_Tp, 4>
3366 : public unary_function<_Tp, size_t>
3368 _LIBCPP_INLINE_VISIBILITY
3369 size_t operator()(_Tp __v) const _NOEXCEPT
3383 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3388 struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3389 : public unary_function<_Tp*, size_t>
3391 _LIBCPP_INLINE_VISIBILITY
3392 size_t operator()(_Tp* __v) const _NOEXCEPT
3400 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3404 template <class _Tp, class _Dp>
3405 struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
3407 typedef unique_ptr<_Tp, _Dp> argument_type;
3408 typedef size_t result_type;
3409 _LIBCPP_INLINE_VISIBILITY
3410 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3412 typedef typename argument_type::pointer pointer;
3413 return hash<pointer>()(__ptr.get());
3422 template <class _Tp>
3423 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3424 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3426 template <class _Tp>
3427 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3430 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3432 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3435 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3437 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3440 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3443 template <class _Tp>
3444 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3445 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3447 template <class _Tp>
3448 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3449 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3451 template <class _Tp>
3452 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3453 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3456 template <class _Alloc>
3457 class __allocator_destructor
3459 typedef allocator_traits<_Alloc> __alloc_traits;
3461 typedef typename __alloc_traits::pointer pointer;
3462 typedef typename __alloc_traits::size_type size_type;
3467 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3469 : __alloc_(__a), __s_(__s) {}
3470 _LIBCPP_INLINE_VISIBILITY
3471 void operator()(pointer __p) _NOEXCEPT
3472 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3475 template <class _InputIterator, class _ForwardIterator>
3477 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3479 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3480 #ifndef _LIBCPP_NO_EXCEPTIONS
3481 _ForwardIterator __s = __r;
3485 for (; __f != __l; ++__f, ++__r)
3486 ::new(&*__r) value_type(*__f);
3487 #ifndef _LIBCPP_NO_EXCEPTIONS
3491 for (; __s != __r; ++__s)
3499 template <class _InputIterator, class _Size, class _ForwardIterator>
3501 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3503 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3504 #ifndef _LIBCPP_NO_EXCEPTIONS
3505 _ForwardIterator __s = __r;
3509 for (; __n > 0; ++__f, ++__r, --__n)
3510 ::new(&*__r) value_type(*__f);
3511 #ifndef _LIBCPP_NO_EXCEPTIONS
3515 for (; __s != __r; ++__s)
3523 template <class _ForwardIterator, class _Tp>
3525 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3527 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3528 #ifndef _LIBCPP_NO_EXCEPTIONS
3529 _ForwardIterator __s = __f;
3533 for (; __f != __l; ++__f)
3534 ::new(&*__f) value_type(__x);
3535 #ifndef _LIBCPP_NO_EXCEPTIONS
3539 for (; __s != __f; ++__s)
3546 template <class _ForwardIterator, class _Size, class _Tp>
3548 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3550 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3551 #ifndef _LIBCPP_NO_EXCEPTIONS
3552 _ForwardIterator __s = __f;
3556 for (; __n > 0; ++__f, --__n)
3557 ::new(&*__f) value_type(__x);
3558 #ifndef _LIBCPP_NO_EXCEPTIONS
3562 for (; __s != __f; ++__s)
3570 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3571 : public std::exception
3574 virtual ~bad_weak_ptr() _NOEXCEPT;
3575 virtual const char* what() const _NOEXCEPT;
3578 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3580 class _LIBCPP_TYPE_VIS __shared_count
3582 __shared_count(const __shared_count&);
3583 __shared_count& operator=(const __shared_count&);
3586 long __shared_owners_;
3587 virtual ~__shared_count();
3589 virtual void __on_zero_shared() _NOEXCEPT = 0;
3592 _LIBCPP_INLINE_VISIBILITY
3593 explicit __shared_count(long __refs = 0) _NOEXCEPT
3594 : __shared_owners_(__refs) {}
3596 void __add_shared() _NOEXCEPT;
3597 bool __release_shared() _NOEXCEPT;
3598 _LIBCPP_INLINE_VISIBILITY
3599 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3602 class _LIBCPP_TYPE_VIS __shared_weak_count
3603 : private __shared_count
3605 long __shared_weak_owners_;
3608 _LIBCPP_INLINE_VISIBILITY
3609 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3610 : __shared_count(__refs),
3611 __shared_weak_owners_(__refs) {}
3613 virtual ~__shared_weak_count();
3616 void __add_shared() _NOEXCEPT;
3617 void __add_weak() _NOEXCEPT;
3618 void __release_shared() _NOEXCEPT;
3619 void __release_weak() _NOEXCEPT;
3620 _LIBCPP_INLINE_VISIBILITY
3621 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3622 __shared_weak_count* lock() _NOEXCEPT;
3624 // Define the function out only if we build static libc++ without RTTI.
3625 // Otherwise we may break clients who need to compile their projects with
3626 // -fno-rtti and yet link against a libc++.dylib compiled
3627 // without -fno-rtti.
3628 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3629 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3632 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3635 template <class _Tp, class _Dp, class _Alloc>
3636 class __shared_ptr_pointer
3637 : public __shared_weak_count
3639 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3641 _LIBCPP_INLINE_VISIBILITY
3642 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3643 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3645 #ifndef _LIBCPP_NO_RTTI
3646 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3650 virtual void __on_zero_shared() _NOEXCEPT;
3651 virtual void __on_zero_shared_weak() _NOEXCEPT;
3654 #ifndef _LIBCPP_NO_RTTI
3656 template <class _Tp, class _Dp, class _Alloc>
3658 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3660 return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3663 #endif // _LIBCPP_NO_RTTI
3665 template <class _Tp, class _Dp, class _Alloc>
3667 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3669 __data_.first().second()(__data_.first().first());
3670 __data_.first().second().~_Dp();
3673 template <class _Tp, class _Dp, class _Alloc>
3675 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3677 typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3678 __data_.second().~_Alloc();
3679 __a.deallocate(this, 1);
3682 template <class _Tp, class _Alloc>
3683 class __shared_ptr_emplace
3684 : public __shared_weak_count
3686 __compressed_pair<_Alloc, _Tp> __data_;
3688 #ifndef _LIBCPP_HAS_NO_VARIADICS
3690 _LIBCPP_INLINE_VISIBILITY
3691 __shared_ptr_emplace(_Alloc __a)
3692 : __data_(_VSTD::move(__a)) {}
3694 template <class ..._Args>
3695 _LIBCPP_INLINE_VISIBILITY
3696 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3697 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3698 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3700 #else // _LIBCPP_HAS_NO_VARIADICS
3702 _LIBCPP_INLINE_VISIBILITY
3703 __shared_ptr_emplace(_Alloc __a)
3706 template <class _A0>
3707 _LIBCPP_INLINE_VISIBILITY
3708 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3709 : __data_(__a, _Tp(__a0)) {}
3711 template <class _A0, class _A1>
3712 _LIBCPP_INLINE_VISIBILITY
3713 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3714 : __data_(__a, _Tp(__a0, __a1)) {}
3716 template <class _A0, class _A1, class _A2>
3717 _LIBCPP_INLINE_VISIBILITY
3718 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3719 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3721 #endif // _LIBCPP_HAS_NO_VARIADICS
3724 virtual void __on_zero_shared() _NOEXCEPT;
3725 virtual void __on_zero_shared_weak() _NOEXCEPT;
3727 _LIBCPP_INLINE_VISIBILITY
3728 _Tp* get() _NOEXCEPT {return &__data_.second();}
3731 template <class _Tp, class _Alloc>
3733 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3735 __data_.second().~_Tp();
3738 template <class _Tp, class _Alloc>
3740 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3742 typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3743 __data_.first().~_Alloc();
3744 __a.deallocate(this, 1);
3747 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3750 class _LIBCPP_TYPE_VIS_ONLY shared_ptr
3753 typedef _Tp element_type;
3755 element_type* __ptr_;
3756 __shared_weak_count* __cntrl_;
3758 struct __nat {int __for_bool_;};
3760 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3761 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3763 class = typename enable_if
3765 is_convertible<_Yp*, element_type*>::value
3768 explicit shared_ptr(_Yp* __p);
3769 template<class _Yp, class _Dp,
3770 class = typename enable_if
3772 is_convertible<_Yp*, element_type*>::value
3775 shared_ptr(_Yp* __p, _Dp __d);
3776 template<class _Yp, class _Dp, class _Alloc,
3777 class = typename enable_if
3779 is_convertible<_Yp*, element_type*>::value
3782 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3783 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3784 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3785 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3786 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3788 shared_ptr(const shared_ptr<_Yp>& __r,
3789 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3791 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3792 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3793 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3794 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3796 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3797 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3798 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3799 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3801 class = typename enable_if
3803 is_convertible<_Yp*, element_type*>::value
3806 shared_ptr(auto_ptr<_Yp>&& __r);
3809 class = typename enable_if
3811 is_convertible<_Yp*, element_type*>::value
3814 shared_ptr(auto_ptr<_Yp> __r);
3816 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3817 template <class _Yp, class _Dp,
3818 class = typename enable_if
3820 !is_array<_Yp>::value &&
3821 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3824 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3825 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3826 template <class _Yp, class _Dp,
3827 class = typename enable_if
3829 !is_array<_Yp>::value &&
3830 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3833 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3834 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3835 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3836 template <class _Yp, class _Dp,
3837 class = typename enable_if
3839 !is_array<_Yp>::value &&
3840 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3842 > shared_ptr(unique_ptr<_Yp, _Dp>,
3843 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3844 template <class _Yp, class _Dp,
3845 class = typename enable_if
3847 !is_array<_Yp>::value &&
3848 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3851 shared_ptr(unique_ptr<_Yp, _Dp>,
3852 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3853 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3857 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3861 is_convertible<_Yp*, element_type*>::value,
3864 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3865 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3866 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3870 is_convertible<_Yp*, element_type*>::value,
3873 operator=(shared_ptr<_Yp>&& __r);
3877 !is_array<_Yp>::value &&
3878 is_convertible<_Yp*, element_type*>::value,
3881 operator=(auto_ptr<_Yp>&& __r);
3882 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3886 !is_array<_Yp>::value &&
3887 is_convertible<_Yp*, element_type*>::value,
3890 operator=(auto_ptr<_Yp> __r);
3892 template <class _Yp, class _Dp>
3895 !is_array<_Yp>::value &&
3896 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3899 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3900 operator=(unique_ptr<_Yp, _Dp>&& __r);
3901 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3902 operator=(unique_ptr<_Yp, _Dp> __r);
3905 void swap(shared_ptr& __r) _NOEXCEPT;
3906 void reset() _NOEXCEPT;
3910 is_convertible<_Yp*, element_type*>::value,
3914 template<class _Yp, class _Dp>
3917 is_convertible<_Yp*, element_type*>::value,
3920 reset(_Yp* __p, _Dp __d);
3921 template<class _Yp, class _Dp, class _Alloc>
3924 is_convertible<_Yp*, element_type*>::value,
3927 reset(_Yp* __p, _Dp __d, _Alloc __a);
3929 _LIBCPP_INLINE_VISIBILITY
3930 element_type* get() const _NOEXCEPT {return __ptr_;}
3931 _LIBCPP_INLINE_VISIBILITY
3932 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3934 _LIBCPP_INLINE_VISIBILITY
3935 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3936 _LIBCPP_INLINE_VISIBILITY
3937 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3938 _LIBCPP_INLINE_VISIBILITY
3939 bool unique() const _NOEXCEPT {return use_count() == 1;}
3940 _LIBCPP_INLINE_VISIBILITY
3941 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3942 template <class _Up>
3943 _LIBCPP_INLINE_VISIBILITY
3944 bool owner_before(shared_ptr<_Up> const& __p) const
3945 {return __cntrl_ < __p.__cntrl_;}
3946 template <class _Up>
3947 _LIBCPP_INLINE_VISIBILITY
3948 bool owner_before(weak_ptr<_Up> const& __p) const
3949 {return __cntrl_ < __p.__cntrl_;}
3950 _LIBCPP_INLINE_VISIBILITY
3952 __owner_equivalent(const shared_ptr& __p) const
3953 {return __cntrl_ == __p.__cntrl_;}
3955 #ifndef _LIBCPP_NO_RTTI
3956 template <class _Dp>
3957 _LIBCPP_INLINE_VISIBILITY
3958 _Dp* __get_deleter() const _NOEXCEPT
3959 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3960 #endif // _LIBCPP_NO_RTTI
3962 #ifndef _LIBCPP_HAS_NO_VARIADICS
3964 template<class ..._Args>
3967 make_shared(_Args&& ...__args);
3969 template<class _Alloc, class ..._Args>
3972 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3974 #else // _LIBCPP_HAS_NO_VARIADICS
3976 static shared_ptr<_Tp> make_shared();
3979 static shared_ptr<_Tp> make_shared(_A0&);
3981 template<class _A0, class _A1>
3982 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3984 template<class _A0, class _A1, class _A2>
3985 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3987 template<class _Alloc>
3988 static shared_ptr<_Tp>
3989 allocate_shared(const _Alloc& __a);
3991 template<class _Alloc, class _A0>
3992 static shared_ptr<_Tp>
3993 allocate_shared(const _Alloc& __a, _A0& __a0);
3995 template<class _Alloc, class _A0, class _A1>
3996 static shared_ptr<_Tp>
3997 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3999 template<class _Alloc, class _A0, class _A1, class _A2>
4000 static shared_ptr<_Tp>
4001 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4003 #endif // _LIBCPP_HAS_NO_VARIADICS
4007 template <class _Yp>
4008 _LIBCPP_INLINE_VISIBILITY
4010 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4013 __e->__weak_this_ = *this;
4016 _LIBCPP_INLINE_VISIBILITY
4017 void __enable_weak_this(const void*) _NOEXCEPT {}
4019 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4020 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4024 inline _LIBCPP_INLINE_VISIBILITY
4026 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4033 inline _LIBCPP_INLINE_VISIBILITY
4035 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4042 template<class _Yp, class>
4043 shared_ptr<_Tp>::shared_ptr(_Yp* __p)
4046 unique_ptr<_Yp> __hold(__p);
4047 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4048 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4050 __enable_weak_this(__p);
4054 template<class _Yp, class _Dp, class>
4055 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4058 #ifndef _LIBCPP_NO_EXCEPTIONS
4061 #endif // _LIBCPP_NO_EXCEPTIONS
4062 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4063 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4064 __enable_weak_this(__p);
4065 #ifndef _LIBCPP_NO_EXCEPTIONS
4072 #endif // _LIBCPP_NO_EXCEPTIONS
4077 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4080 #ifndef _LIBCPP_NO_EXCEPTIONS
4083 #endif // _LIBCPP_NO_EXCEPTIONS
4084 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4085 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4086 #ifndef _LIBCPP_NO_EXCEPTIONS
4093 #endif // _LIBCPP_NO_EXCEPTIONS
4097 template<class _Yp, class _Dp, class _Alloc, class>
4098 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4101 #ifndef _LIBCPP_NO_EXCEPTIONS
4104 #endif // _LIBCPP_NO_EXCEPTIONS
4105 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4106 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4107 typedef __allocator_destructor<_A2> _D2;
4109 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4110 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4111 __cntrl_ = __hold2.release();
4112 __enable_weak_this(__p);
4113 #ifndef _LIBCPP_NO_EXCEPTIONS
4120 #endif // _LIBCPP_NO_EXCEPTIONS
4124 template<class _Dp, class _Alloc>
4125 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4128 #ifndef _LIBCPP_NO_EXCEPTIONS
4131 #endif // _LIBCPP_NO_EXCEPTIONS
4132 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4133 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4134 typedef __allocator_destructor<_A2> _D2;
4136 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4137 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4138 __cntrl_ = __hold2.release();
4139 #ifndef _LIBCPP_NO_EXCEPTIONS
4146 #endif // _LIBCPP_NO_EXCEPTIONS
4151 inline _LIBCPP_INLINE_VISIBILITY
4152 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4154 __cntrl_(__r.__cntrl_)
4157 __cntrl_->__add_shared();
4161 inline _LIBCPP_INLINE_VISIBILITY
4162 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4163 : __ptr_(__r.__ptr_),
4164 __cntrl_(__r.__cntrl_)
4167 __cntrl_->__add_shared();
4172 inline _LIBCPP_INLINE_VISIBILITY
4173 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4174 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4176 : __ptr_(__r.__ptr_),
4177 __cntrl_(__r.__cntrl_)
4180 __cntrl_->__add_shared();
4183 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4186 inline _LIBCPP_INLINE_VISIBILITY
4187 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4188 : __ptr_(__r.__ptr_),
4189 __cntrl_(__r.__cntrl_)
4197 inline _LIBCPP_INLINE_VISIBILITY
4198 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4199 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4201 : __ptr_(__r.__ptr_),
4202 __cntrl_(__r.__cntrl_)
4208 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4211 template<class _Yp, class>
4212 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4213 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4215 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4219 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4220 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4221 __enable_weak_this(__r.get());
4226 template <class _Yp, class _Dp, class>
4227 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4228 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4230 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4232 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4235 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4236 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4237 __enable_weak_this(__r.get());
4242 template <class _Yp, class _Dp, class>
4243 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4244 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4246 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4248 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4251 typedef __shared_ptr_pointer<_Yp*,
4252 reference_wrapper<typename remove_reference<_Dp>::type>,
4253 allocator<_Yp> > _CntrlBlk;
4254 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4255 __enable_weak_this(__r.get());
4259 #ifndef _LIBCPP_HAS_NO_VARIADICS
4262 template<class ..._Args>
4264 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4266 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4267 typedef allocator<_CntrlBlk> _A2;
4268 typedef __allocator_destructor<_A2> _D2;
4270 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4271 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4272 shared_ptr<_Tp> __r;
4273 __r.__ptr_ = __hold2.get()->get();
4274 __r.__cntrl_ = __hold2.release();
4275 __r.__enable_weak_this(__r.__ptr_);
4280 template<class _Alloc, class ..._Args>
4282 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4284 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4285 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4286 typedef __allocator_destructor<_A2> _D2;
4288 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4289 ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4290 shared_ptr<_Tp> __r;
4291 __r.__ptr_ = __hold2.get()->get();
4292 __r.__cntrl_ = __hold2.release();
4293 __r.__enable_weak_this(__r.__ptr_);
4297 #else // _LIBCPP_HAS_NO_VARIADICS
4301 shared_ptr<_Tp>::make_shared()
4303 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4304 typedef allocator<_CntrlBlk> _Alloc2;
4305 typedef __allocator_destructor<_Alloc2> _D2;
4307 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4308 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4309 shared_ptr<_Tp> __r;
4310 __r.__ptr_ = __hold2.get()->get();
4311 __r.__cntrl_ = __hold2.release();
4312 __r.__enable_weak_this(__r.__ptr_);
4319 shared_ptr<_Tp>::make_shared(_A0& __a0)
4321 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4322 typedef allocator<_CntrlBlk> _Alloc2;
4323 typedef __allocator_destructor<_Alloc2> _D2;
4325 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4326 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4327 shared_ptr<_Tp> __r;
4328 __r.__ptr_ = __hold2.get()->get();
4329 __r.__cntrl_ = __hold2.release();
4330 __r.__enable_weak_this(__r.__ptr_);
4335 template<class _A0, class _A1>
4337 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4339 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4340 typedef allocator<_CntrlBlk> _Alloc2;
4341 typedef __allocator_destructor<_Alloc2> _D2;
4343 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4344 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4345 shared_ptr<_Tp> __r;
4346 __r.__ptr_ = __hold2.get()->get();
4347 __r.__cntrl_ = __hold2.release();
4348 __r.__enable_weak_this(__r.__ptr_);
4353 template<class _A0, class _A1, class _A2>
4355 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4357 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4358 typedef allocator<_CntrlBlk> _Alloc2;
4359 typedef __allocator_destructor<_Alloc2> _D2;
4361 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4362 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4363 shared_ptr<_Tp> __r;
4364 __r.__ptr_ = __hold2.get()->get();
4365 __r.__cntrl_ = __hold2.release();
4366 __r.__enable_weak_this(__r.__ptr_);
4371 template<class _Alloc>
4373 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4375 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4376 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4377 typedef __allocator_destructor<_Alloc2> _D2;
4378 _Alloc2 __alloc2(__a);
4379 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4380 ::new(__hold2.get()) _CntrlBlk(__a);
4381 shared_ptr<_Tp> __r;
4382 __r.__ptr_ = __hold2.get()->get();
4383 __r.__cntrl_ = __hold2.release();
4384 __r.__enable_weak_this(__r.__ptr_);
4389 template<class _Alloc, class _A0>
4391 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4393 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4394 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4395 typedef __allocator_destructor<_Alloc2> _D2;
4396 _Alloc2 __alloc2(__a);
4397 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4398 ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4399 shared_ptr<_Tp> __r;
4400 __r.__ptr_ = __hold2.get()->get();
4401 __r.__cntrl_ = __hold2.release();
4402 __r.__enable_weak_this(__r.__ptr_);
4407 template<class _Alloc, class _A0, class _A1>
4409 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4411 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4412 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4413 typedef __allocator_destructor<_Alloc2> _D2;
4414 _Alloc2 __alloc2(__a);
4415 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4416 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4417 shared_ptr<_Tp> __r;
4418 __r.__ptr_ = __hold2.get()->get();
4419 __r.__cntrl_ = __hold2.release();
4420 __r.__enable_weak_this(__r.__ptr_);
4425 template<class _Alloc, class _A0, class _A1, class _A2>
4427 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4429 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4430 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4431 typedef __allocator_destructor<_Alloc2> _D2;
4432 _Alloc2 __alloc2(__a);
4433 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4434 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4435 shared_ptr<_Tp> __r;
4436 __r.__ptr_ = __hold2.get()->get();
4437 __r.__cntrl_ = __hold2.release();
4438 __r.__enable_weak_this(__r.__ptr_);
4442 #endif // _LIBCPP_HAS_NO_VARIADICS
4445 shared_ptr<_Tp>::~shared_ptr()
4448 __cntrl_->__release_shared();
4452 inline _LIBCPP_INLINE_VISIBILITY
4454 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4456 shared_ptr(__r).swap(*this);
4462 inline _LIBCPP_INLINE_VISIBILITY
4465 is_convertible<_Yp*, _Tp*>::value,
4468 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4470 shared_ptr(__r).swap(*this);
4474 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4477 inline _LIBCPP_INLINE_VISIBILITY
4479 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4481 shared_ptr(_VSTD::move(__r)).swap(*this);
4487 inline _LIBCPP_INLINE_VISIBILITY
4490 is_convertible<_Yp*, _Tp*>::value,
4493 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4495 shared_ptr(_VSTD::move(__r)).swap(*this);
4501 inline _LIBCPP_INLINE_VISIBILITY
4504 !is_array<_Yp>::value &&
4505 is_convertible<_Yp*, _Tp*>::value,
4508 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4510 shared_ptr(_VSTD::move(__r)).swap(*this);
4515 template <class _Yp, class _Dp>
4516 inline _LIBCPP_INLINE_VISIBILITY
4519 !is_array<_Yp>::value &&
4520 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4523 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4525 shared_ptr(_VSTD::move(__r)).swap(*this);
4529 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4533 inline _LIBCPP_INLINE_VISIBILITY
4536 !is_array<_Yp>::value &&
4537 is_convertible<_Yp*, _Tp*>::value,
4540 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4542 shared_ptr(__r).swap(*this);
4547 template <class _Yp, class _Dp>
4548 inline _LIBCPP_INLINE_VISIBILITY
4551 !is_array<_Yp>::value &&
4552 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4555 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4557 shared_ptr(_VSTD::move(__r)).swap(*this);
4561 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4564 inline _LIBCPP_INLINE_VISIBILITY
4566 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4568 _VSTD::swap(__ptr_, __r.__ptr_);
4569 _VSTD::swap(__cntrl_, __r.__cntrl_);
4573 inline _LIBCPP_INLINE_VISIBILITY
4575 shared_ptr<_Tp>::reset() _NOEXCEPT
4577 shared_ptr().swap(*this);
4582 inline _LIBCPP_INLINE_VISIBILITY
4585 is_convertible<_Yp*, _Tp*>::value,
4588 shared_ptr<_Tp>::reset(_Yp* __p)
4590 shared_ptr(__p).swap(*this);
4594 template<class _Yp, class _Dp>
4595 inline _LIBCPP_INLINE_VISIBILITY
4598 is_convertible<_Yp*, _Tp*>::value,
4601 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4603 shared_ptr(__p, __d).swap(*this);
4607 template<class _Yp, class _Dp, class _Alloc>
4608 inline _LIBCPP_INLINE_VISIBILITY
4611 is_convertible<_Yp*, _Tp*>::value,
4614 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4616 shared_ptr(__p, __d, __a).swap(*this);
4619 #ifndef _LIBCPP_HAS_NO_VARIADICS
4621 template<class _Tp, class ..._Args>
4622 inline _LIBCPP_INLINE_VISIBILITY
4625 !is_array<_Tp>::value,
4628 make_shared(_Args&& ...__args)
4630 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4633 template<class _Tp, class _Alloc, class ..._Args>
4634 inline _LIBCPP_INLINE_VISIBILITY
4637 !is_array<_Tp>::value,
4640 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4642 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4645 #else // _LIBCPP_HAS_NO_VARIADICS
4648 inline _LIBCPP_INLINE_VISIBILITY
4652 return shared_ptr<_Tp>::make_shared();
4655 template<class _Tp, class _A0>
4656 inline _LIBCPP_INLINE_VISIBILITY
4658 make_shared(_A0& __a0)
4660 return shared_ptr<_Tp>::make_shared(__a0);
4663 template<class _Tp, class _A0, class _A1>
4664 inline _LIBCPP_INLINE_VISIBILITY
4666 make_shared(_A0& __a0, _A1& __a1)
4668 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4671 template<class _Tp, class _A0, class _A1, class _A2>
4672 inline _LIBCPP_INLINE_VISIBILITY
4674 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4676 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4679 template<class _Tp, class _Alloc>
4680 inline _LIBCPP_INLINE_VISIBILITY
4682 allocate_shared(const _Alloc& __a)
4684 return shared_ptr<_Tp>::allocate_shared(__a);
4687 template<class _Tp, class _Alloc, class _A0>
4688 inline _LIBCPP_INLINE_VISIBILITY
4690 allocate_shared(const _Alloc& __a, _A0& __a0)
4692 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4695 template<class _Tp, class _Alloc, class _A0, class _A1>
4696 inline _LIBCPP_INLINE_VISIBILITY
4698 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4700 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4703 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4704 inline _LIBCPP_INLINE_VISIBILITY
4706 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4708 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4711 #endif // _LIBCPP_HAS_NO_VARIADICS
4713 template<class _Tp, class _Up>
4714 inline _LIBCPP_INLINE_VISIBILITY
4716 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4718 return __x.get() == __y.get();
4721 template<class _Tp, class _Up>
4722 inline _LIBCPP_INLINE_VISIBILITY
4724 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4726 return !(__x == __y);
4729 template<class _Tp, class _Up>
4730 inline _LIBCPP_INLINE_VISIBILITY
4732 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4734 typedef typename common_type<_Tp*, _Up*>::type _V;
4735 return less<_V>()(__x.get(), __y.get());
4738 template<class _Tp, class _Up>
4739 inline _LIBCPP_INLINE_VISIBILITY
4741 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4746 template<class _Tp, class _Up>
4747 inline _LIBCPP_INLINE_VISIBILITY
4749 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4751 return !(__y < __x);
4754 template<class _Tp, class _Up>
4755 inline _LIBCPP_INLINE_VISIBILITY
4757 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4759 return !(__x < __y);
4763 inline _LIBCPP_INLINE_VISIBILITY
4765 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4771 inline _LIBCPP_INLINE_VISIBILITY
4773 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4779 inline _LIBCPP_INLINE_VISIBILITY
4781 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4783 return static_cast<bool>(__x);
4787 inline _LIBCPP_INLINE_VISIBILITY
4789 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4791 return static_cast<bool>(__x);
4795 inline _LIBCPP_INLINE_VISIBILITY
4797 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4799 return less<_Tp*>()(__x.get(), nullptr);
4803 inline _LIBCPP_INLINE_VISIBILITY
4805 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4807 return less<_Tp*>()(nullptr, __x.get());
4811 inline _LIBCPP_INLINE_VISIBILITY
4813 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4815 return nullptr < __x;
4819 inline _LIBCPP_INLINE_VISIBILITY
4821 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4823 return __x < nullptr;
4827 inline _LIBCPP_INLINE_VISIBILITY
4829 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4831 return !(nullptr < __x);
4835 inline _LIBCPP_INLINE_VISIBILITY
4837 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4839 return !(__x < nullptr);
4843 inline _LIBCPP_INLINE_VISIBILITY
4845 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4847 return !(__x < nullptr);
4851 inline _LIBCPP_INLINE_VISIBILITY
4853 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4855 return !(nullptr < __x);
4859 inline _LIBCPP_INLINE_VISIBILITY
4861 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4866 template<class _Tp, class _Up>
4867 inline _LIBCPP_INLINE_VISIBILITY
4870 !is_array<_Tp>::value && !is_array<_Up>::value,
4873 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4875 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4878 template<class _Tp, class _Up>
4879 inline _LIBCPP_INLINE_VISIBILITY
4882 !is_array<_Tp>::value && !is_array<_Up>::value,
4885 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4887 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4888 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4891 template<class _Tp, class _Up>
4894 is_array<_Tp>::value == is_array<_Up>::value,
4897 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4899 typedef typename remove_extent<_Tp>::type _RTp;
4900 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4903 #ifndef _LIBCPP_NO_RTTI
4905 template<class _Dp, class _Tp>
4906 inline _LIBCPP_INLINE_VISIBILITY
4908 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4910 return __p.template __get_deleter<_Dp>();
4913 #endif // _LIBCPP_NO_RTTI
4916 class _LIBCPP_TYPE_VIS_ONLY weak_ptr
4919 typedef _Tp element_type;
4921 element_type* __ptr_;
4922 __shared_weak_count* __cntrl_;
4925 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4926 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4927 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4929 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4930 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4931 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4934 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4935 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4936 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4937 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4939 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4942 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4946 is_convertible<_Yp*, element_type*>::value,
4949 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4951 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4953 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4957 is_convertible<_Yp*, element_type*>::value,
4960 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4962 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4967 is_convertible<_Yp*, element_type*>::value,
4970 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4972 void swap(weak_ptr& __r) _NOEXCEPT;
4973 void reset() _NOEXCEPT;
4975 _LIBCPP_INLINE_VISIBILITY
4976 long use_count() const _NOEXCEPT
4977 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4978 _LIBCPP_INLINE_VISIBILITY
4979 bool expired() const _NOEXCEPT
4980 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4981 shared_ptr<_Tp> lock() const _NOEXCEPT;
4983 _LIBCPP_INLINE_VISIBILITY
4984 bool owner_before(const shared_ptr<_Up>& __r) const
4985 {return __cntrl_ < __r.__cntrl_;}
4987 _LIBCPP_INLINE_VISIBILITY
4988 bool owner_before(const weak_ptr<_Up>& __r) const
4989 {return __cntrl_ < __r.__cntrl_;}
4991 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4992 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4996 inline _LIBCPP_INLINE_VISIBILITY
4998 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5005 inline _LIBCPP_INLINE_VISIBILITY
5006 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5007 : __ptr_(__r.__ptr_),
5008 __cntrl_(__r.__cntrl_)
5011 __cntrl_->__add_weak();
5016 inline _LIBCPP_INLINE_VISIBILITY
5017 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5018 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5020 : __ptr_(__r.__ptr_),
5021 __cntrl_(__r.__cntrl_)
5024 __cntrl_->__add_weak();
5029 inline _LIBCPP_INLINE_VISIBILITY
5030 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5031 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5033 : __ptr_(__r.__ptr_),
5034 __cntrl_(__r.__cntrl_)
5037 __cntrl_->__add_weak();
5040 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5043 inline _LIBCPP_INLINE_VISIBILITY
5044 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5045 : __ptr_(__r.__ptr_),
5046 __cntrl_(__r.__cntrl_)
5054 inline _LIBCPP_INLINE_VISIBILITY
5055 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5056 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5058 : __ptr_(__r.__ptr_),
5059 __cntrl_(__r.__cntrl_)
5065 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5068 weak_ptr<_Tp>::~weak_ptr()
5071 __cntrl_->__release_weak();
5075 inline _LIBCPP_INLINE_VISIBILITY
5077 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5079 weak_ptr(__r).swap(*this);
5085 inline _LIBCPP_INLINE_VISIBILITY
5088 is_convertible<_Yp*, _Tp*>::value,
5091 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5093 weak_ptr(__r).swap(*this);
5097 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5100 inline _LIBCPP_INLINE_VISIBILITY
5102 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5104 weak_ptr(_VSTD::move(__r)).swap(*this);
5110 inline _LIBCPP_INLINE_VISIBILITY
5113 is_convertible<_Yp*, _Tp*>::value,
5116 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5118 weak_ptr(_VSTD::move(__r)).swap(*this);
5122 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5126 inline _LIBCPP_INLINE_VISIBILITY
5129 is_convertible<_Yp*, _Tp*>::value,
5132 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5134 weak_ptr(__r).swap(*this);
5139 inline _LIBCPP_INLINE_VISIBILITY
5141 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5143 _VSTD::swap(__ptr_, __r.__ptr_);
5144 _VSTD::swap(__cntrl_, __r.__cntrl_);
5148 inline _LIBCPP_INLINE_VISIBILITY
5150 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5156 inline _LIBCPP_INLINE_VISIBILITY
5158 weak_ptr<_Tp>::reset() _NOEXCEPT
5160 weak_ptr().swap(*this);
5165 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5166 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5167 : __ptr_(__r.__ptr_),
5168 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5171 #ifndef _LIBCPP_NO_EXCEPTIONS
5172 throw bad_weak_ptr();
5174 assert(!"bad_weak_ptr");
5180 weak_ptr<_Tp>::lock() const _NOEXCEPT
5182 shared_ptr<_Tp> __r;
5183 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5185 __r.__ptr_ = __ptr_;
5189 template <class _Tp> struct owner_less;
5191 template <class _Tp>
5192 struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
5193 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5195 typedef bool result_type;
5196 _LIBCPP_INLINE_VISIBILITY
5197 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5198 {return __x.owner_before(__y);}
5199 _LIBCPP_INLINE_VISIBILITY
5200 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5201 {return __x.owner_before(__y);}
5202 _LIBCPP_INLINE_VISIBILITY
5203 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5204 {return __x.owner_before(__y);}
5207 template <class _Tp>
5208 struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
5209 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5211 typedef bool result_type;
5212 _LIBCPP_INLINE_VISIBILITY
5213 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5214 {return __x.owner_before(__y);}
5215 _LIBCPP_INLINE_VISIBILITY
5216 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5217 {return __x.owner_before(__y);}
5218 _LIBCPP_INLINE_VISIBILITY
5219 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5220 {return __x.owner_before(__y);}
5224 class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5226 mutable weak_ptr<_Tp> __weak_this_;
5228 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5229 enable_shared_from_this() _NOEXCEPT {}
5230 _LIBCPP_INLINE_VISIBILITY
5231 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5232 _LIBCPP_INLINE_VISIBILITY
5233 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5235 _LIBCPP_INLINE_VISIBILITY
5236 ~enable_shared_from_this() {}
5238 _LIBCPP_INLINE_VISIBILITY
5239 shared_ptr<_Tp> shared_from_this()
5240 {return shared_ptr<_Tp>(__weak_this_);}
5241 _LIBCPP_INLINE_VISIBILITY
5242 shared_ptr<_Tp const> shared_from_this() const
5243 {return shared_ptr<const _Tp>(__weak_this_);}
5245 template <class _Up> friend class shared_ptr;
5248 template <class _Tp>
5249 struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
5251 typedef shared_ptr<_Tp> argument_type;
5252 typedef size_t result_type;
5253 _LIBCPP_INLINE_VISIBILITY
5254 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5256 return hash<_Tp*>()(__ptr.get());
5260 template<class _CharT, class _Traits, class _Yp>
5261 inline _LIBCPP_INLINE_VISIBILITY
5262 basic_ostream<_CharT, _Traits>&
5263 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5265 #if __has_feature(cxx_atomic)
5267 class _LIBCPP_TYPE_VIS __sp_mut
5271 void lock() _NOEXCEPT;
5272 void unlock() _NOEXCEPT;
5275 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5276 __sp_mut(const __sp_mut&);
5277 __sp_mut& operator=(const __sp_mut&);
5279 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5282 _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5284 template <class _Tp>
5285 inline _LIBCPP_INLINE_VISIBILITY
5287 atomic_is_lock_free(const shared_ptr<_Tp>*)
5292 template <class _Tp>
5294 atomic_load(const shared_ptr<_Tp>* __p)
5296 __sp_mut& __m = __get_sp_mut(__p);
5298 shared_ptr<_Tp> __q = *__p;
5303 template <class _Tp>
5304 inline _LIBCPP_INLINE_VISIBILITY
5306 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5308 return atomic_load(__p);
5311 template <class _Tp>
5313 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5315 __sp_mut& __m = __get_sp_mut(__p);
5321 template <class _Tp>
5322 inline _LIBCPP_INLINE_VISIBILITY
5324 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5326 atomic_store(__p, __r);
5329 template <class _Tp>
5331 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5333 __sp_mut& __m = __get_sp_mut(__p);
5340 template <class _Tp>
5341 inline _LIBCPP_INLINE_VISIBILITY
5343 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5345 return atomic_exchange(__p, __r);
5348 template <class _Tp>
5350 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5352 __sp_mut& __m = __get_sp_mut(__p);
5354 if (__p->__owner_equivalent(*__v))
5365 template <class _Tp>
5366 inline _LIBCPP_INLINE_VISIBILITY
5368 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5370 return atomic_compare_exchange_strong(__p, __v, __w);
5373 template <class _Tp>
5374 inline _LIBCPP_INLINE_VISIBILITY
5376 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5377 shared_ptr<_Tp> __w, memory_order, memory_order)
5379 return atomic_compare_exchange_strong(__p, __v, __w);
5382 template <class _Tp>
5383 inline _LIBCPP_INLINE_VISIBILITY
5385 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5386 shared_ptr<_Tp> __w, memory_order, memory_order)
5388 return atomic_compare_exchange_weak(__p, __v, __w);
5391 #endif // __has_feature(cxx_atomic)
5394 struct _LIBCPP_TYPE_VIS pointer_safety
5405 _LIBCPP_INLINE_VISIBILITY
5406 pointer_safety(__lx __v) : __v_(__v) {}
5407 _LIBCPP_INLINE_VISIBILITY
5408 operator int() const {return __v_;}
5411 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5412 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5413 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5414 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5415 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5417 template <class _Tp>
5418 inline _LIBCPP_INLINE_VISIBILITY
5420 undeclare_reachable(_Tp* __p)
5422 return static_cast<_Tp*>(__undeclare_reachable(__p));
5425 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5427 _LIBCPP_END_NAMESPACE_STD
5429 #endif // _LIBCPP_MEMORY