2 //===-------------------------- memory ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_MEMORY
12 #define _LIBCPP_MEMORY
20 struct allocator_arg_t { };
21 constexpr allocator_arg_t allocator_arg = allocator_arg_t();
23 template <class T, class Alloc> struct uses_allocator;
29 typedef <details> element_type;
30 typedef <details> difference_type;
32 template <class U> using rebind = <details>;
34 static pointer pointer_to(<details>);
38 struct pointer_traits<T*>
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
44 template <class U> using rebind = U*;
46 static pointer pointer_to(<details>) noexcept;
49 template <class Alloc>
50 struct allocator_traits
52 typedef Alloc allocator_type;
53 typedef typename allocator_type::value_type
56 typedef Alloc::pointer | value_type* pointer;
57 typedef Alloc::const_pointer
58 | pointer_traits<pointer>::rebind<const value_type>
60 typedef Alloc::void_pointer
61 | pointer_traits<pointer>::rebind<void>
63 typedef Alloc::const_void_pointer
64 | pointer_traits<pointer>::rebind<const void>
66 typedef Alloc::difference_type
67 | pointer_traits<pointer>::difference_type
69 typedef Alloc::size_type
70 | make_unsigned<difference_type>::type
72 typedef Alloc::propagate_on_container_copy_assignment
73 | false_type propagate_on_container_copy_assignment;
74 typedef Alloc::propagate_on_container_move_assignment
75 | false_type propagate_on_container_move_assignment;
76 typedef Alloc::propagate_on_container_swap
77 | false_type propagate_on_container_swap;
79 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
80 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
82 static pointer allocate(allocator_type& a, size_type n);
83 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
85 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
87 template <class T, class... Args>
88 static void construct(allocator_type& a, T* p, Args&&... args);
91 static void destroy(allocator_type& a, T* p);
93 static size_type max_size(const allocator_type& a);
96 select_on_container_copy_construction(const allocator_type& a);
100 class allocator<void>
103 typedef void* pointer;
104 typedef const void* const_pointer;
105 typedef void value_type;
107 template <class _Up> struct rebind {typedef allocator<_Up> other;};
114 typedef size_t size_type;
115 typedef ptrdiff_t difference_type;
117 typedef const T* const_pointer;
118 typedef typename add_lvalue_reference<T>::type reference;
119 typedef typename add_lvalue_reference<const T>::type const_reference;
120 typedef T value_type;
122 template <class U> struct rebind {typedef allocator<U> other;};
124 allocator() noexcept;
125 allocator(const allocator&) noexcept;
126 template <class U> allocator(const allocator<U>&) noexcept;
128 pointer address(reference x) const noexcept;
129 const_pointer address(const_reference x) const noexcept;
130 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
131 void deallocate(pointer p, size_type n) noexcept;
132 size_type max_size() const noexcept;
133 template<class U, class... Args>
134 void construct(U* p, Args&&... args);
139 template <class T, class U>
140 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
142 template <class T, class U>
143 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
145 template <class OutputIterator, class T>
146 class raw_storage_iterator
147 : public iterator<output_iterator_tag,
148 T, // purposefully not C++03
149 ptrdiff_t, // purposefully not C++03
150 T*, // purposefully not C++03
151 raw_storage_iterator&> // purposefully not C++03
154 explicit raw_storage_iterator(OutputIterator x);
155 raw_storage_iterator& operator*();
156 raw_storage_iterator& operator=(const T& element);
157 raw_storage_iterator& operator++();
158 raw_storage_iterator operator++(int);
161 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162 template <class T> void return_temporary_buffer(T* p) noexcept;
164 template <class T> T* addressof(T& r) noexcept;
166 template <class InputIterator, class ForwardIterator>
168 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
170 template <class InputIterator, class Size, class ForwardIterator>
172 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
174 template <class ForwardIterator, class T>
175 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
177 template <class ForwardIterator, class Size, class T>
179 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
181 template <class Y> struct auto_ptr_ref {};
187 typedef X element_type;
189 explicit auto_ptr(X* p =0) throw();
190 auto_ptr(auto_ptr&) throw();
191 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192 auto_ptr& operator=(auto_ptr&) throw();
193 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
197 typename add_lvalue_reference<X>::type operator*() const throw();
198 X* operator->() const throw();
199 X* get() const throw();
200 X* release() throw();
201 void reset(X* p =0) throw();
203 auto_ptr(auto_ptr_ref<X>) throw();
204 template<class Y> operator auto_ptr_ref<Y>() throw();
205 template<class Y> operator auto_ptr<Y>() throw();
209 struct default_delete
211 constexpr default_delete() noexcept = default;
212 template <class U> default_delete(const default_delete<U>&) noexcept;
214 void operator()(T*) const noexcept;
218 struct default_delete<T[]>
220 constexpr default_delete() noexcept = default;
221 void operator()(T*) const noexcept;
222 template <class U> void operator()(U*) const = delete;
225 template <class T, class D = default_delete<T>>
229 typedef see below pointer;
230 typedef T element_type;
231 typedef D deleter_type;
234 constexpr unique_ptr() noexcept;
235 explicit unique_ptr(pointer p) noexcept;
236 unique_ptr(pointer p, see below d1) noexcept;
237 unique_ptr(pointer p, see below d2) noexcept;
238 unique_ptr(unique_ptr&& u) noexcept;
239 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
240 template <class U, class E>
241 unique_ptr(unique_ptr<U, E>&& u) noexcept;
243 unique_ptr(auto_ptr<U>&& u) noexcept;
249 unique_ptr& operator=(unique_ptr&& u) noexcept;
250 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251 unique_ptr& operator=(nullptr_t) noexcept;
254 typename add_lvalue_reference<T>::type operator*() const;
255 pointer operator->() const noexcept;
256 pointer get() const noexcept;
257 deleter_type& get_deleter() noexcept;
258 const deleter_type& get_deleter() const noexcept;
259 explicit operator bool() const noexcept;
262 pointer release() noexcept;
263 void reset(pointer p = pointer()) noexcept;
264 void swap(unique_ptr& u) noexcept;
267 template <class T, class D>
268 class unique_ptr<T[], D>
271 typedef implementation-defined pointer;
272 typedef T element_type;
273 typedef D deleter_type;
276 constexpr unique_ptr() noexcept;
277 explicit unique_ptr(pointer p) noexcept;
278 unique_ptr(pointer p, see below d) noexcept;
279 unique_ptr(pointer p, see below d) noexcept;
280 unique_ptr(unique_ptr&& u) noexcept;
281 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
287 unique_ptr& operator=(unique_ptr&& u) noexcept;
288 unique_ptr& operator=(nullptr_t) noexcept;
291 T& operator[](size_t i) const;
292 pointer get() const noexcept;
293 deleter_type& get_deleter() noexcept;
294 const deleter_type& get_deleter() const noexcept;
295 explicit operator bool() const noexcept;
298 pointer release() noexcept;
299 void reset(pointer p = pointer()) noexcept;
300 void reset(nullptr_t) noexcept;
301 template <class U> void reset(U) = delete;
302 void swap(unique_ptr& u) noexcept;
305 template <class T, class D>
306 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
308 template <class T1, class D1, class T2, class D2>
309 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
310 template <class T1, class D1, class T2, class D2>
311 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312 template <class T1, class D1, class T2, class D2>
313 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314 template <class T1, class D1, class T2, class D2>
315 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316 template <class T1, class D1, class T2, class D2>
317 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318 template <class T1, class D1, class T2, class D2>
319 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
321 template <class T, class D>
322 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323 template <class T, class D>
324 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325 template <class T, class D>
326 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327 template <class T, class D>
328 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
330 template <class T, class D>
331 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332 template <class T, class D>
333 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334 template <class T, class D>
335 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336 template <class T, class D>
337 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338 template <class T, class D>
339 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340 template <class T, class D>
341 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342 template <class T, class D>
343 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344 template <class T, class D>
345 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
348 : public std::exception
350 bad_weak_ptr() noexcept;
357 typedef T element_type;
360 constexpr shared_ptr() noexcept;
361 template<class Y> explicit shared_ptr(Y* p);
362 template<class Y, class D> shared_ptr(Y* p, D d);
363 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
364 template <class D> shared_ptr(nullptr_t p, D d);
365 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
366 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
367 shared_ptr(const shared_ptr& r) noexcept;
368 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
369 shared_ptr(shared_ptr&& r) noexcept;
370 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
371 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
372 template<class Y> shared_ptr(auto_ptr<Y>&& r);
373 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
374 shared_ptr(nullptr_t) : shared_ptr() { }
380 shared_ptr& operator=(const shared_ptr& r) noexcept;
381 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
382 shared_ptr& operator=(shared_ptr&& r) noexcept;
383 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
384 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
385 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
388 void swap(shared_ptr& r) noexcept;
389 void reset() noexcept;
390 template<class Y> void reset(Y* p);
391 template<class Y, class D> void reset(Y* p, D d);
392 template<class Y, class D, class A> void reset(Y* p, D d, A a);
395 T* get() const noexcept;
396 T& operator*() const noexcept;
397 T* operator->() const noexcept;
398 long use_count() const noexcept;
399 bool unique() const noexcept;
400 explicit operator bool() const noexcept;
401 template<class U> bool owner_before(shared_ptr<U> const& b) const;
402 template<class U> bool owner_before(weak_ptr<U> const& b) const;
405 // shared_ptr comparisons:
406 template<class T, class U>
407 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
408 template<class T, class U>
409 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
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;
420 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
422 bool operator==(nullptr_t, const shared_ptr<T>& y) 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 // shared_ptr specialized algorithms:
445 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
448 template<class T, class U>
449 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
450 template<class T, class U>
451 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
452 template<class T, class U>
453 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
456 template<class E, class T, class Y>
457 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
459 // shared_ptr get_deleter:
460 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
462 template<class T, class... Args>
463 shared_ptr<T> make_shared(Args&&... args);
464 template<class T, class A, class... Args>
465 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
471 typedef T element_type;
474 constexpr weak_ptr() noexcept;
475 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
476 weak_ptr(weak_ptr const& r) noexcept;
477 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
483 weak_ptr& operator=(weak_ptr const& r) noexcept;
484 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
485 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
488 void swap(weak_ptr& r) noexcept;
489 void reset() noexcept;
492 long use_count() const noexcept;
493 bool expired() const noexcept;
494 shared_ptr<T> lock() const noexcept;
495 template<class U> bool owner_before(shared_ptr<U> const& b);
496 template<class U> bool owner_before(weak_ptr<U> const& b);
499 // weak_ptr specialized algorithms:
500 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
503 template<class T> struct owner_less;
506 struct owner_less<shared_ptr<T>>
507 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
509 typedef bool result_type;
510 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
511 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
512 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
516 struct owner_less<weak_ptr<T>>
517 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
519 typedef bool result_type;
520 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
521 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
522 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
526 class enable_shared_from_this
529 constexpr enable_shared_from_this() noexcept;
530 enable_shared_from_this(enable_shared_from_this const&) noexcept;
531 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
532 ~enable_shared_from_this();
534 shared_ptr<T> shared_from_this();
535 shared_ptr<T const> shared_from_this() const;
539 bool atomic_is_lock_free(const shared_ptr<T>* p);
541 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
543 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
545 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
547 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
549 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
552 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
555 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
558 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
561 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
562 shared_ptr<T> w, memory_order success,
563 memory_order failure);
566 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
567 shared_ptr<T> w, memory_order success,
568 memory_order failure);
570 template <class T> struct hash;
571 template <class T, class D> struct hash<unique_ptr<T, D> >;
572 template <class T> struct hash<shared_ptr<T> >;
575 enum class pointer_safety { relaxed, preferred, strict };
576 void declare_reachable(void *p);
577 template <class T> T *undeclare_reachable(T *p);
578 void declare_no_pointers(char *p, size_t n);
579 void undeclare_no_pointers(char *p, size_t n);
580 pointer_safety get_pointer_safety() noexcept;
582 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
589 #include <type_traits>
597 #include <__functional_base>
601 #if defined(_LIBCPP_NO_EXCEPTIONS)
605 #include <__undef_min_max>
607 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
608 #pragma GCC system_header
611 _LIBCPP_BEGIN_NAMESPACE_STD
616 inline _LIBCPP_INLINE_VISIBILITY
618 addressof(_Tp& __x) _NOEXCEPT
620 return (_Tp*)&(char&)__x;
623 #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
624 // Objective-C++ Automatic Reference Counting uses qualified pointers
625 // that require special addressof() signatures. When
626 // _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
627 // itself is providing these definitions. Otherwise, we provide them.
629 inline _LIBCPP_INLINE_VISIBILITY
631 addressof(__strong _Tp& __x) _NOEXCEPT
636 #ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
638 inline _LIBCPP_INLINE_VISIBILITY
640 addressof(__weak _Tp& __x) _NOEXCEPT
647 inline _LIBCPP_INLINE_VISIBILITY
649 addressof(__autoreleasing _Tp& __x) _NOEXCEPT
655 inline _LIBCPP_INLINE_VISIBILITY
656 __unsafe_unretained _Tp*
657 addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
663 template <class _Tp> class allocator;
666 class _LIBCPP_VISIBLE allocator<void>
669 typedef void* pointer;
670 typedef const void* const_pointer;
671 typedef void value_type;
673 template <class _Up> struct rebind {typedef allocator<_Up> other;};
677 class _LIBCPP_VISIBLE allocator<const void>
680 typedef const void* pointer;
681 typedef const void* const_pointer;
682 typedef const void value_type;
684 template <class _Up> struct rebind {typedef allocator<_Up> other;};
690 struct __has_element_type
693 struct __two {char _; char __;};
694 template <class _Up> static __two __test(...);
695 template <class _Up> static char __test(typename _Up::element_type* = 0);
697 static const bool value = sizeof(__test<_Tp>(0)) == 1;
700 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
701 struct __pointer_traits_element_type;
703 template <class _Ptr>
704 struct __pointer_traits_element_type<_Ptr, true>
706 typedef typename _Ptr::element_type type;
709 #ifndef _LIBCPP_HAS_NO_VARIADICS
711 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
712 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
714 typedef typename _Sp<_Tp, _Args...>::element_type type;
717 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
718 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
723 #else // _LIBCPP_HAS_NO_VARIADICS
725 template <template <class> class _Sp, class _Tp>
726 struct __pointer_traits_element_type<_Sp<_Tp>, true>
728 typedef typename _Sp<_Tp>::element_type type;
731 template <template <class> class _Sp, class _Tp>
732 struct __pointer_traits_element_type<_Sp<_Tp>, false>
737 template <template <class, class> class _Sp, class _Tp, class _A0>
738 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
740 typedef typename _Sp<_Tp, _A0>::element_type type;
743 template <template <class, class> class _Sp, class _Tp, class _A0>
744 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
749 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
750 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
752 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
755 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
756 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
761 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
762 class _A1, class _A2>
763 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
765 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
768 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
769 class _A1, class _A2>
770 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
775 #endif // _LIBCPP_HAS_NO_VARIADICS
778 struct __has_difference_type
781 struct __two {char _; char __;};
782 template <class _Up> static __two __test(...);
783 template <class _Up> static char __test(typename _Up::difference_type* = 0);
785 static const bool value = sizeof(__test<_Tp>(0)) == 1;
788 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
789 struct __pointer_traits_difference_type
791 typedef ptrdiff_t type;
794 template <class _Ptr>
795 struct __pointer_traits_difference_type<_Ptr, true>
797 typedef typename _Ptr::difference_type type;
800 template <class _Tp, class _Up>
804 struct __two {char _; char __;};
805 template <class _Xp> static __two __test(...);
806 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
808 static const bool value = sizeof(__test<_Tp>(0)) == 1;
811 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
812 struct __pointer_traits_rebind
814 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
815 typedef typename _Tp::template rebind<_Up> type;
817 typedef typename _Tp::template rebind<_Up>::other type;
821 #ifndef _LIBCPP_HAS_NO_VARIADICS
823 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
824 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
826 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
827 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
829 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
833 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
834 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
836 typedef _Sp<_Up, _Args...> type;
839 #else // _LIBCPP_HAS_NO_VARIADICS
841 template <template <class> class _Sp, class _Tp, class _Up>
842 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
844 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
845 typedef typename _Sp<_Tp>::template rebind<_Up> type;
847 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
851 template <template <class> class _Sp, class _Tp, class _Up>
852 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
854 typedef _Sp<_Up> type;
857 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
858 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
860 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
861 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
863 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
867 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
868 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
870 typedef _Sp<_Up, _A0> type;
873 template <template <class, class, class> class _Sp, class _Tp, class _A0,
874 class _A1, class _Up>
875 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
877 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
878 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
880 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
884 template <template <class, class, class> class _Sp, class _Tp, class _A0,
885 class _A1, class _Up>
886 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
888 typedef _Sp<_Up, _A0, _A1> type;
891 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
892 class _A1, class _A2, class _Up>
893 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
895 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
896 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
898 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
902 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
903 class _A1, class _A2, class _Up>
904 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
906 typedef _Sp<_Up, _A0, _A1, _A2> type;
909 #endif // _LIBCPP_HAS_NO_VARIADICS
911 template <class _Ptr>
912 struct _LIBCPP_VISIBLE pointer_traits
914 typedef _Ptr pointer;
915 typedef typename __pointer_traits_element_type<pointer>::type element_type;
916 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
918 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
919 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
921 template <class _Up> struct rebind
922 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
923 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
928 _LIBCPP_INLINE_VISIBILITY
929 static pointer pointer_to(typename conditional<is_void<element_type>::value,
930 __nat, element_type>::type& __r)
931 {return pointer::pointer_to(__r);}
935 struct _LIBCPP_VISIBLE pointer_traits<_Tp*>
937 typedef _Tp* pointer;
938 typedef _Tp element_type;
939 typedef ptrdiff_t difference_type;
941 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
942 template <class _Up> using rebind = _Up*;
944 template <class _Up> struct rebind {typedef _Up* other;};
950 _LIBCPP_INLINE_VISIBILITY
951 static pointer pointer_to(typename conditional<is_void<element_type>::value,
952 __nat, element_type>::type& __r) _NOEXCEPT
953 {return _VSTD::addressof(__r);}
958 namespace __has_pointer_type_imp
960 template <class _Up> static __two test(...);
961 template <class _Up> static char test(typename _Up::pointer* = 0);
965 struct __has_pointer_type
966 : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
970 namespace __pointer_type_imp
973 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
974 struct __pointer_type
976 typedef typename _Dp::pointer type;
979 template <class _Tp, class _Dp>
980 struct __pointer_type<_Tp, _Dp, false>
985 } // __pointer_type_imp
987 template <class _Tp, class _Dp>
988 struct __pointer_type
990 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
994 struct __has_const_pointer
997 struct __two {char _; char __;};
998 template <class _Up> static __two __test(...);
999 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1001 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1004 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1005 struct __const_pointer
1007 typedef typename _Alloc::const_pointer type;
1010 template <class _Tp, class _Ptr, class _Alloc>
1011 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1013 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1014 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1016 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1020 template <class _Tp>
1021 struct __has_void_pointer
1024 struct __two {char _; char __;};
1025 template <class _Up> static __two __test(...);
1026 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1028 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1031 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1032 struct __void_pointer
1034 typedef typename _Alloc::void_pointer type;
1037 template <class _Ptr, class _Alloc>
1038 struct __void_pointer<_Ptr, _Alloc, false>
1040 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1041 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1043 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1047 template <class _Tp>
1048 struct __has_const_void_pointer
1051 struct __two {char _; char __;};
1052 template <class _Up> static __two __test(...);
1053 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1055 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1058 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1059 struct __const_void_pointer
1061 typedef typename _Alloc::const_void_pointer type;
1064 template <class _Ptr, class _Alloc>
1065 struct __const_void_pointer<_Ptr, _Alloc, false>
1067 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1068 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1070 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1074 template <class _Tp>
1075 inline _LIBCPP_INLINE_VISIBILITY
1077 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1082 template <class _Pointer>
1083 inline _LIBCPP_INLINE_VISIBILITY
1084 typename pointer_traits<_Pointer>::element_type*
1085 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1087 return _VSTD::__to_raw_pointer(__p.operator->());
1090 template <class _Tp>
1091 struct __has_size_type
1094 struct __two {char _; char __;};
1095 template <class _Up> static __two __test(...);
1096 template <class _Up> static char __test(typename _Up::size_type* = 0);
1098 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1101 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1104 typedef typename make_unsigned<_DiffType>::type type;
1107 template <class _Alloc, class _DiffType>
1108 struct __size_type<_Alloc, _DiffType, true>
1110 typedef typename _Alloc::size_type type;
1113 template <class _Tp>
1114 struct __has_propagate_on_container_copy_assignment
1117 struct __two {char _; char __;};
1118 template <class _Up> static __two __test(...);
1119 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1121 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1124 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1125 struct __propagate_on_container_copy_assignment
1127 typedef false_type type;
1130 template <class _Alloc>
1131 struct __propagate_on_container_copy_assignment<_Alloc, true>
1133 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1136 template <class _Tp>
1137 struct __has_propagate_on_container_move_assignment
1140 struct __two {char _; char __;};
1141 template <class _Up> static __two __test(...);
1142 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1144 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1147 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1148 struct __propagate_on_container_move_assignment
1150 typedef false_type type;
1153 template <class _Alloc>
1154 struct __propagate_on_container_move_assignment<_Alloc, true>
1156 typedef typename _Alloc::propagate_on_container_move_assignment type;
1159 template <class _Tp>
1160 struct __has_propagate_on_container_swap
1163 struct __two {char _; char __;};
1164 template <class _Up> static __two __test(...);
1165 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1167 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1170 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1171 struct __propagate_on_container_swap
1173 typedef false_type type;
1176 template <class _Alloc>
1177 struct __propagate_on_container_swap<_Alloc, true>
1179 typedef typename _Alloc::propagate_on_container_swap type;
1182 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1183 struct __has_rebind_other
1186 struct __two {char _; char __;};
1187 template <class _Xp> static __two __test(...);
1188 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1190 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1193 template <class _Tp, class _Up>
1194 struct __has_rebind_other<_Tp, _Up, false>
1196 static const bool value = false;
1199 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1200 struct __allocator_traits_rebind
1202 typedef typename _Tp::template rebind<_Up>::other type;
1205 #ifndef _LIBCPP_HAS_NO_VARIADICS
1207 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1208 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1210 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1213 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1214 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1216 typedef _Alloc<_Up, _Args...> type;
1219 #else // _LIBCPP_HAS_NO_VARIADICS
1221 template <template <class> class _Alloc, class _Tp, class _Up>
1222 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1224 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1227 template <template <class> class _Alloc, class _Tp, class _Up>
1228 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1230 typedef _Alloc<_Up> type;
1233 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1234 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1236 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1239 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1240 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1242 typedef _Alloc<_Up, _A0> type;
1245 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1246 class _A1, class _Up>
1247 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1249 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1252 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1253 class _A1, class _Up>
1254 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1256 typedef _Alloc<_Up, _A0, _A1> type;
1259 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1260 class _A1, class _A2, class _Up>
1261 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1263 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1266 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1267 class _A1, class _A2, class _Up>
1268 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1270 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1273 #endif // _LIBCPP_HAS_NO_VARIADICS
1275 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1277 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1279 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1280 -> decltype(__a.allocate(__sz, __p), true_type());
1282 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1284 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1287 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1288 struct __has_allocate_hint
1289 : integral_constant<bool,
1291 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1292 declval<_SizeType>(),
1293 declval<_ConstVoidPtr>())),
1298 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1300 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1301 struct __has_allocate_hint
1306 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1308 #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1310 template <class _Alloc, class _Tp, class ..._Args>
1311 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1312 _VSTD::declval<_Args>()...),
1314 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1316 template <class _Alloc, class _Pointer, class ..._Args>
1318 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1320 template <class _Alloc, class _Pointer, class ..._Args>
1321 struct __has_construct
1322 : integral_constant<bool,
1324 decltype(__has_construct_test(declval<_Alloc>(),
1325 declval<_Pointer>(),
1326 declval<_Args>()...)),
1331 template <class _Alloc, class _Pointer>
1333 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1334 -> decltype(__a.destroy(__p), true_type());
1336 template <class _Alloc, class _Pointer>
1338 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1341 template <class _Alloc, class _Pointer>
1342 struct __has_destroy
1343 : integral_constant<bool,
1345 decltype(__has_destroy_test(declval<_Alloc>(),
1346 declval<_Pointer>())),
1351 template <class _Alloc>
1353 __has_max_size_test(_Alloc&& __a)
1354 -> decltype(__a.max_size(), true_type());
1356 template <class _Alloc>
1358 __has_max_size_test(const volatile _Alloc& __a)
1361 template <class _Alloc>
1362 struct __has_max_size
1363 : integral_constant<bool,
1365 decltype(__has_max_size_test(declval<_Alloc&>())),
1370 template <class _Alloc>
1372 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1373 -> decltype(__a.select_on_container_copy_construction(), true_type());
1375 template <class _Alloc>
1377 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1380 template <class _Alloc>
1381 struct __has_select_on_container_copy_construction
1382 : integral_constant<bool,
1384 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1389 #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1391 #ifndef _LIBCPP_HAS_NO_VARIADICS
1393 template <class _Alloc, class _Pointer, class ..._Args>
1394 struct __has_construct
1399 #else // _LIBCPP_HAS_NO_VARIADICS
1401 template <class _Alloc, class _Pointer, class _Args>
1402 struct __has_construct
1407 #endif // _LIBCPP_HAS_NO_VARIADICS
1409 template <class _Alloc, class _Pointer>
1410 struct __has_destroy
1415 template <class _Alloc>
1416 struct __has_max_size
1421 template <class _Alloc>
1422 struct __has_select_on_container_copy_construction
1427 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1429 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1430 struct __alloc_traits_difference_type
1432 typedef typename pointer_traits<_Ptr>::difference_type type;
1435 template <class _Alloc, class _Ptr>
1436 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1438 typedef typename _Alloc::difference_type type;
1441 template <class _Alloc>
1442 struct _LIBCPP_VISIBLE allocator_traits
1444 typedef _Alloc allocator_type;
1445 typedef typename allocator_type::value_type value_type;
1447 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1448 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1449 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1450 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1452 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1453 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1455 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1456 propagate_on_container_copy_assignment;
1457 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1458 propagate_on_container_move_assignment;
1459 typedef typename __propagate_on_container_swap<allocator_type>::type
1460 propagate_on_container_swap;
1462 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1463 template <class _Tp> using rebind_alloc =
1464 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1465 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1466 #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1467 template <class _Tp> struct rebind_alloc
1468 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1469 template <class _Tp> struct rebind_traits
1470 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1471 #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1473 _LIBCPP_INLINE_VISIBILITY
1474 static pointer allocate(allocator_type& __a, size_type __n)
1475 {return __a.allocate(__n);}
1476 _LIBCPP_INLINE_VISIBILITY
1477 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1478 {return allocate(__a, __n, __hint,
1479 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1481 _LIBCPP_INLINE_VISIBILITY
1482 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1483 {__a.deallocate(__p, __n);}
1485 #ifndef _LIBCPP_HAS_NO_VARIADICS
1486 template <class _Tp, class... _Args>
1487 _LIBCPP_INLINE_VISIBILITY
1488 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1489 {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1490 __a, __p, _VSTD::forward<_Args>(__args)...);}
1491 #else // _LIBCPP_HAS_NO_VARIADICS
1492 template <class _Tp>
1493 _LIBCPP_INLINE_VISIBILITY
1494 static void construct(allocator_type& __a, _Tp* __p)
1496 ::new ((void*)__p) _Tp();
1498 template <class _Tp, class _A0>
1499 _LIBCPP_INLINE_VISIBILITY
1500 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1502 ::new ((void*)__p) _Tp(__a0);
1504 template <class _Tp, class _A0, class _A1>
1505 _LIBCPP_INLINE_VISIBILITY
1506 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1509 ::new ((void*)__p) _Tp(__a0, __a1);
1511 template <class _Tp, class _A0, class _A1, class _A2>
1512 _LIBCPP_INLINE_VISIBILITY
1513 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1514 const _A1& __a1, const _A2& __a2)
1516 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1518 #endif // _LIBCPP_HAS_NO_VARIADICS
1520 template <class _Tp>
1521 _LIBCPP_INLINE_VISIBILITY
1522 static void destroy(allocator_type& __a, _Tp* __p)
1523 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1525 _LIBCPP_INLINE_VISIBILITY
1526 static size_type max_size(const allocator_type& __a)
1527 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1529 _LIBCPP_INLINE_VISIBILITY
1530 static allocator_type
1531 select_on_container_copy_construction(const allocator_type& __a)
1532 {return select_on_container_copy_construction(
1533 __has_select_on_container_copy_construction<const allocator_type>(),
1536 template <class _Ptr>
1537 _LIBCPP_INLINE_VISIBILITY
1540 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1542 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1543 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1546 template <class _Tp>
1547 _LIBCPP_INLINE_VISIBILITY
1551 (is_same<allocator_type, allocator<_Tp> >::value
1552 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1553 is_trivially_move_constructible<_Tp>::value,
1556 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1558 ptrdiff_t _Np = __end1 - __begin1;
1559 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1563 template <class _Ptr>
1564 _LIBCPP_INLINE_VISIBILITY
1567 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1569 while (__end1 != __begin1)
1570 construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
1573 template <class _Tp>
1574 _LIBCPP_INLINE_VISIBILITY
1578 (is_same<allocator_type, allocator<_Tp> >::value
1579 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1580 is_trivially_move_constructible<_Tp>::value,
1583 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1585 ptrdiff_t _Np = __end1 - __begin1;
1587 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1592 _LIBCPP_INLINE_VISIBILITY
1593 static pointer allocate(allocator_type& __a, size_type __n,
1594 const_void_pointer __hint, true_type)
1595 {return __a.allocate(__n, __hint);}
1596 _LIBCPP_INLINE_VISIBILITY
1597 static pointer allocate(allocator_type& __a, size_type __n,
1598 const_void_pointer, false_type)
1599 {return __a.allocate(__n);}
1601 #ifndef _LIBCPP_HAS_NO_VARIADICS
1602 template <class _Tp, class... _Args>
1603 _LIBCPP_INLINE_VISIBILITY
1604 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1605 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1606 template <class _Tp, class... _Args>
1607 _LIBCPP_INLINE_VISIBILITY
1608 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1610 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1612 #endif // _LIBCPP_HAS_NO_VARIADICS
1614 template <class _Tp>
1615 _LIBCPP_INLINE_VISIBILITY
1616 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1618 template <class _Tp>
1619 _LIBCPP_INLINE_VISIBILITY
1620 static void __destroy(false_type, allocator_type&, _Tp* __p)
1625 _LIBCPP_INLINE_VISIBILITY
1626 static size_type __max_size(true_type, const allocator_type& __a)
1627 {return __a.max_size();}
1628 _LIBCPP_INLINE_VISIBILITY
1629 static size_type __max_size(false_type, const allocator_type&)
1630 {return numeric_limits<size_type>::max();}
1632 _LIBCPP_INLINE_VISIBILITY
1633 static allocator_type
1634 select_on_container_copy_construction(true_type, const allocator_type& __a)
1635 {return __a.select_on_container_copy_construction();}
1636 _LIBCPP_INLINE_VISIBILITY
1637 static allocator_type
1638 select_on_container_copy_construction(false_type, const allocator_type& __a)
1644 template <class _Tp>
1645 class _LIBCPP_VISIBLE allocator
1648 typedef size_t size_type;
1649 typedef ptrdiff_t difference_type;
1650 typedef _Tp* pointer;
1651 typedef const _Tp* const_pointer;
1652 typedef _Tp& reference;
1653 typedef const _Tp& const_reference;
1654 typedef _Tp value_type;
1656 typedef true_type propagate_on_container_move_assignment;
1658 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1660 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1661 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1662 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1663 {return _VSTD::addressof(__x);}
1664 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1665 {return _VSTD::addressof(__x);}
1666 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1667 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1668 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1669 {::operator delete((void*)__p);}
1670 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1671 {return size_type(~0) / sizeof(_Tp);}
1672 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1673 template <class _Up, class... _Args>
1674 _LIBCPP_INLINE_VISIBILITY
1676 construct(_Up* __p, _Args&&... __args)
1678 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1680 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1681 _LIBCPP_INLINE_VISIBILITY
1683 construct(pointer __p)
1685 ::new((void*)__p) _Tp();
1687 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1689 template <class _A0>
1690 _LIBCPP_INLINE_VISIBILITY
1692 construct(pointer __p, _A0& __a0)
1694 ::new((void*)__p) _Tp(__a0);
1696 template <class _A0>
1697 _LIBCPP_INLINE_VISIBILITY
1699 construct(pointer __p, const _A0& __a0)
1701 ::new((void*)__p) _Tp(__a0);
1703 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1704 template <class _A0, class _A1>
1705 _LIBCPP_INLINE_VISIBILITY
1707 construct(pointer __p, _A0& __a0, _A1& __a1)
1709 ::new((void*)__p) _Tp(__a0, __a1);
1711 template <class _A0, class _A1>
1712 _LIBCPP_INLINE_VISIBILITY
1714 construct(pointer __p, const _A0& __a0, _A1& __a1)
1716 ::new((void*)__p) _Tp(__a0, __a1);
1718 template <class _A0, class _A1>
1719 _LIBCPP_INLINE_VISIBILITY
1721 construct(pointer __p, _A0& __a0, const _A1& __a1)
1723 ::new((void*)__p) _Tp(__a0, __a1);
1725 template <class _A0, class _A1>
1726 _LIBCPP_INLINE_VISIBILITY
1728 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1730 ::new((void*)__p) _Tp(__a0, __a1);
1732 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1733 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1736 template <class _Tp>
1737 class _LIBCPP_VISIBLE allocator<const _Tp>
1740 typedef size_t size_type;
1741 typedef ptrdiff_t difference_type;
1742 typedef const _Tp* pointer;
1743 typedef const _Tp* const_pointer;
1744 typedef const _Tp& reference;
1745 typedef const _Tp& const_reference;
1746 typedef _Tp value_type;
1748 typedef true_type propagate_on_container_move_assignment;
1750 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1752 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1753 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1754 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1755 {return _VSTD::addressof(__x);}
1756 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1757 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1758 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1759 {::operator delete((void*)__p);}
1760 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1761 {return size_type(~0) / sizeof(_Tp);}
1762 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1763 template <class _Up, class... _Args>
1764 _LIBCPP_INLINE_VISIBILITY
1766 construct(_Up* __p, _Args&&... __args)
1768 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1770 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1771 _LIBCPP_INLINE_VISIBILITY
1773 construct(pointer __p)
1775 ::new((void*)__p) _Tp();
1777 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1779 template <class _A0>
1780 _LIBCPP_INLINE_VISIBILITY
1782 construct(pointer __p, _A0& __a0)
1784 ::new((void*)__p) _Tp(__a0);
1786 template <class _A0>
1787 _LIBCPP_INLINE_VISIBILITY
1789 construct(pointer __p, const _A0& __a0)
1791 ::new((void*)__p) _Tp(__a0);
1793 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1794 template <class _A0, class _A1>
1795 _LIBCPP_INLINE_VISIBILITY
1797 construct(pointer __p, _A0& __a0, _A1& __a1)
1799 ::new((void*)__p) _Tp(__a0, __a1);
1801 template <class _A0, class _A1>
1802 _LIBCPP_INLINE_VISIBILITY
1804 construct(pointer __p, const _A0& __a0, _A1& __a1)
1806 ::new((void*)__p) _Tp(__a0, __a1);
1808 template <class _A0, class _A1>
1809 _LIBCPP_INLINE_VISIBILITY
1811 construct(pointer __p, _A0& __a0, const _A1& __a1)
1813 ::new((void*)__p) _Tp(__a0, __a1);
1815 template <class _A0, class _A1>
1816 _LIBCPP_INLINE_VISIBILITY
1818 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1820 ::new((void*)__p) _Tp(__a0, __a1);
1822 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1823 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1826 template <class _Tp, class _Up>
1827 inline _LIBCPP_INLINE_VISIBILITY
1828 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1830 template <class _Tp, class _Up>
1831 inline _LIBCPP_INLINE_VISIBILITY
1832 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1834 template <class _OutputIterator, class _Tp>
1835 class _LIBCPP_VISIBLE raw_storage_iterator
1836 : public iterator<output_iterator_tag,
1837 _Tp, // purposefully not C++03
1838 ptrdiff_t, // purposefully not C++03
1839 _Tp*, // purposefully not C++03
1840 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1843 _OutputIterator __x_;
1845 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1846 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1847 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1848 {::new(&*__x_) _Tp(__element); return *this;}
1849 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1850 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1851 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1854 template <class _Tp>
1855 pair<_Tp*, ptrdiff_t>
1856 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1858 pair<_Tp*, ptrdiff_t> __r(0, 0);
1859 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1860 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1866 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1877 template <class _Tp>
1878 inline _LIBCPP_INLINE_VISIBILITY
1879 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1881 template <class _Tp>
1888 class _LIBCPP_VISIBLE auto_ptr
1893 typedef _Tp element_type;
1895 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1896 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1897 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1898 : __ptr_(__p.release()) {}
1899 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1900 {reset(__p.release()); return *this;}
1901 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1902 {reset(__p.release()); return *this;}
1903 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1904 {reset(__p.__ptr_); return *this;}
1905 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1907 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1909 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1910 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1911 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1917 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1924 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1925 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1926 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1927 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1928 {return auto_ptr<_Up>(release());}
1932 class _LIBCPP_VISIBLE auto_ptr<void>
1935 typedef void element_type;
1938 template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1939 typename remove_cv<_T2>::type>::value,
1940 bool = is_empty<_T1>::value
1941 #if __has_feature(is_final)
1945 bool = is_empty<_T2>::value
1946 #if __has_feature(is_final)
1950 struct __libcpp_compressed_pair_switch;
1952 template <class _T1, class _T2, bool IsSame>
1953 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1955 template <class _T1, class _T2, bool IsSame>
1956 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1958 template <class _T1, class _T2, bool IsSame>
1959 struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1961 template <class _T1, class _T2>
1962 struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1964 template <class _T1, class _T2>
1965 struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1967 template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1968 class __libcpp_compressed_pair_imp;
1970 template <class _T1, class _T2>
1971 class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1977 typedef _T1 _T1_param;
1978 typedef _T2 _T2_param;
1980 typedef typename remove_reference<_T1>::type& _T1_reference;
1981 typedef typename remove_reference<_T2>::type& _T2_reference;
1983 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1984 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1986 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1987 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1988 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1989 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
1990 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
1991 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
1992 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
1994 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1996 _LIBCPP_INLINE_VISIBILITY
1997 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
1998 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
1999 is_nothrow_copy_constructible<_T2>::value)
2000 : __first_(__p.first()),
2001 __second_(__p.second()) {}
2003 _LIBCPP_INLINE_VISIBILITY
2004 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2005 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2006 is_nothrow_copy_assignable<_T2>::value)
2008 __first_ = __p.first();
2009 __second_ = __p.second();
2013 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2015 _LIBCPP_INLINE_VISIBILITY
2016 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2017 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2018 is_nothrow_move_constructible<_T2>::value)
2019 : __first_(_VSTD::forward<_T1>(__p.first())),
2020 __second_(_VSTD::forward<_T2>(__p.second())) {}
2022 _LIBCPP_INLINE_VISIBILITY
2023 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2024 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2025 is_nothrow_move_assignable<_T2>::value)
2027 __first_ = _VSTD::forward<_T1>(__p.first());
2028 __second_ = _VSTD::forward<_T2>(__p.second());
2032 #ifndef _LIBCPP_HAS_NO_VARIADICS
2034 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2035 _LIBCPP_INLINE_VISIBILITY
2036 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2037 tuple<_Args1...> __first_args,
2038 tuple<_Args2...> __second_args,
2039 __tuple_indices<_I1...>,
2040 __tuple_indices<_I2...>)
2041 : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2042 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2045 #endif // _LIBCPP_HAS_NO_VARIADICS
2047 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2049 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2051 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2052 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2054 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2055 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2057 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2058 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2059 __is_nothrow_swappable<_T1>::value)
2062 swap(__first_, __x.__first_);
2063 swap(__second_, __x.__second_);
2067 template <class _T1, class _T2>
2068 class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2074 typedef _T1 _T1_param;
2075 typedef _T2 _T2_param;
2077 typedef _T1& _T1_reference;
2078 typedef typename remove_reference<_T2>::type& _T2_reference;
2080 typedef const _T1& _T1_const_reference;
2081 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2083 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2084 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2085 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2086 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2087 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2088 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2089 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2091 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2093 _LIBCPP_INLINE_VISIBILITY
2094 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2095 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2096 is_nothrow_copy_constructible<_T2>::value)
2097 : _T1(__p.first()), __second_(__p.second()) {}
2099 _LIBCPP_INLINE_VISIBILITY
2100 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2101 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2102 is_nothrow_copy_assignable<_T2>::value)
2104 _T1::operator=(__p.first());
2105 __second_ = __p.second();
2109 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2111 _LIBCPP_INLINE_VISIBILITY
2112 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2113 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2114 is_nothrow_move_constructible<_T2>::value)
2115 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2117 _LIBCPP_INLINE_VISIBILITY
2118 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2119 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2120 is_nothrow_move_assignable<_T2>::value)
2122 _T1::operator=(_VSTD::move(__p.first()));
2123 __second_ = _VSTD::forward<_T2>(__p.second());
2127 #ifndef _LIBCPP_HAS_NO_VARIADICS
2129 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2130 _LIBCPP_INLINE_VISIBILITY
2131 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2132 tuple<_Args1...> __first_args,
2133 tuple<_Args2...> __second_args,
2134 __tuple_indices<_I1...>,
2135 __tuple_indices<_I2...>)
2136 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2137 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2140 #endif // _LIBCPP_HAS_NO_VARIADICS
2142 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2144 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2146 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2147 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2149 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2150 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2152 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2153 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2154 __is_nothrow_swappable<_T1>::value)
2157 swap(__second_, __x.__second_);
2161 template <class _T1, class _T2>
2162 class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2168 typedef _T1 _T1_param;
2169 typedef _T2 _T2_param;
2171 typedef typename remove_reference<_T1>::type& _T1_reference;
2172 typedef _T2& _T2_reference;
2174 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2175 typedef const _T2& _T2_const_reference;
2177 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2178 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2179 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2180 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2181 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2182 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2183 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2184 is_nothrow_move_constructible<_T2>::value)
2185 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2187 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2189 _LIBCPP_INLINE_VISIBILITY
2190 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2191 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2192 is_nothrow_copy_constructible<_T2>::value)
2193 : _T2(__p.second()), __first_(__p.first()) {}
2195 _LIBCPP_INLINE_VISIBILITY
2196 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2197 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2198 is_nothrow_copy_assignable<_T2>::value)
2200 _T2::operator=(__p.second());
2201 __first_ = __p.first();
2205 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2207 _LIBCPP_INLINE_VISIBILITY
2208 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2209 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2210 is_nothrow_move_constructible<_T2>::value)
2211 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2213 _LIBCPP_INLINE_VISIBILITY
2214 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2215 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2216 is_nothrow_move_assignable<_T2>::value)
2218 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2219 __first_ = _VSTD::move(__p.first());
2223 #ifndef _LIBCPP_HAS_NO_VARIADICS
2225 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2226 _LIBCPP_INLINE_VISIBILITY
2227 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2228 tuple<_Args1...> __first_args,
2229 tuple<_Args2...> __second_args,
2230 __tuple_indices<_I1...>,
2231 __tuple_indices<_I2...>)
2232 : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2233 __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2237 #endif // _LIBCPP_HAS_NO_VARIADICS
2239 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2241 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2243 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2244 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2246 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2247 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2249 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2250 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2251 __is_nothrow_swappable<_T1>::value)
2254 swap(__first_, __x.__first_);
2258 template <class _T1, class _T2>
2259 class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2264 typedef _T1 _T1_param;
2265 typedef _T2 _T2_param;
2267 typedef _T1& _T1_reference;
2268 typedef _T2& _T2_reference;
2270 typedef const _T1& _T1_const_reference;
2271 typedef const _T2& _T2_const_reference;
2273 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2274 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2275 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2276 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2277 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2278 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2279 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2281 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2283 _LIBCPP_INLINE_VISIBILITY
2284 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2285 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2286 is_nothrow_copy_constructible<_T2>::value)
2287 : _T1(__p.first()), _T2(__p.second()) {}
2289 _LIBCPP_INLINE_VISIBILITY
2290 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2291 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2292 is_nothrow_copy_assignable<_T2>::value)
2294 _T1::operator=(__p.first());
2295 _T2::operator=(__p.second());
2299 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2301 _LIBCPP_INLINE_VISIBILITY
2302 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2303 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2304 is_nothrow_move_constructible<_T2>::value)
2305 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2307 _LIBCPP_INLINE_VISIBILITY
2308 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2309 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2310 is_nothrow_move_assignable<_T2>::value)
2312 _T1::operator=(_VSTD::move(__p.first()));
2313 _T2::operator=(_VSTD::move(__p.second()));
2317 #ifndef _LIBCPP_HAS_NO_VARIADICS
2319 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2320 _LIBCPP_INLINE_VISIBILITY
2321 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2322 tuple<_Args1...> __first_args,
2323 tuple<_Args2...> __second_args,
2324 __tuple_indices<_I1...>,
2325 __tuple_indices<_I2...>)
2326 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2327 _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2330 #endif // _LIBCPP_HAS_NO_VARIADICS
2332 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2334 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2336 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2337 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2339 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2340 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2342 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2343 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2344 __is_nothrow_swappable<_T1>::value)
2349 template <class _T1, class _T2>
2350 class __compressed_pair
2351 : private __libcpp_compressed_pair_imp<_T1, _T2>
2353 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2355 typedef typename base::_T1_param _T1_param;
2356 typedef typename base::_T2_param _T2_param;
2358 typedef typename base::_T1_reference _T1_reference;
2359 typedef typename base::_T2_reference _T2_reference;
2361 typedef typename base::_T1_const_reference _T1_const_reference;
2362 typedef typename base::_T2_const_reference _T2_const_reference;
2364 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2365 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2366 : base(_VSTD::forward<_T1_param>(__t1)) {}
2367 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2368 : base(_VSTD::forward<_T2_param>(__t2)) {}
2369 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2370 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2372 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2374 _LIBCPP_INLINE_VISIBILITY
2375 __compressed_pair(const __compressed_pair& __p)
2376 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2377 is_nothrow_copy_constructible<_T2>::value)
2380 _LIBCPP_INLINE_VISIBILITY
2381 __compressed_pair& operator=(const __compressed_pair& __p)
2382 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2383 is_nothrow_copy_assignable<_T2>::value)
2385 base::operator=(__p);
2389 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2390 _LIBCPP_INLINE_VISIBILITY
2391 __compressed_pair(__compressed_pair&& __p)
2392 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2393 is_nothrow_move_constructible<_T2>::value)
2394 : base(_VSTD::move(__p)) {}
2396 _LIBCPP_INLINE_VISIBILITY
2397 __compressed_pair& operator=(__compressed_pair&& __p)
2398 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2399 is_nothrow_move_assignable<_T2>::value)
2401 base::operator=(_VSTD::move(__p));
2405 #ifndef _LIBCPP_HAS_NO_VARIADICS
2407 template <class... _Args1, class... _Args2>
2408 _LIBCPP_INLINE_VISIBILITY
2409 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2410 tuple<_Args2...> __second_args)
2411 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2412 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2413 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2416 #endif // _LIBCPP_HAS_NO_VARIADICS
2418 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2420 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2422 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2423 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2425 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2426 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2428 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2429 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2430 __is_nothrow_swappable<_T1>::value)
2434 template <class _T1, class _T2>
2435 inline _LIBCPP_INLINE_VISIBILITY
2437 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2438 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2439 __is_nothrow_swappable<_T1>::value)
2442 // __same_or_less_cv_qualified
2444 template <class _Ptr1, class _Ptr2,
2445 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2446 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2449 struct __same_or_less_cv_qualified_imp
2450 : is_convertible<_Ptr1, _Ptr2> {};
2452 template <class _Ptr1, class _Ptr2>
2453 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2456 template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2457 !is_pointer<_Ptr1>::value>
2458 struct __same_or_less_cv_qualified
2459 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2461 template <class _Ptr1, class _Ptr2>
2462 struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2467 template <class _Tp>
2468 struct _LIBCPP_VISIBLE default_delete
2470 _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2471 template <class _Up>
2472 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2473 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2474 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2476 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2481 template <class _Tp>
2482 struct _LIBCPP_VISIBLE default_delete<_Tp[]>
2485 _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2486 template <class _Up>
2487 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2488 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2489 template <class _Up>
2490 _LIBCPP_INLINE_VISIBILITY
2491 void operator() (_Up* __ptr,
2492 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2494 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2499 template <class _Tp, class _Dp = default_delete<_Tp> >
2500 class _LIBCPP_VISIBLE unique_ptr
2503 typedef _Tp element_type;
2504 typedef _Dp deleter_type;
2505 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2507 __compressed_pair<pointer, deleter_type> __ptr_;
2509 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2510 unique_ptr(unique_ptr&);
2511 template <class _Up, class _Ep>
2512 unique_ptr(unique_ptr<_Up, _Ep>&);
2513 unique_ptr& operator=(unique_ptr&);
2514 template <class _Up, class _Ep>
2515 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2516 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2518 struct __nat {int __for_bool_;};
2520 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2521 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2523 _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2526 static_assert(!is_pointer<deleter_type>::value,
2527 "unique_ptr constructed with null function pointer deleter");
2529 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2532 static_assert(!is_pointer<deleter_type>::value,
2533 "unique_ptr constructed with null function pointer deleter");
2535 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2536 : __ptr_(_VSTD::move(__p))
2538 static_assert(!is_pointer<deleter_type>::value,
2539 "unique_ptr constructed with null function pointer deleter");
2542 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2543 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2544 is_reference<deleter_type>::value,
2546 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2548 : __ptr_(__p, __d) {}
2550 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2552 : __ptr_(__p, _VSTD::move(__d))
2554 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2556 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2557 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2558 template <class _Up, class _Ep>
2559 _LIBCPP_INLINE_VISIBILITY
2560 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2563 !is_array<_Up>::value &&
2564 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2565 is_convertible<_Ep, deleter_type>::value &&
2567 !is_reference<deleter_type>::value ||
2568 is_same<deleter_type, _Ep>::value
2571 >::type = __nat()) _NOEXCEPT
2572 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2574 template <class _Up>
2575 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2577 is_convertible<_Up*, _Tp*>::value &&
2578 is_same<_Dp, default_delete<_Tp> >::value,
2580 >::type = __nat()) _NOEXCEPT
2581 : __ptr_(__p.release())
2585 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2587 reset(__u.release());
2588 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2592 template <class _Up, class _Ep>
2593 _LIBCPP_INLINE_VISIBILITY
2596 !is_array<_Up>::value &&
2597 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2598 is_assignable<deleter_type&, _Ep&&>::value,
2601 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2603 reset(__u.release());
2604 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2607 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2609 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2611 return __rv<unique_ptr>(*this);
2614 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2615 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2617 template <class _Up, class _Ep>
2618 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2620 reset(__u.release());
2621 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2625 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2626 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2628 template <class _Up>
2629 _LIBCPP_INLINE_VISIBILITY
2631 is_convertible<_Up*, _Tp*>::value &&
2632 is_same<_Dp, default_delete<_Tp> >::value,
2635 operator=(auto_ptr<_Up> __p)
2636 {reset(__p.release()); return *this;}
2638 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2639 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2641 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2647 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2648 {return *__ptr_.first();}
2649 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2650 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2651 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2652 {return __ptr_.second();}
2653 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2654 {return __ptr_.second();}
2655 _LIBCPP_INLINE_VISIBILITY
2656 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2657 {return __ptr_.first() != nullptr;}
2659 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2661 pointer __t = __ptr_.first();
2662 __ptr_.first() = pointer();
2666 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2668 pointer __tmp = __ptr_.first();
2669 __ptr_.first() = __p;
2671 __ptr_.second()(__tmp);
2674 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2675 {__ptr_.swap(__u.__ptr_);}
2678 template <class _Tp, class _Dp>
2679 class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp>
2682 typedef _Tp element_type;
2683 typedef _Dp deleter_type;
2684 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2686 __compressed_pair<pointer, deleter_type> __ptr_;
2688 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2689 unique_ptr(unique_ptr&);
2690 template <class _Up>
2691 unique_ptr(unique_ptr<_Up>&);
2692 unique_ptr& operator=(unique_ptr&);
2693 template <class _Up>
2694 unique_ptr& operator=(unique_ptr<_Up>&);
2695 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2697 struct __nat {int __for_bool_;};
2699 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2700 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2702 _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2705 static_assert(!is_pointer<deleter_type>::value,
2706 "unique_ptr constructed with null function pointer deleter");
2708 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2711 static_assert(!is_pointer<deleter_type>::value,
2712 "unique_ptr constructed with null function pointer deleter");
2714 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2715 template <class _Pp,
2716 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2718 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2721 static_assert(!is_pointer<deleter_type>::value,
2722 "unique_ptr constructed with null function pointer deleter");
2725 template <class _Pp,
2726 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2728 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2729 is_reference<deleter_type>::value,
2731 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2733 : __ptr_(__p, __d) {}
2735 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2736 is_reference<deleter_type>::value,
2738 typename add_lvalue_reference<const deleter_type>::type>::type __d)
2740 : __ptr_(pointer(), __d) {}
2742 template <class _Pp,
2743 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2745 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2747 : __ptr_(__p, _VSTD::move(__d))
2749 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2752 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2754 : __ptr_(pointer(), _VSTD::move(__d))
2756 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2759 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2760 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2762 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2764 reset(__u.release());
2765 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2769 template <class _Up, class _Ep>
2770 _LIBCPP_INLINE_VISIBILITY
2771 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2774 is_array<_Up>::value &&
2775 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2776 && is_convertible<_Ep, deleter_type>::value &&
2778 !is_reference<deleter_type>::value ||
2779 is_same<deleter_type, _Ep>::value
2784 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2787 template <class _Up, class _Ep>
2788 _LIBCPP_INLINE_VISIBILITY
2791 is_array<_Up>::value &&
2792 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2793 is_assignable<deleter_type&, _Ep&&>::value,
2796 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2798 reset(__u.release());
2799 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2802 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2804 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2807 static_assert(!is_pointer<deleter_type>::value,
2808 "unique_ptr constructed with null function pointer deleter");
2811 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2812 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2814 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2815 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2817 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2819 return __rv<unique_ptr>(*this);
2822 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2823 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2825 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2827 reset(__u->release());
2828 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2832 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2833 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2835 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2841 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2842 {return __ptr_.first()[__i];}
2843 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2844 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2845 {return __ptr_.second();}
2846 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2847 {return __ptr_.second();}
2848 _LIBCPP_INLINE_VISIBILITY
2849 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2850 {return __ptr_.first() != nullptr;}
2852 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2854 pointer __t = __ptr_.first();
2855 __ptr_.first() = pointer();
2859 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2860 template <class _Pp,
2861 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2863 _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2865 pointer __tmp = __ptr_.first();
2866 __ptr_.first() = __p;
2868 __ptr_.second()(__tmp);
2870 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2872 pointer __tmp = __ptr_.first();
2873 __ptr_.first() = nullptr;
2875 __ptr_.second()(__tmp);
2877 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2879 pointer __tmp = __ptr_.first();
2880 __ptr_.first() = nullptr;
2882 __ptr_.second()(__tmp);
2884 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2885 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2887 pointer __tmp = __ptr_.first();
2888 __ptr_.first() = __p;
2890 __ptr_.second()(__tmp);
2892 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2894 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2897 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2898 template <class _Up>
2899 explicit unique_ptr(_Up);
2900 template <class _Up>
2902 typename conditional<
2903 is_reference<deleter_type>::value,
2905 typename add_lvalue_reference<const deleter_type>::type>::type,
2908 is_convertible<_Up, pointer>::value,
2911 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2914 template <class _Tp, class _Dp>
2915 inline _LIBCPP_INLINE_VISIBILITY
2917 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2919 template <class _T1, class _D1, class _T2, class _D2>
2920 inline _LIBCPP_INLINE_VISIBILITY
2922 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2924 template <class _T1, class _D1, class _T2, class _D2>
2925 inline _LIBCPP_INLINE_VISIBILITY
2927 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2929 template <class _T1, class _D1, class _T2, class _D2>
2930 inline _LIBCPP_INLINE_VISIBILITY
2932 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2934 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2935 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2936 typedef typename common_type<_P1, _P2>::type _V;
2937 return less<_V>()(__x.get(), __y.get());
2940 template <class _T1, class _D1, class _T2, class _D2>
2941 inline _LIBCPP_INLINE_VISIBILITY
2943 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2945 template <class _T1, class _D1, class _T2, class _D2>
2946 inline _LIBCPP_INLINE_VISIBILITY
2948 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2950 template <class _T1, class _D1, class _T2, class _D2>
2951 inline _LIBCPP_INLINE_VISIBILITY
2953 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2955 template <class _T1, class _D1>
2956 inline _LIBCPP_INLINE_VISIBILITY
2958 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2963 template <class _T1, class _D1>
2964 inline _LIBCPP_INLINE_VISIBILITY
2966 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2971 template <class _T1, class _D1>
2972 inline _LIBCPP_INLINE_VISIBILITY
2974 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2976 return static_cast<bool>(__x);
2979 template <class _T1, class _D1>
2980 inline _LIBCPP_INLINE_VISIBILITY
2982 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2984 return static_cast<bool>(__x);
2987 template <class _T1, class _D1>
2988 inline _LIBCPP_INLINE_VISIBILITY
2990 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2992 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2993 return less<_P1>()(__x.get(), nullptr);
2996 template <class _T1, class _D1>
2997 inline _LIBCPP_INLINE_VISIBILITY
2999 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3001 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3002 return less<_P1>()(nullptr, __x.get());
3005 template <class _T1, class _D1>
3006 inline _LIBCPP_INLINE_VISIBILITY
3008 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3010 return nullptr < __x;
3013 template <class _T1, class _D1>
3014 inline _LIBCPP_INLINE_VISIBILITY
3016 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3018 return __x < nullptr;
3021 template <class _T1, class _D1>
3022 inline _LIBCPP_INLINE_VISIBILITY
3024 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3026 return !(nullptr < __x);
3029 template <class _T1, class _D1>
3030 inline _LIBCPP_INLINE_VISIBILITY
3032 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3034 return !(__x < nullptr);
3037 template <class _T1, class _D1>
3038 inline _LIBCPP_INLINE_VISIBILITY
3040 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3042 return !(__x < nullptr);
3045 template <class _T1, class _D1>
3046 inline _LIBCPP_INLINE_VISIBILITY
3048 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3050 return !(nullptr < __x);
3053 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3055 template <class _Tp, class _Dp>
3056 inline _LIBCPP_INLINE_VISIBILITY
3057 unique_ptr<_Tp, _Dp>
3058 move(unique_ptr<_Tp, _Dp>& __t)
3060 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3065 template <class _Tp> struct hash;
3067 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3068 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
3069 // multiplication, which can be very slow on 32-bit systems.
3070 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3071 struct __murmur2_or_cityhash;
3073 template <class _Size>
3074 struct __murmur2_or_cityhash<_Size, 32>
3076 _Size operator()(const void* __key, _Size __len);
3080 template <class _Size>
3082 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3084 const _Size __m = 0x5bd1e995;
3085 const _Size __r = 24;
3087 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3088 for (; __len >= 4; __data += 4, __len -= 4)
3090 _Size __k = *(const _Size*)__data;
3100 __h ^= __data[2] << 16;
3102 __h ^= __data[1] << 8;
3113 template <class _Size>
3114 struct __murmur2_or_cityhash<_Size, 64>
3116 _Size operator()(const void* __key, _Size __len);
3119 // Some primes between 2^63 and 2^64.
3120 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3121 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3122 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3123 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3125 static _Size __rotate(_Size __val, int __shift) {
3126 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3129 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3130 return (__val >> __shift) | (__val << (64 - __shift));
3133 static _Size __shift_mix(_Size __val) {
3134 return __val ^ (__val >> 47);
3137 static _Size __hash_len_16(_Size __u, _Size __v) {
3138 const _Size __mul = 0x9ddfea08eb382d69ULL;
3139 _Size __a = (__u ^ __v) * __mul;
3141 _Size __b = (__v ^ __a) * __mul;
3147 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3149 const _Size __a = *(const _Size*)__s;
3150 const _Size __b = *(const _Size*)(__s + __len - 8);
3151 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3154 const uint32_t __a = *(const uint32_t*)(__s);
3155 const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3156 return __hash_len_16(__len + (__a << 3), __b);
3159 const unsigned char __a = __s[0];
3160 const unsigned char __b = __s[__len >> 1];
3161 const unsigned char __c = __s[__len - 1];
3162 const uint32_t __y = static_cast<uint32_t>(__a) +
3163 (static_cast<uint32_t>(__b) << 8);
3164 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3165 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3170 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3171 const _Size __a = *(const _Size*)(__s) * __k1;
3172 const _Size __b = *(const _Size*)(__s + 8);
3173 const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3174 const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3175 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3176 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3179 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3180 // Callers do best to use "random-looking" values for a and b.
3181 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3182 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3184 __b = __rotate(__b + __a + __z, 21);
3185 const _Size __c = __a;
3188 __b += __rotate(__a, 44);
3189 return pair<_Size, _Size>(__a + __z, __b + __c);
3192 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3193 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3194 const char* __s, _Size __a, _Size __b) {
3195 return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3196 *(const _Size*)(__s + 8),
3197 *(const _Size*)(__s + 16),
3198 *(const _Size*)(__s + 24),
3203 // Return an 8-byte hash for 33 to 64 bytes.
3204 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3205 _Size __z = *(const _Size*)(__s + 24);
3206 _Size __a = *(const _Size*)(__s) +
3207 (__len + *(const _Size*)(__s + __len - 16)) * __k0;
3208 _Size __b = __rotate(__a + __z, 52);
3209 _Size __c = __rotate(__a, 37);
3210 __a += *(const _Size*)(__s + 8);
3211 __c += __rotate(__a, 7);
3212 __a += *(const _Size*)(__s + 16);
3213 _Size __vf = __a + __z;
3214 _Size __vs = __b + __rotate(__a, 31) + __c;
3215 __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3216 __z += *(const _Size*)(__s + __len - 8);
3217 __b = __rotate(__a + __z, 52);
3218 __c = __rotate(__a, 37);
3219 __a += *(const _Size*)(__s + __len - 24);
3220 __c += __rotate(__a, 7);
3221 __a += *(const _Size*)(__s + __len - 16);
3222 _Size __wf = __a + __z;
3223 _Size __ws = __b + __rotate(__a, 31) + __c;
3224 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3225 return __shift_mix(__r * __k0 + __vs) * __k2;
3230 template <class _Size>
3232 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3234 const char* __s = static_cast<const char*>(__key);
3237 return __hash_len_0_to_16(__s, __len);
3239 return __hash_len_17_to_32(__s, __len);
3241 } else if (__len <= 64) {
3242 return __hash_len_33_to_64(__s, __len);
3245 // For strings over 64 bytes we hash the end first, and then as we
3246 // loop we keep 56 bytes of state: v, w, x, y, and z.
3247 _Size __x = *(const _Size*)(__s + __len - 40);
3248 _Size __y = *(const _Size*)(__s + __len - 16) +
3249 *(const _Size*)(__s + __len - 56);
3250 _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3251 *(const _Size*)(__s + __len - 24));
3252 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3253 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3254 __x = __x * __k1 + *(const _Size*)(__s);
3256 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3257 __len = (__len - 1) & ~static_cast<_Size>(63);
3259 __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3260 __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3262 __y += __v.first + *(const _Size*)(__s + 40);
3263 __z = __rotate(__z + __w.first, 33) * __k1;
3264 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3265 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3266 __y + *(const _Size*)(__s + 16));
3267 std::swap(__z, __x);
3270 } while (__len != 0);
3271 return __hash_len_16(
3272 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3273 __hash_len_16(__v.second, __w.second) + __x);
3276 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3277 struct __scalar_hash;
3279 template <class _Tp>
3280 struct __scalar_hash<_Tp, 0>
3281 : public unary_function<_Tp, size_t>
3283 _LIBCPP_INLINE_VISIBILITY
3284 size_t operator()(_Tp __v) const _NOEXCEPT
3297 template <class _Tp>
3298 struct __scalar_hash<_Tp, 1>
3299 : public unary_function<_Tp, size_t>
3301 _LIBCPP_INLINE_VISIBILITY
3302 size_t operator()(_Tp __v) const _NOEXCEPT
3314 template <class _Tp>
3315 struct __scalar_hash<_Tp, 2>
3316 : public unary_function<_Tp, size_t>
3318 _LIBCPP_INLINE_VISIBILITY
3319 size_t operator()(_Tp __v) const _NOEXCEPT
3331 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3335 template <class _Tp>
3336 struct __scalar_hash<_Tp, 3>
3337 : public unary_function<_Tp, size_t>
3339 _LIBCPP_INLINE_VISIBILITY
3340 size_t operator()(_Tp __v) const _NOEXCEPT
3353 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3357 template <class _Tp>
3358 struct __scalar_hash<_Tp, 4>
3359 : public unary_function<_Tp, size_t>
3361 _LIBCPP_INLINE_VISIBILITY
3362 size_t operator()(_Tp __v) const _NOEXCEPT
3376 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3381 struct _LIBCPP_VISIBLE hash<_Tp*>
3382 : public __scalar_hash<_Tp*>
3386 template <class _Tp, class _Dp>
3387 struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
3389 typedef unique_ptr<_Tp, _Dp> argument_type;
3390 typedef size_t result_type;
3391 _LIBCPP_INLINE_VISIBILITY
3392 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3394 typedef typename argument_type::pointer pointer;
3395 return hash<pointer>()(__ptr.get());
3404 template <class _Tp>
3405 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3406 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3408 template <class _Tp>
3409 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3412 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3414 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3417 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3419 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3422 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3425 template <class _Tp>
3426 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3427 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3429 template <class _Tp>
3430 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3431 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3433 template <class _Tp>
3434 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3435 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3438 template <class _Alloc>
3439 class __allocator_destructor
3441 typedef allocator_traits<_Alloc> __alloc_traits;
3443 typedef typename __alloc_traits::pointer pointer;
3444 typedef typename __alloc_traits::size_type size_type;
3449 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3451 : __alloc_(__a), __s_(__s) {}
3452 _LIBCPP_INLINE_VISIBILITY
3453 void operator()(pointer __p) _NOEXCEPT
3454 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3457 template <class _InputIterator, class _ForwardIterator>
3459 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3461 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3462 #ifndef _LIBCPP_NO_EXCEPTIONS
3463 _ForwardIterator __s = __r;
3467 for (; __f != __l; ++__f, ++__r)
3468 ::new(&*__r) value_type(*__f);
3469 #ifndef _LIBCPP_NO_EXCEPTIONS
3473 for (; __s != __r; ++__s)
3481 template <class _InputIterator, class _Size, class _ForwardIterator>
3483 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3485 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3486 #ifndef _LIBCPP_NO_EXCEPTIONS
3487 _ForwardIterator __s = __r;
3491 for (; __n > 0; ++__f, ++__r, --__n)
3492 ::new(&*__r) value_type(*__f);
3493 #ifndef _LIBCPP_NO_EXCEPTIONS
3497 for (; __s != __r; ++__s)
3505 template <class _ForwardIterator, class _Tp>
3507 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3509 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3510 #ifndef _LIBCPP_NO_EXCEPTIONS
3511 _ForwardIterator __s = __f;
3515 for (; __f != __l; ++__f)
3516 ::new(&*__f) value_type(__x);
3517 #ifndef _LIBCPP_NO_EXCEPTIONS
3521 for (; __s != __f; ++__s)
3528 template <class _ForwardIterator, class _Size, class _Tp>
3530 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3532 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3533 #ifndef _LIBCPP_NO_EXCEPTIONS
3534 _ForwardIterator __s = __f;
3538 for (; __n > 0; ++__f, --__n)
3539 ::new(&*__f) value_type(__x);
3540 #ifndef _LIBCPP_NO_EXCEPTIONS
3544 for (; __s != __f; ++__s)
3552 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3553 : public std::exception
3556 virtual ~bad_weak_ptr() _NOEXCEPT;
3557 virtual const char* what() const _NOEXCEPT;
3560 template<class _Tp> class weak_ptr;
3562 class __shared_count
3564 __shared_count(const __shared_count&);
3565 __shared_count& operator=(const __shared_count&);
3568 long __shared_owners_;
3569 virtual ~__shared_count();
3571 virtual void __on_zero_shared() _NOEXCEPT = 0;
3574 _LIBCPP_INLINE_VISIBILITY
3575 explicit __shared_count(long __refs = 0) _NOEXCEPT
3576 : __shared_owners_(__refs) {}
3578 void __add_shared() _NOEXCEPT;
3579 bool __release_shared() _NOEXCEPT;
3580 _LIBCPP_INLINE_VISIBILITY
3581 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3584 class __shared_weak_count
3585 : private __shared_count
3587 long __shared_weak_owners_;
3590 _LIBCPP_INLINE_VISIBILITY
3591 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3592 : __shared_count(__refs),
3593 __shared_weak_owners_(__refs) {}
3595 virtual ~__shared_weak_count();
3598 void __add_shared() _NOEXCEPT;
3599 void __add_weak() _NOEXCEPT;
3600 void __release_shared() _NOEXCEPT;
3601 void __release_weak() _NOEXCEPT;
3602 _LIBCPP_INLINE_VISIBILITY
3603 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3604 __shared_weak_count* lock() _NOEXCEPT;
3606 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3608 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3611 template <class _Tp, class _Dp, class _Alloc>
3612 class __shared_ptr_pointer
3613 : public __shared_weak_count
3615 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3617 _LIBCPP_INLINE_VISIBILITY
3618 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3619 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3621 #ifndef _LIBCPP_NO_RTTI
3622 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3626 virtual void __on_zero_shared() _NOEXCEPT;
3627 virtual void __on_zero_shared_weak() _NOEXCEPT;
3630 #ifndef _LIBCPP_NO_RTTI
3632 template <class _Tp, class _Dp, class _Alloc>
3634 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3636 return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3639 #endif // _LIBCPP_NO_RTTI
3641 template <class _Tp, class _Dp, class _Alloc>
3643 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3645 __data_.first().second()(__data_.first().first());
3646 __data_.first().second().~_Dp();
3649 template <class _Tp, class _Dp, class _Alloc>
3651 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3653 typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3654 __data_.second().~_Alloc();
3655 __a.deallocate(this, 1);
3658 template <class _Tp, class _Alloc>
3659 class __shared_ptr_emplace
3660 : public __shared_weak_count
3662 __compressed_pair<_Alloc, _Tp> __data_;
3664 #ifndef _LIBCPP_HAS_NO_VARIADICS
3666 _LIBCPP_INLINE_VISIBILITY
3667 __shared_ptr_emplace(_Alloc __a)
3668 : __data_(_VSTD::move(__a)) {}
3670 template <class ..._Args>
3671 _LIBCPP_INLINE_VISIBILITY
3672 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3673 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3674 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3676 #else // _LIBCPP_HAS_NO_VARIADICS
3678 _LIBCPP_INLINE_VISIBILITY
3679 __shared_ptr_emplace(_Alloc __a)
3682 template <class _A0>
3683 _LIBCPP_INLINE_VISIBILITY
3684 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3685 : __data_(__a, _Tp(__a0)) {}
3687 template <class _A0, class _A1>
3688 _LIBCPP_INLINE_VISIBILITY
3689 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3690 : __data_(__a, _Tp(__a0, __a1)) {}
3692 template <class _A0, class _A1, class _A2>
3693 _LIBCPP_INLINE_VISIBILITY
3694 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3695 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3697 #endif // _LIBCPP_HAS_NO_VARIADICS
3700 virtual void __on_zero_shared() _NOEXCEPT;
3701 virtual void __on_zero_shared_weak() _NOEXCEPT;
3703 _LIBCPP_INLINE_VISIBILITY
3704 _Tp* get() _NOEXCEPT {return &__data_.second();}
3707 template <class _Tp, class _Alloc>
3709 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3711 __data_.second().~_Tp();
3714 template <class _Tp, class _Alloc>
3716 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3718 typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3719 __data_.first().~_Alloc();
3720 __a.deallocate(this, 1);
3723 template<class _Tp> class enable_shared_from_this;
3726 class _LIBCPP_VISIBLE shared_ptr
3729 typedef _Tp element_type;
3731 element_type* __ptr_;
3732 __shared_weak_count* __cntrl_;
3734 struct __nat {int __for_bool_;};
3736 shared_ptr() _NOEXCEPT;
3737 shared_ptr(nullptr_t) _NOEXCEPT;
3739 class = typename enable_if
3741 is_convertible<_Yp*, element_type*>::value
3744 explicit shared_ptr(_Yp* __p);
3745 template<class _Yp, class _Dp,
3746 class = typename enable_if
3748 is_convertible<_Yp*, element_type*>::value
3751 shared_ptr(_Yp* __p, _Dp __d);
3752 template<class _Yp, class _Dp, class _Alloc,
3753 class = typename enable_if
3755 is_convertible<_Yp*, element_type*>::value
3758 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3759 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3760 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3761 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3762 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3764 shared_ptr(const shared_ptr<_Yp>& __r,
3765 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3767 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3768 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3769 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3770 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3772 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3773 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3774 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3775 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3777 class = typename enable_if
3779 is_convertible<_Yp*, element_type*>::value
3782 shared_ptr(auto_ptr<_Yp>&& __r);
3785 class = typename enable_if
3787 is_convertible<_Yp*, element_type*>::value
3790 shared_ptr(auto_ptr<_Yp> __r);
3792 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3793 template <class _Yp, class _Dp,
3794 class = typename enable_if
3796 !is_array<_Yp>::value &&
3797 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3800 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3801 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3802 template <class _Yp, class _Dp,
3803 class = typename enable_if
3805 !is_array<_Yp>::value &&
3806 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3809 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3810 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3811 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3812 template <class _Yp, class _Dp,
3813 class = typename enable_if
3815 !is_array<_Yp>::value &&
3816 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3818 > shared_ptr(unique_ptr<_Yp, _Dp>,
3819 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3820 template <class _Yp, class _Dp,
3821 class = typename enable_if
3823 !is_array<_Yp>::value &&
3824 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3827 shared_ptr(unique_ptr<_Yp, _Dp>,
3828 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3829 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3833 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3837 is_convertible<_Yp*, element_type*>::value,
3840 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3841 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3842 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3846 is_convertible<_Yp*, element_type*>::value,
3849 operator=(shared_ptr<_Yp>&& __r);
3853 !is_array<_Yp>::value &&
3854 is_convertible<_Yp*, element_type*>::value,
3857 operator=(auto_ptr<_Yp>&& __r);
3858 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3862 !is_array<_Yp>::value &&
3863 is_convertible<_Yp*, element_type*>::value,
3866 operator=(auto_ptr<_Yp> __r);
3868 template <class _Yp, class _Dp>
3871 !is_array<_Yp>::value &&
3872 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3875 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3876 operator=(unique_ptr<_Yp, _Dp>&& __r);
3877 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3878 operator=(unique_ptr<_Yp, _Dp> __r);
3881 void swap(shared_ptr& __r) _NOEXCEPT;
3882 void reset() _NOEXCEPT;
3886 is_convertible<_Yp*, element_type*>::value,
3890 template<class _Yp, class _Dp>
3893 is_convertible<_Yp*, element_type*>::value,
3896 reset(_Yp* __p, _Dp __d);
3897 template<class _Yp, class _Dp, class _Alloc>
3900 is_convertible<_Yp*, element_type*>::value,
3903 reset(_Yp* __p, _Dp __d, _Alloc __a);
3905 _LIBCPP_INLINE_VISIBILITY
3906 element_type* get() const _NOEXCEPT {return __ptr_;}
3907 _LIBCPP_INLINE_VISIBILITY
3908 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3910 _LIBCPP_INLINE_VISIBILITY
3911 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3912 _LIBCPP_INLINE_VISIBILITY
3913 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3914 _LIBCPP_INLINE_VISIBILITY
3915 bool unique() const _NOEXCEPT {return use_count() == 1;}
3916 _LIBCPP_INLINE_VISIBILITY
3917 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3918 template <class _Up>
3919 _LIBCPP_INLINE_VISIBILITY
3920 bool owner_before(shared_ptr<_Up> const& __p) const
3921 {return __cntrl_ < __p.__cntrl_;}
3922 template <class _Up>
3923 _LIBCPP_INLINE_VISIBILITY
3924 bool owner_before(weak_ptr<_Up> const& __p) const
3925 {return __cntrl_ < __p.__cntrl_;}
3927 #ifndef _LIBCPP_NO_RTTI
3928 template <class _Dp>
3929 _LIBCPP_INLINE_VISIBILITY
3930 _Dp* __get_deleter() const _NOEXCEPT
3931 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3932 #endif // _LIBCPP_NO_RTTI
3934 #ifndef _LIBCPP_HAS_NO_VARIADICS
3936 template<class ..._Args>
3939 make_shared(_Args&& ...__args);
3941 template<class _Alloc, class ..._Args>
3944 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3946 #else // _LIBCPP_HAS_NO_VARIADICS
3948 static shared_ptr<_Tp> make_shared();
3951 static shared_ptr<_Tp> make_shared(_A0&);
3953 template<class _A0, class _A1>
3954 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3956 template<class _A0, class _A1, class _A2>
3957 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3959 template<class _Alloc>
3960 static shared_ptr<_Tp>
3961 allocate_shared(const _Alloc& __a);
3963 template<class _Alloc, class _A0>
3964 static shared_ptr<_Tp>
3965 allocate_shared(const _Alloc& __a, _A0& __a0);
3967 template<class _Alloc, class _A0, class _A1>
3968 static shared_ptr<_Tp>
3969 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3971 template<class _Alloc, class _A0, class _A1, class _A2>
3972 static shared_ptr<_Tp>
3973 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3975 #endif // _LIBCPP_HAS_NO_VARIADICS
3979 template <class _Yp>
3980 _LIBCPP_INLINE_VISIBILITY
3982 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
3985 __e->__weak_this_ = *this;
3988 _LIBCPP_INLINE_VISIBILITY
3989 void __enable_weak_this(const void*) _NOEXCEPT {}
3991 template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
3992 template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
3996 inline _LIBCPP_INLINE_VISIBILITY
3997 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4004 inline _LIBCPP_INLINE_VISIBILITY
4005 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4012 template<class _Yp, class>
4013 shared_ptr<_Tp>::shared_ptr(_Yp* __p)
4016 unique_ptr<_Yp> __hold(__p);
4017 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4018 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4020 __enable_weak_this(__p);
4024 template<class _Yp, class _Dp, class>
4025 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4028 #ifndef _LIBCPP_NO_EXCEPTIONS
4031 #endif // _LIBCPP_NO_EXCEPTIONS
4032 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4033 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4034 __enable_weak_this(__p);
4035 #ifndef _LIBCPP_NO_EXCEPTIONS
4042 #endif // _LIBCPP_NO_EXCEPTIONS
4047 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4050 #ifndef _LIBCPP_NO_EXCEPTIONS
4053 #endif // _LIBCPP_NO_EXCEPTIONS
4054 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4055 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4056 #ifndef _LIBCPP_NO_EXCEPTIONS
4063 #endif // _LIBCPP_NO_EXCEPTIONS
4067 template<class _Yp, class _Dp, class _Alloc, class>
4068 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4071 #ifndef _LIBCPP_NO_EXCEPTIONS
4074 #endif // _LIBCPP_NO_EXCEPTIONS
4075 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4076 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4077 typedef __allocator_destructor<_A2> _D2;
4079 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4080 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4081 __cntrl_ = __hold2.release();
4082 __enable_weak_this(__p);
4083 #ifndef _LIBCPP_NO_EXCEPTIONS
4090 #endif // _LIBCPP_NO_EXCEPTIONS
4094 template<class _Dp, class _Alloc>
4095 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4098 #ifndef _LIBCPP_NO_EXCEPTIONS
4101 #endif // _LIBCPP_NO_EXCEPTIONS
4102 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4103 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4104 typedef __allocator_destructor<_A2> _D2;
4106 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4107 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4108 __cntrl_ = __hold2.release();
4109 #ifndef _LIBCPP_NO_EXCEPTIONS
4116 #endif // _LIBCPP_NO_EXCEPTIONS
4121 inline _LIBCPP_INLINE_VISIBILITY
4122 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4124 __cntrl_(__r.__cntrl_)
4127 __cntrl_->__add_shared();
4131 inline _LIBCPP_INLINE_VISIBILITY
4132 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4133 : __ptr_(__r.__ptr_),
4134 __cntrl_(__r.__cntrl_)
4137 __cntrl_->__add_shared();
4142 inline _LIBCPP_INLINE_VISIBILITY
4143 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4144 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4146 : __ptr_(__r.__ptr_),
4147 __cntrl_(__r.__cntrl_)
4150 __cntrl_->__add_shared();
4153 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4156 inline _LIBCPP_INLINE_VISIBILITY
4157 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4158 : __ptr_(__r.__ptr_),
4159 __cntrl_(__r.__cntrl_)
4167 inline _LIBCPP_INLINE_VISIBILITY
4168 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4169 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4171 : __ptr_(__r.__ptr_),
4172 __cntrl_(__r.__cntrl_)
4178 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4181 template<class _Yp, class>
4182 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4183 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4185 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4189 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4190 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4191 __enable_weak_this(__r.get());
4196 template <class _Yp, class _Dp, class>
4197 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4198 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4200 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4202 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4205 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4206 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4207 __enable_weak_this(__r.get());
4212 template <class _Yp, class _Dp, class>
4213 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4214 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4216 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4218 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4221 typedef __shared_ptr_pointer<_Yp*,
4222 reference_wrapper<typename remove_reference<_Dp>::type>,
4223 allocator<_Yp> > _CntrlBlk;
4224 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4225 __enable_weak_this(__r.get());
4229 #ifndef _LIBCPP_HAS_NO_VARIADICS
4232 template<class ..._Args>
4234 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4236 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4237 typedef allocator<_CntrlBlk> _A2;
4238 typedef __allocator_destructor<_A2> _D2;
4240 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4241 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4242 shared_ptr<_Tp> __r;
4243 __r.__ptr_ = __hold2.get()->get();
4244 __r.__cntrl_ = __hold2.release();
4245 __r.__enable_weak_this(__r.__ptr_);
4250 template<class _Alloc, class ..._Args>
4252 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4254 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4255 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4256 typedef __allocator_destructor<_A2> _D2;
4258 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4259 ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4260 shared_ptr<_Tp> __r;
4261 __r.__ptr_ = __hold2.get()->get();
4262 __r.__cntrl_ = __hold2.release();
4263 __r.__enable_weak_this(__r.__ptr_);
4267 #else // _LIBCPP_HAS_NO_VARIADICS
4271 shared_ptr<_Tp>::make_shared()
4273 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4274 typedef allocator<_CntrlBlk> _Alloc2;
4275 typedef __allocator_destructor<_Alloc2> _D2;
4277 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4278 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4279 shared_ptr<_Tp> __r;
4280 __r.__ptr_ = __hold2.get()->get();
4281 __r.__cntrl_ = __hold2.release();
4282 __r.__enable_weak_this(__r.__ptr_);
4289 shared_ptr<_Tp>::make_shared(_A0& __a0)
4291 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4292 typedef allocator<_CntrlBlk> _Alloc2;
4293 typedef __allocator_destructor<_Alloc2> _D2;
4295 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4296 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4297 shared_ptr<_Tp> __r;
4298 __r.__ptr_ = __hold2.get()->get();
4299 __r.__cntrl_ = __hold2.release();
4300 __r.__enable_weak_this(__r.__ptr_);
4305 template<class _A0, class _A1>
4307 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4309 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4310 typedef allocator<_CntrlBlk> _Alloc2;
4311 typedef __allocator_destructor<_Alloc2> _D2;
4313 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4314 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4315 shared_ptr<_Tp> __r;
4316 __r.__ptr_ = __hold2.get()->get();
4317 __r.__cntrl_ = __hold2.release();
4318 __r.__enable_weak_this(__r.__ptr_);
4323 template<class _A0, class _A1, class _A2>
4325 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4327 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4328 typedef allocator<_CntrlBlk> _Alloc2;
4329 typedef __allocator_destructor<_Alloc2> _D2;
4331 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4332 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4333 shared_ptr<_Tp> __r;
4334 __r.__ptr_ = __hold2.get()->get();
4335 __r.__cntrl_ = __hold2.release();
4336 __r.__enable_weak_this(__r.__ptr_);
4341 template<class _Alloc>
4343 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4345 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4346 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4347 typedef __allocator_destructor<_Alloc2> _D2;
4348 _Alloc2 __alloc2(__a);
4349 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4350 ::new(__hold2.get()) _CntrlBlk(__a);
4351 shared_ptr<_Tp> __r;
4352 __r.__ptr_ = __hold2.get()->get();
4353 __r.__cntrl_ = __hold2.release();
4354 __r.__enable_weak_this(__r.__ptr_);
4359 template<class _Alloc, class _A0>
4361 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4363 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4364 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4365 typedef __allocator_destructor<_Alloc2> _D2;
4366 _Alloc2 __alloc2(__a);
4367 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4368 ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4369 shared_ptr<_Tp> __r;
4370 __r.__ptr_ = __hold2.get()->get();
4371 __r.__cntrl_ = __hold2.release();
4372 __r.__enable_weak_this(__r.__ptr_);
4377 template<class _Alloc, class _A0, class _A1>
4379 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4381 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4382 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4383 typedef __allocator_destructor<_Alloc2> _D2;
4384 _Alloc2 __alloc2(__a);
4385 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4386 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4387 shared_ptr<_Tp> __r;
4388 __r.__ptr_ = __hold2.get()->get();
4389 __r.__cntrl_ = __hold2.release();
4390 __r.__enable_weak_this(__r.__ptr_);
4395 template<class _Alloc, class _A0, class _A1, class _A2>
4397 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4399 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4400 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4401 typedef __allocator_destructor<_Alloc2> _D2;
4402 _Alloc2 __alloc2(__a);
4403 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4404 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4405 shared_ptr<_Tp> __r;
4406 __r.__ptr_ = __hold2.get()->get();
4407 __r.__cntrl_ = __hold2.release();
4408 __r.__enable_weak_this(__r.__ptr_);
4412 #endif // _LIBCPP_HAS_NO_VARIADICS
4415 shared_ptr<_Tp>::~shared_ptr()
4418 __cntrl_->__release_shared();
4422 inline _LIBCPP_INLINE_VISIBILITY
4424 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4426 shared_ptr(__r).swap(*this);
4432 inline _LIBCPP_INLINE_VISIBILITY
4435 is_convertible<_Yp*, _Tp*>::value,
4438 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4440 shared_ptr(__r).swap(*this);
4444 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4447 inline _LIBCPP_INLINE_VISIBILITY
4449 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4451 shared_ptr(_VSTD::move(__r)).swap(*this);
4457 inline _LIBCPP_INLINE_VISIBILITY
4460 is_convertible<_Yp*, _Tp*>::value,
4463 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4465 shared_ptr(_VSTD::move(__r)).swap(*this);
4471 inline _LIBCPP_INLINE_VISIBILITY
4474 !is_array<_Yp>::value &&
4475 is_convertible<_Yp*, _Tp*>::value,
4478 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4480 shared_ptr(_VSTD::move(__r)).swap(*this);
4485 template <class _Yp, class _Dp>
4486 inline _LIBCPP_INLINE_VISIBILITY
4489 !is_array<_Yp>::value &&
4490 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4493 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4495 shared_ptr(_VSTD::move(__r)).swap(*this);
4499 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4503 inline _LIBCPP_INLINE_VISIBILITY
4506 !is_array<_Yp>::value &&
4507 is_convertible<_Yp*, _Tp*>::value,
4510 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4512 shared_ptr(__r).swap(*this);
4517 template <class _Yp, class _Dp>
4518 inline _LIBCPP_INLINE_VISIBILITY
4521 !is_array<_Yp>::value &&
4522 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4525 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4527 shared_ptr(_VSTD::move(__r)).swap(*this);
4531 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4534 inline _LIBCPP_INLINE_VISIBILITY
4536 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4538 _VSTD::swap(__ptr_, __r.__ptr_);
4539 _VSTD::swap(__cntrl_, __r.__cntrl_);
4543 inline _LIBCPP_INLINE_VISIBILITY
4545 shared_ptr<_Tp>::reset() _NOEXCEPT
4547 shared_ptr().swap(*this);
4552 inline _LIBCPP_INLINE_VISIBILITY
4555 is_convertible<_Yp*, _Tp*>::value,
4558 shared_ptr<_Tp>::reset(_Yp* __p)
4560 shared_ptr(__p).swap(*this);
4564 template<class _Yp, class _Dp>
4565 inline _LIBCPP_INLINE_VISIBILITY
4568 is_convertible<_Yp*, _Tp*>::value,
4571 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4573 shared_ptr(__p, __d).swap(*this);
4577 template<class _Yp, class _Dp, class _Alloc>
4578 inline _LIBCPP_INLINE_VISIBILITY
4581 is_convertible<_Yp*, _Tp*>::value,
4584 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4586 shared_ptr(__p, __d, __a).swap(*this);
4589 #ifndef _LIBCPP_HAS_NO_VARIADICS
4591 template<class _Tp, class ..._Args>
4592 inline _LIBCPP_INLINE_VISIBILITY
4595 !is_array<_Tp>::value,
4598 make_shared(_Args&& ...__args)
4600 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4603 template<class _Tp, class _Alloc, class ..._Args>
4604 inline _LIBCPP_INLINE_VISIBILITY
4607 !is_array<_Tp>::value,
4610 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4612 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4615 #else // _LIBCPP_HAS_NO_VARIADICS
4618 inline _LIBCPP_INLINE_VISIBILITY
4622 return shared_ptr<_Tp>::make_shared();
4625 template<class _Tp, class _A0>
4626 inline _LIBCPP_INLINE_VISIBILITY
4628 make_shared(_A0& __a0)
4630 return shared_ptr<_Tp>::make_shared(__a0);
4633 template<class _Tp, class _A0, class _A1>
4634 inline _LIBCPP_INLINE_VISIBILITY
4636 make_shared(_A0& __a0, _A1& __a1)
4638 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4641 template<class _Tp, class _A0, class _A1, class _A2>
4642 inline _LIBCPP_INLINE_VISIBILITY
4644 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4646 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4649 template<class _Tp, class _Alloc>
4650 inline _LIBCPP_INLINE_VISIBILITY
4652 allocate_shared(const _Alloc& __a)
4654 return shared_ptr<_Tp>::allocate_shared(__a);
4657 template<class _Tp, class _Alloc, class _A0>
4658 inline _LIBCPP_INLINE_VISIBILITY
4660 allocate_shared(const _Alloc& __a, _A0& __a0)
4662 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4665 template<class _Tp, class _Alloc, class _A0, class _A1>
4666 inline _LIBCPP_INLINE_VISIBILITY
4668 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4670 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4673 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4674 inline _LIBCPP_INLINE_VISIBILITY
4676 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4678 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4681 #endif // _LIBCPP_HAS_NO_VARIADICS
4683 template<class _Tp, class _Up>
4684 inline _LIBCPP_INLINE_VISIBILITY
4686 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4688 return __x.get() == __y.get();
4691 template<class _Tp, class _Up>
4692 inline _LIBCPP_INLINE_VISIBILITY
4694 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4696 return !(__x == __y);
4699 template<class _Tp, class _Up>
4700 inline _LIBCPP_INLINE_VISIBILITY
4702 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4704 typedef typename common_type<_Tp*, _Up*>::type _V;
4705 return less<_V>()(__x.get(), __y.get());
4708 template<class _Tp, class _Up>
4709 inline _LIBCPP_INLINE_VISIBILITY
4711 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4716 template<class _Tp, class _Up>
4717 inline _LIBCPP_INLINE_VISIBILITY
4719 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4721 return !(__y < __x);
4724 template<class _Tp, class _Up>
4725 inline _LIBCPP_INLINE_VISIBILITY
4727 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4729 return !(__x < __y);
4733 inline _LIBCPP_INLINE_VISIBILITY
4735 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4741 inline _LIBCPP_INLINE_VISIBILITY
4743 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4749 inline _LIBCPP_INLINE_VISIBILITY
4751 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4753 return static_cast<bool>(__x);
4757 inline _LIBCPP_INLINE_VISIBILITY
4759 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4761 return static_cast<bool>(__x);
4765 inline _LIBCPP_INLINE_VISIBILITY
4767 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4769 return less<_Tp*>()(__x.get(), nullptr);
4773 inline _LIBCPP_INLINE_VISIBILITY
4775 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4777 return less<_Tp*>()(nullptr, __x.get());
4781 inline _LIBCPP_INLINE_VISIBILITY
4783 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4785 return nullptr < __x;
4789 inline _LIBCPP_INLINE_VISIBILITY
4791 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4793 return __x < nullptr;
4797 inline _LIBCPP_INLINE_VISIBILITY
4799 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4801 return !(nullptr < __x);
4805 inline _LIBCPP_INLINE_VISIBILITY
4807 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4809 return !(__x < nullptr);
4813 inline _LIBCPP_INLINE_VISIBILITY
4815 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4817 return !(__x < nullptr);
4821 inline _LIBCPP_INLINE_VISIBILITY
4823 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4825 return !(nullptr < __x);
4829 inline _LIBCPP_INLINE_VISIBILITY
4831 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4836 template<class _Tp, class _Up>
4837 inline _LIBCPP_INLINE_VISIBILITY
4840 !is_array<_Tp>::value && !is_array<_Up>::value,
4843 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4845 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4848 template<class _Tp, class _Up>
4849 inline _LIBCPP_INLINE_VISIBILITY
4852 !is_array<_Tp>::value && !is_array<_Up>::value,
4855 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4857 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4858 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4861 template<class _Tp, class _Up>
4864 is_array<_Tp>::value == is_array<_Up>::value,
4867 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4869 typedef typename remove_extent<_Tp>::type _RTp;
4870 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4873 #ifndef _LIBCPP_NO_RTTI
4875 template<class _Dp, class _Tp>
4876 inline _LIBCPP_INLINE_VISIBILITY
4878 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4880 return __p.template __get_deleter<_Dp>();
4883 #endif // _LIBCPP_NO_RTTI
4886 class _LIBCPP_VISIBLE weak_ptr
4889 typedef _Tp element_type;
4891 element_type* __ptr_;
4892 __shared_weak_count* __cntrl_;
4895 weak_ptr() _NOEXCEPT;
4896 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4897 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4899 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4900 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4901 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4904 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4905 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4906 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4907 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4909 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4912 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4916 is_convertible<_Yp*, element_type*>::value,
4919 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4921 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4923 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4927 is_convertible<_Yp*, element_type*>::value,
4930 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4932 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4937 is_convertible<_Yp*, element_type*>::value,
4940 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4942 void swap(weak_ptr& __r) _NOEXCEPT;
4943 void reset() _NOEXCEPT;
4945 _LIBCPP_INLINE_VISIBILITY
4946 long use_count() const _NOEXCEPT
4947 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4948 _LIBCPP_INLINE_VISIBILITY
4949 bool expired() const _NOEXCEPT
4950 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4951 shared_ptr<_Tp> lock() const _NOEXCEPT;
4953 _LIBCPP_INLINE_VISIBILITY
4954 bool owner_before(const shared_ptr<_Up>& __r) const
4955 {return __cntrl_ < __r.__cntrl_;}
4957 _LIBCPP_INLINE_VISIBILITY
4958 bool owner_before(const weak_ptr<_Up>& __r) const
4959 {return __cntrl_ < __r.__cntrl_;}
4961 template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
4962 template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
4966 inline _LIBCPP_INLINE_VISIBILITY
4967 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4974 inline _LIBCPP_INLINE_VISIBILITY
4975 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
4976 : __ptr_(__r.__ptr_),
4977 __cntrl_(__r.__cntrl_)
4980 __cntrl_->__add_weak();
4985 inline _LIBCPP_INLINE_VISIBILITY
4986 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
4987 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4989 : __ptr_(__r.__ptr_),
4990 __cntrl_(__r.__cntrl_)
4993 __cntrl_->__add_weak();
4998 inline _LIBCPP_INLINE_VISIBILITY
4999 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5000 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5002 : __ptr_(__r.__ptr_),
5003 __cntrl_(__r.__cntrl_)
5006 __cntrl_->__add_weak();
5009 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5012 inline _LIBCPP_INLINE_VISIBILITY
5013 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5014 : __ptr_(__r.__ptr_),
5015 __cntrl_(__r.__cntrl_)
5023 inline _LIBCPP_INLINE_VISIBILITY
5024 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5025 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5027 : __ptr_(__r.__ptr_),
5028 __cntrl_(__r.__cntrl_)
5034 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5037 weak_ptr<_Tp>::~weak_ptr()
5040 __cntrl_->__release_weak();
5044 inline _LIBCPP_INLINE_VISIBILITY
5046 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5048 weak_ptr(__r).swap(*this);
5054 inline _LIBCPP_INLINE_VISIBILITY
5057 is_convertible<_Yp*, _Tp*>::value,
5060 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5062 weak_ptr(__r).swap(*this);
5066 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5069 inline _LIBCPP_INLINE_VISIBILITY
5071 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5073 weak_ptr(_VSTD::move(__r)).swap(*this);
5079 inline _LIBCPP_INLINE_VISIBILITY
5082 is_convertible<_Yp*, _Tp*>::value,
5085 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5087 weak_ptr(_VSTD::move(__r)).swap(*this);
5091 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5095 inline _LIBCPP_INLINE_VISIBILITY
5098 is_convertible<_Yp*, _Tp*>::value,
5101 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5103 weak_ptr(__r).swap(*this);
5108 inline _LIBCPP_INLINE_VISIBILITY
5110 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5112 _VSTD::swap(__ptr_, __r.__ptr_);
5113 _VSTD::swap(__cntrl_, __r.__cntrl_);
5117 inline _LIBCPP_INLINE_VISIBILITY
5119 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5125 inline _LIBCPP_INLINE_VISIBILITY
5127 weak_ptr<_Tp>::reset() _NOEXCEPT
5129 weak_ptr().swap(*this);
5134 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5135 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5136 : __ptr_(__r.__ptr_),
5137 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5140 #ifndef _LIBCPP_NO_EXCEPTIONS
5141 throw bad_weak_ptr();
5143 assert(!"bad_weak_ptr");
5149 weak_ptr<_Tp>::lock() const _NOEXCEPT
5151 shared_ptr<_Tp> __r;
5152 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5154 __r.__ptr_ = __ptr_;
5158 template <class _Tp> struct owner_less;
5160 template <class _Tp>
5161 struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> >
5162 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5164 typedef bool result_type;
5165 _LIBCPP_INLINE_VISIBILITY
5166 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5167 {return __x.owner_before(__y);}
5168 _LIBCPP_INLINE_VISIBILITY
5169 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5170 {return __x.owner_before(__y);}
5171 _LIBCPP_INLINE_VISIBILITY
5172 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5173 {return __x.owner_before(__y);}
5176 template <class _Tp>
5177 struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> >
5178 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5180 typedef bool result_type;
5181 _LIBCPP_INLINE_VISIBILITY
5182 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5183 {return __x.owner_before(__y);}
5184 _LIBCPP_INLINE_VISIBILITY
5185 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5186 {return __x.owner_before(__y);}
5187 _LIBCPP_INLINE_VISIBILITY
5188 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5189 {return __x.owner_before(__y);}
5193 class _LIBCPP_VISIBLE enable_shared_from_this
5195 mutable weak_ptr<_Tp> __weak_this_;
5197 _LIBCPP_INLINE_VISIBILITY
5198 enable_shared_from_this() _NOEXCEPT {}
5199 _LIBCPP_INLINE_VISIBILITY
5200 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5201 _LIBCPP_INLINE_VISIBILITY
5202 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5204 _LIBCPP_INLINE_VISIBILITY
5205 ~enable_shared_from_this() {}
5207 _LIBCPP_INLINE_VISIBILITY
5208 shared_ptr<_Tp> shared_from_this()
5209 {return shared_ptr<_Tp>(__weak_this_);}
5210 _LIBCPP_INLINE_VISIBILITY
5211 shared_ptr<_Tp const> shared_from_this() const
5212 {return shared_ptr<const _Tp>(__weak_this_);}
5214 template <class _Up> friend class shared_ptr;
5217 template <class _Tp>
5218 struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
5220 typedef shared_ptr<_Tp> argument_type;
5221 typedef size_t result_type;
5222 _LIBCPP_INLINE_VISIBILITY
5223 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5225 return hash<_Tp*>()(__ptr.get());
5229 template<class _CharT, class _Traits, class _Yp>
5230 inline _LIBCPP_INLINE_VISIBILITY
5231 basic_ostream<_CharT, _Traits>&
5232 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5235 struct _LIBCPP_VISIBLE pointer_safety
5246 _LIBCPP_INLINE_VISIBILITY
5247 pointer_safety(_ __v) : __v_(__v) {}
5248 _LIBCPP_INLINE_VISIBILITY
5249 operator int() const {return __v_;}
5252 void declare_reachable(void* __p);
5253 void declare_no_pointers(char* __p, size_t __n);
5254 void undeclare_no_pointers(char* __p, size_t __n);
5255 pointer_safety get_pointer_safety() _NOEXCEPT;
5256 void* __undeclare_reachable(void* __p);
5258 template <class _Tp>
5259 inline _LIBCPP_INLINE_VISIBILITY
5261 undeclare_reachable(_Tp* __p)
5263 return static_cast<_Tp*>(__undeclare_reachable(__p));
5266 void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5268 _LIBCPP_END_NAMESPACE_STD
5270 #endif // _LIBCPP_MEMORY