2 //===-------------------------- memory ------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_MEMORY
11 #define _LIBCPP_MEMORY
19 struct allocator_arg_t { };
20 inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
22 template <class T, class Alloc> struct uses_allocator;
28 typedef <details> element_type;
29 typedef <details> difference_type;
31 template <class U> using rebind = <details>;
33 static pointer pointer_to(<details>);
37 struct pointer_traits<T*>
40 typedef T element_type;
41 typedef ptrdiff_t difference_type;
43 template <class U> using rebind = U*;
45 static pointer pointer_to(<details>) noexcept; // constexpr in C++20
48 template <class T> constexpr T* to_address(T* p) noexcept; // C++20
49 template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
51 template <class Alloc>
52 struct allocator_traits
54 typedef Alloc allocator_type;
55 typedef typename allocator_type::value_type
58 typedef Alloc::pointer | value_type* pointer;
59 typedef Alloc::const_pointer
60 | pointer_traits<pointer>::rebind<const value_type>
62 typedef Alloc::void_pointer
63 | pointer_traits<pointer>::rebind<void>
65 typedef Alloc::const_void_pointer
66 | pointer_traits<pointer>::rebind<const void>
68 typedef Alloc::difference_type
69 | pointer_traits<pointer>::difference_type
71 typedef Alloc::size_type
72 | make_unsigned<difference_type>::type
74 typedef Alloc::propagate_on_container_copy_assignment
75 | false_type propagate_on_container_copy_assignment;
76 typedef Alloc::propagate_on_container_move_assignment
77 | false_type propagate_on_container_move_assignment;
78 typedef Alloc::propagate_on_container_swap
79 | false_type propagate_on_container_swap;
80 typedef Alloc::is_always_equal
81 | is_empty is_always_equal;
83 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
84 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
86 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
87 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
89 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
91 template <class T, class... Args>
92 static void construct(allocator_type& a, T* p, Args&&... args);
95 static void destroy(allocator_type& a, T* p);
97 static size_type max_size(const allocator_type& a); // noexcept in C++14
100 select_on_container_copy_construction(const allocator_type& a);
104 class allocator<void>
107 typedef void* pointer;
108 typedef const void* const_pointer;
109 typedef void value_type;
111 template <class _Up> struct rebind {typedef allocator<_Up> other;};
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
121 typedef const T* const_pointer;
122 typedef typename add_lvalue_reference<T>::type reference;
123 typedef typename add_lvalue_reference<const T>::type const_reference;
124 typedef T value_type;
126 template <class U> struct rebind {typedef allocator<U> other;};
128 constexpr allocator() noexcept; // constexpr in C++20
129 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
131 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
133 pointer address(reference x) const noexcept;
134 const_pointer address(const_reference x) const noexcept;
135 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
136 void deallocate(pointer p, size_type n) noexcept;
137 size_type max_size() const noexcept;
138 template<class U, class... Args>
139 void construct(U* p, Args&&... args);
144 template <class T, class U>
145 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
147 template <class T, class U>
148 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
150 template <class OutputIterator, class T>
151 class raw_storage_iterator
152 : public iterator<output_iterator_tag,
153 T, // purposefully not C++03
154 ptrdiff_t, // purposefully not C++03
155 T*, // purposefully not C++03
156 raw_storage_iterator&> // purposefully not C++03
159 explicit raw_storage_iterator(OutputIterator x);
160 raw_storage_iterator& operator*();
161 raw_storage_iterator& operator=(const T& element);
162 raw_storage_iterator& operator++();
163 raw_storage_iterator operator++(int);
166 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
167 template <class T> void return_temporary_buffer(T* p) noexcept;
169 template <class T> T* addressof(T& r) noexcept;
170 template <class T> T* addressof(const T&& r) noexcept = delete;
172 template <class InputIterator, class ForwardIterator>
174 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
176 template <class InputIterator, class Size, class ForwardIterator>
178 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
180 template <class ForwardIterator, class T>
181 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
183 template <class ForwardIterator, class Size, class T>
185 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
188 void destroy_at(T* location);
190 template <class ForwardIterator>
191 void destroy(ForwardIterator first, ForwardIterator last);
193 template <class ForwardIterator, class Size>
194 ForwardIterator destroy_n(ForwardIterator first, Size n);
196 template <class InputIterator, class ForwardIterator>
197 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
199 template <class InputIterator, class Size, class ForwardIterator>
200 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
202 template <class ForwardIterator>
203 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
205 template <class ForwardIterator, class Size>
206 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
208 template <class ForwardIterator>
209 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
211 template <class ForwardIterator, class Size>
212 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
214 template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
217 class auto_ptr // deprecated in C++11, removed in C++17
220 typedef X element_type;
222 explicit auto_ptr(X* p =0) throw();
223 auto_ptr(auto_ptr&) throw();
224 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
225 auto_ptr& operator=(auto_ptr&) throw();
226 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
227 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
230 typename add_lvalue_reference<X>::type operator*() const throw();
231 X* operator->() const throw();
232 X* get() const throw();
233 X* release() throw();
234 void reset(X* p =0) throw();
236 auto_ptr(auto_ptr_ref<X>) throw();
237 template<class Y> operator auto_ptr_ref<Y>() throw();
238 template<class Y> operator auto_ptr<Y>() throw();
242 struct default_delete
244 constexpr default_delete() noexcept = default;
245 template <class U> default_delete(const default_delete<U>&) noexcept;
247 void operator()(T*) const noexcept;
251 struct default_delete<T[]>
253 constexpr default_delete() noexcept = default;
254 void operator()(T*) const noexcept;
255 template <class U> void operator()(U*) const = delete;
258 template <class T, class D = default_delete<T>>
262 typedef see below pointer;
263 typedef T element_type;
264 typedef D deleter_type;
267 constexpr unique_ptr() noexcept;
268 explicit unique_ptr(pointer p) noexcept;
269 unique_ptr(pointer p, see below d1) noexcept;
270 unique_ptr(pointer p, see below d2) noexcept;
271 unique_ptr(unique_ptr&& u) noexcept;
272 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
273 template <class U, class E>
274 unique_ptr(unique_ptr<U, E>&& u) noexcept;
276 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
282 unique_ptr& operator=(unique_ptr&& u) noexcept;
283 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
284 unique_ptr& operator=(nullptr_t) noexcept;
287 typename add_lvalue_reference<T>::type operator*() const;
288 pointer operator->() const noexcept;
289 pointer get() const noexcept;
290 deleter_type& get_deleter() noexcept;
291 const deleter_type& get_deleter() const noexcept;
292 explicit operator bool() const noexcept;
295 pointer release() noexcept;
296 void reset(pointer p = pointer()) noexcept;
297 void swap(unique_ptr& u) noexcept;
300 template <class T, class D>
301 class unique_ptr<T[], D>
304 typedef implementation-defined pointer;
305 typedef T element_type;
306 typedef D deleter_type;
309 constexpr unique_ptr() noexcept;
310 explicit unique_ptr(pointer p) noexcept;
311 unique_ptr(pointer p, see below d) noexcept;
312 unique_ptr(pointer p, see below d) noexcept;
313 unique_ptr(unique_ptr&& u) noexcept;
314 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
320 unique_ptr& operator=(unique_ptr&& u) noexcept;
321 unique_ptr& operator=(nullptr_t) noexcept;
324 T& operator[](size_t i) const;
325 pointer get() const noexcept;
326 deleter_type& get_deleter() noexcept;
327 const deleter_type& get_deleter() const noexcept;
328 explicit operator bool() const noexcept;
331 pointer release() noexcept;
332 void reset(pointer p = pointer()) noexcept;
333 void reset(nullptr_t) noexcept;
334 template <class U> void reset(U) = delete;
335 void swap(unique_ptr& u) noexcept;
338 template <class T, class D>
339 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
341 template <class T1, class D1, class T2, class D2>
342 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
343 template <class T1, class D1, class T2, class D2>
344 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
345 template <class T1, class D1, class T2, class D2>
346 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
347 template <class T1, class D1, class T2, class D2>
348 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
349 template <class T1, class D1, class T2, class D2>
350 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
351 template <class T1, class D1, class T2, class D2>
352 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
354 template <class T, class D>
355 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
356 template <class T, class D>
357 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
358 template <class T, class D>
359 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
360 template <class T, class D>
361 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
363 template <class T, class D>
364 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
365 template <class T, class D>
366 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
367 template <class T, class D>
368 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
369 template <class T, class D>
370 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
371 template <class T, class D>
372 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
373 template <class T, class D>
374 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
375 template <class T, class D>
376 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
377 template <class T, class D>
378 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
381 : public std::exception
383 bad_weak_ptr() noexcept;
386 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
387 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
388 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
390 template<class E, class T, class Y, class D>
391 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
397 typedef T element_type;
398 typedef weak_ptr<T> weak_type; // C++17
401 constexpr shared_ptr() noexcept;
402 template<class Y> explicit shared_ptr(Y* p);
403 template<class Y, class D> shared_ptr(Y* p, D d);
404 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
405 template <class D> shared_ptr(nullptr_t p, D d);
406 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
407 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
408 shared_ptr(const shared_ptr& r) noexcept;
409 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
410 shared_ptr(shared_ptr&& r) noexcept;
411 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
412 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
413 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
414 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
415 shared_ptr(nullptr_t) : shared_ptr() { }
421 shared_ptr& operator=(const shared_ptr& r) noexcept;
422 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
423 shared_ptr& operator=(shared_ptr&& r) noexcept;
424 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
425 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
426 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
429 void swap(shared_ptr& r) noexcept;
430 void reset() noexcept;
431 template<class Y> void reset(Y* p);
432 template<class Y, class D> void reset(Y* p, D d);
433 template<class Y, class D, class A> void reset(Y* p, D d, A a);
436 T* get() const noexcept;
437 T& operator*() const noexcept;
438 T* operator->() const noexcept;
439 long use_count() const noexcept;
440 bool unique() const noexcept;
441 explicit operator bool() const noexcept;
442 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
443 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
446 // shared_ptr comparisons:
447 template<class T, class U>
448 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
449 template<class T, class U>
450 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
451 template<class T, class U>
452 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
453 template<class T, class U>
454 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
455 template<class T, class U>
456 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
457 template<class T, class U>
458 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
461 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
463 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
465 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
467 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
469 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
471 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
473 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
475 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
477 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
479 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
481 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
483 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
485 // shared_ptr specialized algorithms:
486 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
489 template<class T, class U>
490 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
491 template<class T, class U>
492 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
493 template<class T, class U>
494 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
497 template<class E, class T, class Y>
498 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
500 // shared_ptr get_deleter:
501 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
503 template<class T, class... Args>
504 shared_ptr<T> make_shared(Args&&... args);
505 template<class T, class A, class... Args>
506 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
512 typedef T element_type;
515 constexpr weak_ptr() noexcept;
516 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
517 weak_ptr(weak_ptr const& r) noexcept;
518 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
519 weak_ptr(weak_ptr&& r) noexcept; // C++14
520 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
526 weak_ptr& operator=(weak_ptr const& r) noexcept;
527 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
528 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
529 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
530 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
533 void swap(weak_ptr& r) noexcept;
534 void reset() noexcept;
537 long use_count() const noexcept;
538 bool expired() const noexcept;
539 shared_ptr<T> lock() const noexcept;
540 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
541 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
544 // weak_ptr specialized algorithms:
545 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
548 template<class T> struct owner_less;
551 struct owner_less<shared_ptr<T> >
552 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
554 typedef bool result_type;
555 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
556 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
557 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
561 struct owner_less<weak_ptr<T> >
562 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
564 typedef bool result_type;
565 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
566 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
570 template <> // Added in C++14
571 struct owner_less<void>
573 template <class _Tp, class _Up>
574 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
575 template <class _Tp, class _Up>
576 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
577 template <class _Tp, class _Up>
578 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
579 template <class _Tp, class _Up>
580 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
582 typedef void is_transparent;
586 class enable_shared_from_this
589 constexpr enable_shared_from_this() noexcept;
590 enable_shared_from_this(enable_shared_from_this const&) noexcept;
591 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
592 ~enable_shared_from_this();
594 shared_ptr<T> shared_from_this();
595 shared_ptr<T const> shared_from_this() const;
599 bool atomic_is_lock_free(const shared_ptr<T>* p);
601 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
603 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
605 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
607 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
609 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
612 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
615 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
618 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
621 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
622 shared_ptr<T> w, memory_order success,
623 memory_order failure);
626 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
627 shared_ptr<T> w, memory_order success,
628 memory_order failure);
630 template <class T> struct hash;
631 template <class T, class D> struct hash<unique_ptr<T, D> >;
632 template <class T> struct hash<shared_ptr<T> >;
634 template <class T, class Alloc>
635 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
638 enum class pointer_safety { relaxed, preferred, strict };
639 void declare_reachable(void *p);
640 template <class T> T *undeclare_reachable(T *p);
641 void declare_no_pointers(char *p, size_t n);
642 void undeclare_no_pointers(char *p, size_t n);
643 pointer_safety get_pointer_safety() noexcept;
645 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
652 #include <type_traits>
660 #include <__functional_base>
665 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
670 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
671 #pragma GCC system_header
675 #include <__undef_macros>
678 _LIBCPP_BEGIN_NAMESPACE_STD
680 template <class _ValueType>
681 inline _LIBCPP_INLINE_VISIBILITY
682 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
683 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
684 defined(__ATOMIC_RELAXED) && \
685 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
686 return __atomic_load_n(__value, __ATOMIC_RELAXED);
692 template <class _ValueType>
693 inline _LIBCPP_INLINE_VISIBILITY
694 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
695 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
696 defined(__ATOMIC_ACQUIRE) && \
697 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
698 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
704 // addressof moved to <type_traits>
706 template <class _Tp> class allocator;
709 class _LIBCPP_TEMPLATE_VIS allocator<void>
712 typedef void* pointer;
713 typedef const void* const_pointer;
714 typedef void value_type;
716 template <class _Up> struct rebind {typedef allocator<_Up> other;};
720 class _LIBCPP_TEMPLATE_VIS allocator<const void>
723 typedef const void* pointer;
724 typedef const void* const_pointer;
725 typedef const void value_type;
727 template <class _Up> struct rebind {typedef allocator<_Up> other;};
732 template <class _Tp, class = void>
733 struct __has_element_type : false_type {};
736 struct __has_element_type<_Tp,
737 typename __void_t<typename _Tp::element_type>::type> : true_type {};
739 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
740 struct __pointer_traits_element_type;
742 template <class _Ptr>
743 struct __pointer_traits_element_type<_Ptr, true>
745 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
748 #ifndef _LIBCPP_HAS_NO_VARIADICS
750 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
751 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
753 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
756 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
757 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
759 typedef _LIBCPP_NODEBUG_TYPE _Tp type;
762 #else // _LIBCPP_HAS_NO_VARIADICS
764 template <template <class> class _Sp, class _Tp>
765 struct __pointer_traits_element_type<_Sp<_Tp>, true>
767 typedef typename _Sp<_Tp>::element_type type;
770 template <template <class> class _Sp, class _Tp>
771 struct __pointer_traits_element_type<_Sp<_Tp>, false>
776 template <template <class, class> class _Sp, class _Tp, class _A0>
777 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
779 typedef typename _Sp<_Tp, _A0>::element_type type;
782 template <template <class, class> class _Sp, class _Tp, class _A0>
783 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
788 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
789 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
791 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
794 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
795 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
800 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
801 class _A1, class _A2>
802 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
804 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
807 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
808 class _A1, class _A2>
809 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
814 #endif // _LIBCPP_HAS_NO_VARIADICS
816 template <class _Tp, class = void>
817 struct __has_difference_type : false_type {};
820 struct __has_difference_type<_Tp,
821 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
823 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
824 struct __pointer_traits_difference_type
826 typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
829 template <class _Ptr>
830 struct __pointer_traits_difference_type<_Ptr, true>
832 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
835 template <class _Tp, class _Up>
839 struct __two {char __lx; char __lxx;};
840 template <class _Xp> static __two __test(...);
841 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
843 static const bool value = sizeof(__test<_Tp>(0)) == 1;
846 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
847 struct __pointer_traits_rebind
849 #ifndef _LIBCPP_CXX03_LANG
850 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
852 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
856 #ifndef _LIBCPP_HAS_NO_VARIADICS
858 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
859 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
861 #ifndef _LIBCPP_CXX03_LANG
862 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
864 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
868 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
869 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
871 typedef _Sp<_Up, _Args...> type;
874 #else // _LIBCPP_HAS_NO_VARIADICS
876 template <template <class> class _Sp, class _Tp, class _Up>
877 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
879 #ifndef _LIBCPP_CXX03_LANG
880 typedef typename _Sp<_Tp>::template rebind<_Up> type;
882 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
886 template <template <class> class _Sp, class _Tp, class _Up>
887 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
889 typedef _Sp<_Up> type;
892 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
893 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
895 #ifndef _LIBCPP_CXX03_LANG
896 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
898 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
902 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
903 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
905 typedef _Sp<_Up, _A0> type;
908 template <template <class, class, class> class _Sp, class _Tp, class _A0,
909 class _A1, class _Up>
910 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
912 #ifndef _LIBCPP_CXX03_LANG
913 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
915 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
919 template <template <class, class, class> class _Sp, class _Tp, class _A0,
920 class _A1, class _Up>
921 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
923 typedef _Sp<_Up, _A0, _A1> type;
926 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
927 class _A1, class _A2, class _Up>
928 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
930 #ifndef _LIBCPP_CXX03_LANG
931 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
933 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
937 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
938 class _A1, class _A2, class _Up>
939 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
941 typedef _Sp<_Up, _A0, _A1, _A2> type;
944 #endif // _LIBCPP_HAS_NO_VARIADICS
946 template <class _Ptr>
947 struct _LIBCPP_TEMPLATE_VIS pointer_traits
949 typedef _Ptr pointer;
950 typedef typename __pointer_traits_element_type<pointer>::type element_type;
951 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
953 #ifndef _LIBCPP_CXX03_LANG
954 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
956 template <class _Up> struct rebind
957 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
958 #endif // _LIBCPP_CXX03_LANG
963 _LIBCPP_INLINE_VISIBILITY
964 static pointer pointer_to(typename conditional<is_void<element_type>::value,
965 __nat, element_type>::type& __r)
966 {return pointer::pointer_to(__r);}
970 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
972 typedef _Tp* pointer;
973 typedef _Tp element_type;
974 typedef ptrdiff_t difference_type;
976 #ifndef _LIBCPP_CXX03_LANG
977 template <class _Up> using rebind = _Up*;
979 template <class _Up> struct rebind {typedef _Up* other;};
985 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
986 static pointer pointer_to(typename conditional<is_void<element_type>::value,
987 __nat, element_type>::type& __r) _NOEXCEPT
988 {return _VSTD::addressof(__r);}
991 template <class _From, class _To>
992 struct __rebind_pointer {
993 #ifndef _LIBCPP_CXX03_LANG
994 typedef typename pointer_traits<_From>::template rebind<_To> type;
996 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
1002 template <class _Tp, class = void>
1003 struct __has_pointer_type : false_type {};
1005 template <class _Tp>
1006 struct __has_pointer_type<_Tp,
1007 typename __void_t<typename _Tp::pointer>::type> : true_type {};
1009 namespace __pointer_type_imp
1012 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1013 struct __pointer_type
1015 typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type;
1018 template <class _Tp, class _Dp>
1019 struct __pointer_type<_Tp, _Dp, false>
1021 typedef _LIBCPP_NODEBUG_TYPE _Tp* type;
1024 } // __pointer_type_imp
1026 template <class _Tp, class _Dp>
1027 struct __pointer_type
1029 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1032 template <class _Tp, class = void>
1033 struct __has_const_pointer : false_type {};
1035 template <class _Tp>
1036 struct __has_const_pointer<_Tp,
1037 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1039 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1040 struct __const_pointer
1042 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type;
1045 template <class _Tp, class _Ptr, class _Alloc>
1046 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1048 #ifndef _LIBCPP_CXX03_LANG
1049 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1051 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1055 template <class _Tp, class = void>
1056 struct __has_void_pointer : false_type {};
1058 template <class _Tp>
1059 struct __has_void_pointer<_Tp,
1060 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1062 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1063 struct __void_pointer
1065 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type;
1068 template <class _Ptr, class _Alloc>
1069 struct __void_pointer<_Ptr, _Alloc, false>
1071 #ifndef _LIBCPP_CXX03_LANG
1072 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;
1074 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type;
1078 template <class _Tp, class = void>
1079 struct __has_const_void_pointer : false_type {};
1081 template <class _Tp>
1082 struct __has_const_void_pointer<_Tp,
1083 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1085 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1086 struct __const_void_pointer
1088 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type;
1091 template <class _Ptr, class _Alloc>
1092 struct __const_void_pointer<_Ptr, _Alloc, false>
1094 #ifndef _LIBCPP_CXX03_LANG
1095 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;
1097 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1101 template <class _Tp>
1102 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1104 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1109 #if _LIBCPP_STD_VER <= 17
1110 template <class _Pointer>
1111 inline _LIBCPP_INLINE_VISIBILITY
1112 typename pointer_traits<_Pointer>::element_type*
1113 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1115 return _VSTD::__to_raw_pointer(__p.operator->());
1118 template <class _Pointer>
1119 inline _LIBCPP_INLINE_VISIBILITY
1121 __to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1122 -> decltype(pointer_traits<_Pointer>::to_address(__p))
1124 return pointer_traits<_Pointer>::to_address(__p);
1127 template <class _Pointer, class... _None>
1128 inline _LIBCPP_INLINE_VISIBILITY
1130 __to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1132 return _VSTD::__to_raw_pointer(__p.operator->());
1135 template <class _Tp>
1136 inline _LIBCPP_INLINE_VISIBILITY constexpr
1138 to_address(_Tp* __p) _NOEXCEPT
1140 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1144 template <class _Pointer>
1145 inline _LIBCPP_INLINE_VISIBILITY
1147 to_address(const _Pointer& __p) _NOEXCEPT
1149 return _VSTD::__to_raw_pointer(__p);
1153 template <class _Tp, class = void>
1154 struct __has_size_type : false_type {};
1156 template <class _Tp>
1157 struct __has_size_type<_Tp,
1158 typename __void_t<typename _Tp::size_type>::type> : true_type {};
1160 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1163 typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;
1166 template <class _Alloc, class _DiffType>
1167 struct __size_type<_Alloc, _DiffType, true>
1169 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type;
1172 template <class _Tp, class = void>
1173 struct __has_propagate_on_container_copy_assignment : false_type {};
1175 template <class _Tp>
1176 struct __has_propagate_on_container_copy_assignment<_Tp,
1177 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1180 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1181 struct __propagate_on_container_copy_assignment
1183 typedef _LIBCPP_NODEBUG_TYPE false_type type;
1186 template <class _Alloc>
1187 struct __propagate_on_container_copy_assignment<_Alloc, true>
1189 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;
1192 template <class _Tp, class = void>
1193 struct __has_propagate_on_container_move_assignment : false_type {};
1195 template <class _Tp>
1196 struct __has_propagate_on_container_move_assignment<_Tp,
1197 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1200 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1201 struct __propagate_on_container_move_assignment
1203 typedef false_type type;
1206 template <class _Alloc>
1207 struct __propagate_on_container_move_assignment<_Alloc, true>
1209 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;
1212 template <class _Tp, class = void>
1213 struct __has_propagate_on_container_swap : false_type {};
1215 template <class _Tp>
1216 struct __has_propagate_on_container_swap<_Tp,
1217 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1220 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1221 struct __propagate_on_container_swap
1223 typedef false_type type;
1226 template <class _Alloc>
1227 struct __propagate_on_container_swap<_Alloc, true>
1229 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;
1232 template <class _Tp, class = void>
1233 struct __has_is_always_equal : false_type {};
1235 template <class _Tp>
1236 struct __has_is_always_equal<_Tp,
1237 typename __void_t<typename _Tp::is_always_equal>::type>
1240 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1241 struct __is_always_equal
1243 typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type;
1246 template <class _Alloc>
1247 struct __is_always_equal<_Alloc, true>
1249 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type;
1252 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1253 struct __has_rebind_other
1256 struct __two {char __lx; char __lxx;};
1257 template <class _Xp> static __two __test(...);
1258 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1260 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1263 template <class _Tp, class _Up>
1264 struct __has_rebind_other<_Tp, _Up, false>
1266 static const bool value = false;
1269 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1270 struct __allocator_traits_rebind
1272 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
1275 #ifndef _LIBCPP_HAS_NO_VARIADICS
1277 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1278 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1280 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1283 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1284 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1286 typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
1289 #else // _LIBCPP_HAS_NO_VARIADICS
1291 template <template <class> class _Alloc, class _Tp, class _Up>
1292 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1294 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1297 template <template <class> class _Alloc, class _Tp, class _Up>
1298 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1300 typedef _Alloc<_Up> type;
1303 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1304 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1306 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1309 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1310 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1312 typedef _Alloc<_Up, _A0> type;
1315 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1316 class _A1, class _Up>
1317 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1319 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1322 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1323 class _A1, class _Up>
1324 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1326 typedef _Alloc<_Up, _A0, _A1> type;
1329 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1330 class _A1, class _A2, class _Up>
1331 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1333 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1336 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1337 class _A1, class _A2, class _Up>
1338 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1340 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1343 #endif // _LIBCPP_HAS_NO_VARIADICS
1345 #ifndef _LIBCPP_CXX03_LANG
1347 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1349 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1350 -> decltype((void)__a.allocate(__sz, __p), true_type());
1352 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1354 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1357 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1358 struct __has_allocate_hint
1359 : integral_constant<bool,
1361 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1362 declval<_SizeType>(),
1363 declval<_ConstVoidPtr>())),
1368 #else // _LIBCPP_CXX03_LANG
1370 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1371 struct __has_allocate_hint
1376 #endif // _LIBCPP_CXX03_LANG
1378 #if !defined(_LIBCPP_CXX03_LANG)
1380 template <class _Alloc, class _Tp, class ..._Args>
1381 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1382 _VSTD::declval<_Args>()...),
1384 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1386 template <class _Alloc, class _Pointer, class ..._Args>
1388 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1390 template <class _Alloc, class _Pointer, class ..._Args>
1391 struct __has_construct
1392 : integral_constant<bool,
1394 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1395 declval<_Pointer>(),
1396 declval<_Args>()...)),
1401 template <class _Alloc, class _Pointer>
1403 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1404 -> decltype(__a.destroy(__p), true_type());
1406 template <class _Alloc, class _Pointer>
1408 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1411 template <class _Alloc, class _Pointer>
1412 struct __has_destroy
1413 : integral_constant<bool,
1415 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1416 declval<_Pointer>())),
1421 template <class _Alloc>
1423 __has_max_size_test(_Alloc&& __a)
1424 -> decltype(__a.max_size(), true_type());
1426 template <class _Alloc>
1428 __has_max_size_test(const volatile _Alloc& __a)
1431 template <class _Alloc>
1432 struct __has_max_size
1433 : integral_constant<bool,
1435 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1440 template <class _Alloc>
1442 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1443 -> decltype(__a.select_on_container_copy_construction(), true_type());
1445 template <class _Alloc>
1447 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1450 template <class _Alloc>
1451 struct __has_select_on_container_copy_construction
1452 : integral_constant<bool,
1454 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1459 #else // _LIBCPP_CXX03_LANG
1461 template <class _Alloc, class _Pointer, class _Tp, class = void>
1462 struct __has_construct : std::false_type {};
1464 template <class _Alloc, class _Pointer, class _Tp>
1465 struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
1466 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
1467 >::type> : std::true_type {};
1469 template <class _Alloc, class _Pointer, class = void>
1470 struct __has_destroy : false_type {};
1472 template <class _Alloc, class _Pointer>
1473 struct __has_destroy<_Alloc, _Pointer, typename __void_t<
1474 decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
1475 >::type> : std::true_type {};
1477 template <class _Alloc>
1478 struct __has_max_size
1483 template <class _Alloc>
1484 struct __has_select_on_container_copy_construction
1489 #endif // _LIBCPP_CXX03_LANG
1491 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1492 struct __alloc_traits_difference_type
1494 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;
1497 template <class _Alloc, class _Ptr>
1498 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1500 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type;
1503 template <class _Tp>
1504 struct __is_default_allocator : false_type {};
1506 template <class _Tp>
1507 struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
1511 template <class _Alloc,
1512 bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value
1514 struct __is_cpp17_move_insertable;
1515 template <class _Alloc>
1516 struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {};
1517 template <class _Alloc>
1518 struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {};
1520 template <class _Alloc,
1521 bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value
1523 struct __is_cpp17_copy_insertable;
1524 template <class _Alloc>
1525 struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {};
1526 template <class _Alloc>
1527 struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool,
1528 std::is_copy_constructible<typename _Alloc::value_type>::value &&
1529 __is_cpp17_move_insertable<_Alloc>::value>
1534 template <class _Alloc>
1535 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1537 typedef _Alloc allocator_type;
1538 typedef typename allocator_type::value_type value_type;
1540 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1541 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1542 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1543 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1545 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1546 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1548 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1549 propagate_on_container_copy_assignment;
1550 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1551 propagate_on_container_move_assignment;
1552 typedef typename __propagate_on_container_swap<allocator_type>::type
1553 propagate_on_container_swap;
1554 typedef typename __is_always_equal<allocator_type>::type
1557 #ifndef _LIBCPP_CXX03_LANG
1558 template <class _Tp> using rebind_alloc =
1559 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1560 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >;
1561 #else // _LIBCPP_CXX03_LANG
1562 template <class _Tp> struct rebind_alloc
1563 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1564 template <class _Tp> struct rebind_traits
1565 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1566 #endif // _LIBCPP_CXX03_LANG
1568 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1569 static pointer allocate(allocator_type& __a, size_type __n)
1570 {return __a.allocate(__n);}
1571 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1572 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1573 {return __allocate(__a, __n, __hint,
1574 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1576 _LIBCPP_INLINE_VISIBILITY
1577 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1578 {__a.deallocate(__p, __n);}
1580 #ifndef _LIBCPP_HAS_NO_VARIADICS
1581 template <class _Tp, class... _Args>
1582 _LIBCPP_INLINE_VISIBILITY
1583 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1584 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1585 __a, __p, _VSTD::forward<_Args>(__args)...);}
1586 #else // _LIBCPP_HAS_NO_VARIADICS
1587 template <class _Tp>
1588 _LIBCPP_INLINE_VISIBILITY
1589 static void construct(allocator_type&, _Tp* __p)
1591 ::new ((void*)__p) _Tp();
1593 template <class _Tp, class _A0>
1594 _LIBCPP_INLINE_VISIBILITY
1595 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1597 __construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
1600 template <class _Tp, class _A0, class _A1>
1601 _LIBCPP_INLINE_VISIBILITY
1602 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1605 ::new ((void*)__p) _Tp(__a0, __a1);
1607 template <class _Tp, class _A0, class _A1, class _A2>
1608 _LIBCPP_INLINE_VISIBILITY
1609 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1610 const _A1& __a1, const _A2& __a2)
1612 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1614 #endif // _LIBCPP_HAS_NO_VARIADICS
1616 template <class _Tp>
1617 _LIBCPP_INLINE_VISIBILITY
1618 static void destroy(allocator_type& __a, _Tp* __p)
1619 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1621 _LIBCPP_INLINE_VISIBILITY
1622 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1623 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1625 _LIBCPP_INLINE_VISIBILITY
1626 static allocator_type
1627 select_on_container_copy_construction(const allocator_type& __a)
1628 {return __select_on_container_copy_construction(
1629 __has_select_on_container_copy_construction<const allocator_type>(),
1632 template <class _Ptr>
1633 _LIBCPP_INLINE_VISIBILITY
1636 __construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1638 static_assert(__is_cpp17_move_insertable<allocator_type>::value,
1639 "The specified type does not meet the requirements of Cpp17MoveInsertible");
1640 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1641 construct(__a, _VSTD::__to_raw_pointer(__begin2),
1642 #ifdef _LIBCPP_NO_EXCEPTIONS
1643 _VSTD::move(*__begin1)
1645 _VSTD::move_if_noexcept(*__begin1)
1650 template <class _Tp>
1651 _LIBCPP_INLINE_VISIBILITY
1655 (__is_default_allocator<allocator_type>::value
1656 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1657 is_trivially_move_constructible<_Tp>::value,
1660 __construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1662 ptrdiff_t _Np = __end1 - __begin1;
1665 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1670 template <class _Iter, class _Ptr>
1671 _LIBCPP_INLINE_VISIBILITY
1674 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1676 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1677 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1680 template <class _SourceTp, class _DestTp,
1681 class _RawSourceTp = typename remove_const<_SourceTp>::type,
1682 class _RawDestTp = typename remove_const<_DestTp>::type>
1683 _LIBCPP_INLINE_VISIBILITY
1687 is_trivially_move_constructible<_DestTp>::value &&
1688 is_same<_RawSourceTp, _RawDestTp>::value &&
1689 (__is_default_allocator<allocator_type>::value ||
1690 !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
1693 __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
1695 ptrdiff_t _Np = __end1 - __begin1;
1698 _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
1703 template <class _Ptr>
1704 _LIBCPP_INLINE_VISIBILITY
1707 __construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1709 static_assert(__is_cpp17_move_insertable<allocator_type>::value,
1710 "The specified type does not meet the requirements of Cpp17MoveInsertable");
1711 while (__end1 != __begin1)
1713 construct(__a, _VSTD::__to_raw_pointer(__end2 - 1),
1714 #ifdef _LIBCPP_NO_EXCEPTIONS
1715 _VSTD::move(*--__end1)
1717 _VSTD::move_if_noexcept(*--__end1)
1724 template <class _Tp>
1725 _LIBCPP_INLINE_VISIBILITY
1729 (__is_default_allocator<allocator_type>::value
1730 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1731 is_trivially_move_constructible<_Tp>::value,
1734 __construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1736 ptrdiff_t _Np = __end1 - __begin1;
1739 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1744 _LIBCPP_INLINE_VISIBILITY
1745 static pointer __allocate(allocator_type& __a, size_type __n,
1746 const_void_pointer __hint, true_type)
1747 {return __a.allocate(__n, __hint);}
1748 _LIBCPP_INLINE_VISIBILITY
1749 static pointer __allocate(allocator_type& __a, size_type __n,
1750 const_void_pointer, false_type)
1751 {return __a.allocate(__n);}
1753 #ifndef _LIBCPP_HAS_NO_VARIADICS
1754 template <class _Tp, class... _Args>
1755 _LIBCPP_INLINE_VISIBILITY
1756 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1757 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1758 template <class _Tp, class... _Args>
1759 _LIBCPP_INLINE_VISIBILITY
1760 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1762 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1764 #else // _LIBCPP_HAS_NO_VARIADICS
1765 template <class _Tp, class _A0>
1766 _LIBCPP_INLINE_VISIBILITY
1767 static void __construct(true_type, allocator_type& __a, _Tp* __p,
1769 {__a.construct(__p, __a0);}
1770 template <class _Tp, class _A0>
1771 _LIBCPP_INLINE_VISIBILITY
1772 static void __construct(false_type, allocator_type&, _Tp* __p,
1775 ::new ((void*)__p) _Tp(__a0);
1777 #endif // _LIBCPP_HAS_NO_VARIADICS
1779 template <class _Tp>
1780 _LIBCPP_INLINE_VISIBILITY
1781 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1783 template <class _Tp>
1784 _LIBCPP_INLINE_VISIBILITY
1785 static void __destroy(false_type, allocator_type&, _Tp* __p)
1790 _LIBCPP_INLINE_VISIBILITY
1791 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1792 {return __a.max_size();}
1793 _LIBCPP_INLINE_VISIBILITY
1794 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
1795 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1797 _LIBCPP_INLINE_VISIBILITY
1798 static allocator_type
1799 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1800 {return __a.select_on_container_copy_construction();}
1801 _LIBCPP_INLINE_VISIBILITY
1802 static allocator_type
1803 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1807 template <class _Traits, class _Tp>
1808 struct __rebind_alloc_helper
1810 #ifndef _LIBCPP_CXX03_LANG
1811 typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type;
1813 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1819 template <class _Tp>
1820 class _LIBCPP_TEMPLATE_VIS allocator
1823 typedef size_t size_type;
1824 typedef ptrdiff_t difference_type;
1825 typedef _Tp* pointer;
1826 typedef const _Tp* const_pointer;
1827 typedef _Tp& reference;
1828 typedef const _Tp& const_reference;
1829 typedef _Tp value_type;
1831 typedef true_type propagate_on_container_move_assignment;
1832 typedef true_type is_always_equal;
1834 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1837 allocator() _NOEXCEPT {}
1839 template <class _Up>
1840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1841 allocator(const allocator<_Up>&) _NOEXCEPT {}
1843 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1844 {return _VSTD::addressof(__x);}
1845 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1846 {return _VSTD::addressof(__x);}
1847 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1848 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1850 if (__n > max_size())
1851 __throw_length_error("allocator<T>::allocate(size_t n)"
1852 " 'n' exceeds maximum supported size");
1853 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1855 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1856 {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1857 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1858 {return size_type(~0) / sizeof(_Tp);}
1859 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1860 template <class _Up, class... _Args>
1861 _LIBCPP_INLINE_VISIBILITY
1863 construct(_Up* __p, _Args&&... __args)
1865 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1867 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1868 _LIBCPP_INLINE_VISIBILITY
1870 construct(pointer __p)
1872 ::new((void*)__p) _Tp();
1874 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1876 template <class _A0>
1877 _LIBCPP_INLINE_VISIBILITY
1879 construct(pointer __p, _A0& __a0)
1881 ::new((void*)__p) _Tp(__a0);
1883 template <class _A0>
1884 _LIBCPP_INLINE_VISIBILITY
1886 construct(pointer __p, const _A0& __a0)
1888 ::new((void*)__p) _Tp(__a0);
1890 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1891 template <class _A0, class _A1>
1892 _LIBCPP_INLINE_VISIBILITY
1894 construct(pointer __p, _A0& __a0, _A1& __a1)
1896 ::new((void*)__p) _Tp(__a0, __a1);
1898 template <class _A0, class _A1>
1899 _LIBCPP_INLINE_VISIBILITY
1901 construct(pointer __p, const _A0& __a0, _A1& __a1)
1903 ::new((void*)__p) _Tp(__a0, __a1);
1905 template <class _A0, class _A1>
1906 _LIBCPP_INLINE_VISIBILITY
1908 construct(pointer __p, _A0& __a0, const _A1& __a1)
1910 ::new((void*)__p) _Tp(__a0, __a1);
1912 template <class _A0, class _A1>
1913 _LIBCPP_INLINE_VISIBILITY
1915 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1917 ::new((void*)__p) _Tp(__a0, __a1);
1919 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1920 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1923 template <class _Tp>
1924 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1927 typedef size_t size_type;
1928 typedef ptrdiff_t difference_type;
1929 typedef const _Tp* pointer;
1930 typedef const _Tp* const_pointer;
1931 typedef const _Tp& reference;
1932 typedef const _Tp& const_reference;
1933 typedef const _Tp value_type;
1935 typedef true_type propagate_on_container_move_assignment;
1936 typedef true_type is_always_equal;
1938 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1940 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1941 allocator() _NOEXCEPT {}
1943 template <class _Up>
1944 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1945 allocator(const allocator<_Up>&) _NOEXCEPT {}
1947 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1948 {return _VSTD::addressof(__x);}
1949 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1951 if (__n > max_size())
1952 __throw_length_error("allocator<const T>::allocate(size_t n)"
1953 " 'n' exceeds maximum supported size");
1954 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1956 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1957 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1958 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1959 {return size_type(~0) / sizeof(_Tp);}
1960 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1961 template <class _Up, class... _Args>
1962 _LIBCPP_INLINE_VISIBILITY
1964 construct(_Up* __p, _Args&&... __args)
1966 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1968 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1969 _LIBCPP_INLINE_VISIBILITY
1971 construct(pointer __p)
1973 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1975 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1977 template <class _A0>
1978 _LIBCPP_INLINE_VISIBILITY
1980 construct(pointer __p, _A0& __a0)
1982 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1984 template <class _A0>
1985 _LIBCPP_INLINE_VISIBILITY
1987 construct(pointer __p, const _A0& __a0)
1989 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1991 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1992 template <class _A0, class _A1>
1993 _LIBCPP_INLINE_VISIBILITY
1995 construct(pointer __p, _A0& __a0, _A1& __a1)
1997 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1999 template <class _A0, class _A1>
2000 _LIBCPP_INLINE_VISIBILITY
2002 construct(pointer __p, const _A0& __a0, _A1& __a1)
2004 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
2006 template <class _A0, class _A1>
2007 _LIBCPP_INLINE_VISIBILITY
2009 construct(pointer __p, _A0& __a0, const _A1& __a1)
2011 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
2013 template <class _A0, class _A1>
2014 _LIBCPP_INLINE_VISIBILITY
2016 construct(pointer __p, const _A0& __a0, const _A1& __a1)
2018 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
2020 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
2021 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
2024 template <class _Tp, class _Up>
2025 inline _LIBCPP_INLINE_VISIBILITY
2026 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
2028 template <class _Tp, class _Up>
2029 inline _LIBCPP_INLINE_VISIBILITY
2030 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
2032 template <class _OutputIterator, class _Tp>
2033 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
2034 : public iterator<output_iterator_tag,
2035 _Tp, // purposefully not C++03
2036 ptrdiff_t, // purposefully not C++03
2037 _Tp*, // purposefully not C++03
2038 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
2041 _OutputIterator __x_;
2043 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
2044 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
2045 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
2046 {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
2047 #if _LIBCPP_STD_VER >= 14
2048 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
2049 {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
2051 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
2052 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
2053 {raw_storage_iterator __t(*this); ++__x_; return __t;}
2054 #if _LIBCPP_STD_VER >= 14
2055 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
2059 template <class _Tp>
2060 _LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
2061 pair<_Tp*, ptrdiff_t>
2062 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
2064 pair<_Tp*, ptrdiff_t> __r(0, 0);
2065 const ptrdiff_t __m = (~ptrdiff_t(0) ^
2066 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2072 #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2073 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
2075 std::align_val_t __al =
2076 std::align_val_t(std::alignment_of<_Tp>::value);
2077 __r.first = static_cast<_Tp*>(::operator new(
2078 __n * sizeof(_Tp), __al, nothrow));
2080 __r.first = static_cast<_Tp*>(::operator new(
2081 __n * sizeof(_Tp), nothrow));
2084 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
2086 // Since aligned operator new is unavailable, return an empty
2087 // buffer rather than one with invalid alignment.
2091 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2104 template <class _Tp>
2105 inline _LIBCPP_INLINE_VISIBILITY
2106 void return_temporary_buffer(_Tp* __p) _NOEXCEPT
2108 _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
2111 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2112 template <class _Tp>
2113 struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
2119 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
2124 typedef _Tp element_type;
2126 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2127 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2128 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2129 : __ptr_(__p.release()) {}
2130 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2131 {reset(__p.release()); return *this;}
2132 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2133 {reset(__p.release()); return *this;}
2134 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2135 {reset(__p.__ptr_); return *this;}
2136 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2138 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2140 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2141 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2142 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2148 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2155 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2156 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2157 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2158 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2159 {return auto_ptr<_Up>(release());}
2163 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
2166 typedef void element_type;
2170 template <class _Tp, int _Idx,
2171 bool _CanBeEmptyBase =
2172 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2173 struct __compressed_pair_elem {
2174 typedef _Tp _ParamT;
2175 typedef _Tp& reference;
2176 typedef const _Tp& const_reference;
2178 #ifndef _LIBCPP_CXX03_LANG
2179 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
2181 template <class _Up, class = typename enable_if<
2182 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2184 _LIBCPP_INLINE_VISIBILITY
2186 __compressed_pair_elem(_Up&& __u)
2187 : __value_(_VSTD::forward<_Up>(__u))
2191 template <class... _Args, size_t... _Indexes>
2192 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2193 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2194 __tuple_indices<_Indexes...>)
2195 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2197 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2198 _LIBCPP_INLINE_VISIBILITY
2199 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2202 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2203 _LIBCPP_INLINE_VISIBILITY
2204 const_reference __get() const _NOEXCEPT { return __value_; }
2210 template <class _Tp, int _Idx>
2211 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2212 typedef _Tp _ParamT;
2213 typedef _Tp& reference;
2214 typedef const _Tp& const_reference;
2215 typedef _Tp __value_type;
2217 #ifndef _LIBCPP_CXX03_LANG
2218 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
2220 template <class _Up, class = typename enable_if<
2221 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2223 _LIBCPP_INLINE_VISIBILITY
2225 __compressed_pair_elem(_Up&& __u)
2226 : __value_type(_VSTD::forward<_Up>(__u))
2229 template <class... _Args, size_t... _Indexes>
2230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2231 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2232 __tuple_indices<_Indexes...>)
2233 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2235 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2236 _LIBCPP_INLINE_VISIBILITY
2237 __compressed_pair_elem(_ParamT __p)
2238 : __value_type(std::forward<_ParamT>(__p)) {}
2241 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2242 _LIBCPP_INLINE_VISIBILITY
2243 const_reference __get() const _NOEXCEPT { return *this; }
2246 // Tag used to construct the second element of the compressed pair.
2247 struct __second_tag {};
2249 template <class _T1, class _T2>
2250 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2251 private __compressed_pair_elem<_T2, 1> {
2252 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
2253 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
2255 // NOTE: This static assert should never fire because __compressed_pair
2256 // is *almost never* used in a scenario where it's possible for T1 == T2.
2257 // (The exception is std::function where it is possible that the function
2258 // object and the allocator have the same type).
2259 static_assert((!is_same<_T1, _T2>::value),
2260 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2261 "The current implementation is NOT ABI-compatible with the previous "
2262 "implementation for this configuration");
2265 #ifndef _LIBCPP_CXX03_LANG
2266 template <bool _Dummy = true,
2267 class = typename enable_if<
2268 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2269 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2272 _LIBCPP_INLINE_VISIBILITY
2273 constexpr __compressed_pair() {}
2275 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2276 __compressed_pair>::value,
2278 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2279 __compressed_pair(_Tp&& __t)
2280 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2282 template <class _Tp>
2283 _LIBCPP_INLINE_VISIBILITY constexpr
2284 __compressed_pair(__second_tag, _Tp&& __t)
2285 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2287 template <class _U1, class _U2>
2288 _LIBCPP_INLINE_VISIBILITY constexpr
2289 __compressed_pair(_U1&& __t1, _U2&& __t2)
2290 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2292 template <class... _Args1, class... _Args2>
2293 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2294 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2295 tuple<_Args2...> __second_args)
2296 : _Base1(__pc, _VSTD::move(__first_args),
2297 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2298 _Base2(__pc, _VSTD::move(__second_args),
2299 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2302 _LIBCPP_INLINE_VISIBILITY
2303 __compressed_pair() {}
2305 _LIBCPP_INLINE_VISIBILITY explicit
2306 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2308 _LIBCPP_INLINE_VISIBILITY
2309 __compressed_pair(__second_tag, _T2 __t2)
2310 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2312 _LIBCPP_INLINE_VISIBILITY
2313 __compressed_pair(_T1 __t1, _T2 __t2)
2314 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2317 _LIBCPP_INLINE_VISIBILITY
2318 typename _Base1::reference first() _NOEXCEPT {
2319 return static_cast<_Base1&>(*this).__get();
2322 _LIBCPP_INLINE_VISIBILITY
2323 typename _Base1::const_reference first() const _NOEXCEPT {
2324 return static_cast<_Base1 const&>(*this).__get();
2327 _LIBCPP_INLINE_VISIBILITY
2328 typename _Base2::reference second() _NOEXCEPT {
2329 return static_cast<_Base2&>(*this).__get();
2332 _LIBCPP_INLINE_VISIBILITY
2333 typename _Base2::const_reference second() const _NOEXCEPT {
2334 return static_cast<_Base2 const&>(*this).__get();
2337 _LIBCPP_INLINE_VISIBILITY
2338 void swap(__compressed_pair& __x)
2339 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2340 __is_nothrow_swappable<_T2>::value)
2343 swap(first(), __x.first());
2344 swap(second(), __x.second());
2348 template <class _T1, class _T2>
2349 inline _LIBCPP_INLINE_VISIBILITY
2350 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2351 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2352 __is_nothrow_swappable<_T2>::value) {
2358 template <class _Tp>
2359 struct _LIBCPP_TEMPLATE_VIS default_delete {
2360 static_assert(!is_function<_Tp>::value,
2361 "default_delete cannot be instantiated for function types");
2362 #ifndef _LIBCPP_CXX03_LANG
2363 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
2365 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2367 template <class _Up>
2368 _LIBCPP_INLINE_VISIBILITY
2369 default_delete(const default_delete<_Up>&,
2370 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2373 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2374 static_assert(sizeof(_Tp) > 0,
2375 "default_delete can not delete incomplete type");
2376 static_assert(!is_void<_Tp>::value,
2377 "default_delete can not delete incomplete type");
2382 template <class _Tp>
2383 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2385 template <class _Up>
2386 struct _EnableIfConvertible
2387 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2390 #ifndef _LIBCPP_CXX03_LANG
2391 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
2393 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2396 template <class _Up>
2397 _LIBCPP_INLINE_VISIBILITY
2398 default_delete(const default_delete<_Up[]>&,
2399 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2401 template <class _Up>
2402 _LIBCPP_INLINE_VISIBILITY
2403 typename _EnableIfConvertible<_Up>::type
2404 operator()(_Up* __ptr) const _NOEXCEPT {
2405 static_assert(sizeof(_Tp) > 0,
2406 "default_delete can not delete incomplete type");
2407 static_assert(!is_void<_Tp>::value,
2408 "default_delete can not delete void type");
2413 template <class _Deleter>
2414 struct __unique_ptr_deleter_sfinae {
2415 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2416 typedef const _Deleter& __lval_ref_type;
2417 typedef _Deleter&& __good_rval_ref_type;
2418 typedef true_type __enable_rval_overload;
2421 template <class _Deleter>
2422 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2423 typedef const _Deleter& __lval_ref_type;
2424 typedef const _Deleter&& __bad_rval_ref_type;
2425 typedef false_type __enable_rval_overload;
2428 template <class _Deleter>
2429 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2430 typedef _Deleter& __lval_ref_type;
2431 typedef _Deleter&& __bad_rval_ref_type;
2432 typedef false_type __enable_rval_overload;
2435 template <class _Tp, class _Dp = default_delete<_Tp> >
2436 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2438 typedef _Tp element_type;
2439 typedef _Dp deleter_type;
2440 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer;
2442 static_assert(!is_rvalue_reference<deleter_type>::value,
2443 "the specified deleter type cannot be an rvalue reference");
2446 __compressed_pair<pointer, deleter_type> __ptr_;
2448 struct __nat { int __for_bool_; };
2450 typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2452 template <bool _Dummy>
2453 using _LValRefType _LIBCPP_NODEBUG_TYPE =
2454 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2456 template <bool _Dummy>
2457 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
2458 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2460 template <bool _Dummy>
2461 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
2462 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2464 template <bool _Dummy, class _Deleter = typename __dependent_type<
2465 __identity<deleter_type>, _Dummy>::type>
2466 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
2467 typename enable_if<is_default_constructible<_Deleter>::value &&
2468 !is_pointer<_Deleter>::value>::type;
2470 template <class _ArgType>
2471 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
2472 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2474 template <class _UPtr, class _Up>
2475 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2476 is_convertible<typename _UPtr::pointer, pointer>::value &&
2477 !is_array<_Up>::value
2480 template <class _UDel>
2481 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2482 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2483 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2486 template <class _UDel>
2487 using _EnableIfDeleterAssignable = typename enable_if<
2488 is_assignable<_Dp&, _UDel&&>::value
2492 template <bool _Dummy = true,
2493 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2494 _LIBCPP_INLINE_VISIBILITY
2495 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
2497 template <bool _Dummy = true,
2498 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2499 _LIBCPP_INLINE_VISIBILITY
2500 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
2502 template <bool _Dummy = true,
2503 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2504 _LIBCPP_INLINE_VISIBILITY
2505 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {}
2507 template <bool _Dummy = true,
2508 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
2509 _LIBCPP_INLINE_VISIBILITY
2510 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
2511 : __ptr_(__p, __d) {}
2513 template <bool _Dummy = true,
2514 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
2515 _LIBCPP_INLINE_VISIBILITY
2516 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2517 : __ptr_(__p, _VSTD::move(__d)) {
2518 static_assert(!is_reference<deleter_type>::value,
2519 "rvalue deleter bound to reference");
2522 template <bool _Dummy = true,
2523 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
2524 _LIBCPP_INLINE_VISIBILITY
2525 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2527 _LIBCPP_INLINE_VISIBILITY
2528 unique_ptr(unique_ptr&& __u) _NOEXCEPT
2529 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2532 template <class _Up, class _Ep,
2533 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2534 class = _EnableIfDeleterConvertible<_Ep>
2536 _LIBCPP_INLINE_VISIBILITY
2537 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2538 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2540 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2541 template <class _Up>
2542 _LIBCPP_INLINE_VISIBILITY
2543 unique_ptr(auto_ptr<_Up>&& __p,
2544 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2545 is_same<_Dp, default_delete<_Tp> >::value,
2546 __nat>::type = __nat()) _NOEXCEPT
2547 : __ptr_(__p.release()) {}
2550 _LIBCPP_INLINE_VISIBILITY
2551 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2552 reset(__u.release());
2553 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2557 template <class _Up, class _Ep,
2558 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2559 class = _EnableIfDeleterAssignable<_Ep>
2561 _LIBCPP_INLINE_VISIBILITY
2562 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2563 reset(__u.release());
2564 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2568 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2569 template <class _Up>
2570 _LIBCPP_INLINE_VISIBILITY
2571 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2572 is_same<_Dp, default_delete<_Tp> >::value,
2574 operator=(auto_ptr<_Up> __p) {
2575 reset(__p.release());
2580 #ifdef _LIBCPP_CXX03_LANG
2581 unique_ptr(unique_ptr const&) = delete;
2582 unique_ptr& operator=(unique_ptr const&) = delete;
2586 _LIBCPP_INLINE_VISIBILITY
2587 ~unique_ptr() { reset(); }
2589 _LIBCPP_INLINE_VISIBILITY
2590 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2595 _LIBCPP_INLINE_VISIBILITY
2596 typename add_lvalue_reference<_Tp>::type
2598 return *__ptr_.first();
2600 _LIBCPP_INLINE_VISIBILITY
2601 pointer operator->() const _NOEXCEPT {
2602 return __ptr_.first();
2604 _LIBCPP_INLINE_VISIBILITY
2605 pointer get() const _NOEXCEPT {
2606 return __ptr_.first();
2608 _LIBCPP_INLINE_VISIBILITY
2609 deleter_type& get_deleter() _NOEXCEPT {
2610 return __ptr_.second();
2612 _LIBCPP_INLINE_VISIBILITY
2613 const deleter_type& get_deleter() const _NOEXCEPT {
2614 return __ptr_.second();
2616 _LIBCPP_INLINE_VISIBILITY
2617 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2618 return __ptr_.first() != nullptr;
2621 _LIBCPP_INLINE_VISIBILITY
2622 pointer release() _NOEXCEPT {
2623 pointer __t = __ptr_.first();
2624 __ptr_.first() = pointer();
2628 _LIBCPP_INLINE_VISIBILITY
2629 void reset(pointer __p = pointer()) _NOEXCEPT {
2630 pointer __tmp = __ptr_.first();
2631 __ptr_.first() = __p;
2633 __ptr_.second()(__tmp);
2636 _LIBCPP_INLINE_VISIBILITY
2637 void swap(unique_ptr& __u) _NOEXCEPT {
2638 __ptr_.swap(__u.__ptr_);
2643 template <class _Tp, class _Dp>
2644 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2646 typedef _Tp element_type;
2647 typedef _Dp deleter_type;
2648 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2651 __compressed_pair<pointer, deleter_type> __ptr_;
2653 template <class _From>
2654 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2656 template <class _FromElem>
2657 struct _CheckArrayPointerConversion<_FromElem*>
2658 : integral_constant<bool,
2659 is_same<_FromElem*, pointer>::value ||
2660 (is_same<pointer, element_type*>::value &&
2661 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2665 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2667 template <bool _Dummy>
2668 using _LValRefType _LIBCPP_NODEBUG_TYPE =
2669 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2671 template <bool _Dummy>
2672 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
2673 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2675 template <bool _Dummy>
2676 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
2677 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2679 template <bool _Dummy, class _Deleter = typename __dependent_type<
2680 __identity<deleter_type>, _Dummy>::type>
2681 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
2682 typename enable_if<is_default_constructible<_Deleter>::value &&
2683 !is_pointer<_Deleter>::value>::type;
2685 template <class _ArgType>
2686 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
2687 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2689 template <class _Pp>
2690 using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2691 _CheckArrayPointerConversion<_Pp>::value
2694 template <class _UPtr, class _Up,
2695 class _ElemT = typename _UPtr::element_type>
2696 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2697 is_array<_Up>::value &&
2698 is_same<pointer, element_type*>::value &&
2699 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2700 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2703 template <class _UDel>
2704 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2705 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2706 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2709 template <class _UDel>
2710 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
2711 is_assignable<_Dp&, _UDel&&>::value
2715 template <bool _Dummy = true,
2716 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2717 _LIBCPP_INLINE_VISIBILITY
2718 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
2720 template <bool _Dummy = true,
2721 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2722 _LIBCPP_INLINE_VISIBILITY
2723 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
2725 template <class _Pp, bool _Dummy = true,
2726 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2727 class = _EnableIfPointerConvertible<_Pp> >
2728 _LIBCPP_INLINE_VISIBILITY
2729 explicit unique_ptr(_Pp __p) _NOEXCEPT
2732 template <class _Pp, bool _Dummy = true,
2733 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
2734 class = _EnableIfPointerConvertible<_Pp> >
2735 _LIBCPP_INLINE_VISIBILITY
2736 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
2737 : __ptr_(__p, __d) {}
2739 template <bool _Dummy = true,
2740 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
2741 _LIBCPP_INLINE_VISIBILITY
2742 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
2743 : __ptr_(nullptr, __d) {}
2745 template <class _Pp, bool _Dummy = true,
2746 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
2747 class = _EnableIfPointerConvertible<_Pp> >
2748 _LIBCPP_INLINE_VISIBILITY
2749 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2750 : __ptr_(__p, _VSTD::move(__d)) {
2751 static_assert(!is_reference<deleter_type>::value,
2752 "rvalue deleter bound to reference");
2755 template <bool _Dummy = true,
2756 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
2757 _LIBCPP_INLINE_VISIBILITY
2758 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2759 : __ptr_(nullptr, _VSTD::move(__d)) {
2760 static_assert(!is_reference<deleter_type>::value,
2761 "rvalue deleter bound to reference");
2764 template <class _Pp, bool _Dummy = true,
2765 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
2766 class = _EnableIfPointerConvertible<_Pp> >
2767 _LIBCPP_INLINE_VISIBILITY
2768 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2770 _LIBCPP_INLINE_VISIBILITY
2771 unique_ptr(unique_ptr&& __u) _NOEXCEPT
2772 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2775 _LIBCPP_INLINE_VISIBILITY
2776 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2777 reset(__u.release());
2778 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2782 template <class _Up, class _Ep,
2783 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2784 class = _EnableIfDeleterConvertible<_Ep>
2786 _LIBCPP_INLINE_VISIBILITY
2787 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2788 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2791 template <class _Up, class _Ep,
2792 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2793 class = _EnableIfDeleterAssignable<_Ep>
2795 _LIBCPP_INLINE_VISIBILITY
2797 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2798 reset(__u.release());
2799 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2803 #ifdef _LIBCPP_CXX03_LANG
2804 unique_ptr(unique_ptr const&) = delete;
2805 unique_ptr& operator=(unique_ptr const&) = delete;
2809 _LIBCPP_INLINE_VISIBILITY
2810 ~unique_ptr() { reset(); }
2812 _LIBCPP_INLINE_VISIBILITY
2813 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2818 _LIBCPP_INLINE_VISIBILITY
2819 typename add_lvalue_reference<_Tp>::type
2820 operator[](size_t __i) const {
2821 return __ptr_.first()[__i];
2823 _LIBCPP_INLINE_VISIBILITY
2824 pointer get() const _NOEXCEPT {
2825 return __ptr_.first();
2828 _LIBCPP_INLINE_VISIBILITY
2829 deleter_type& get_deleter() _NOEXCEPT {
2830 return __ptr_.second();
2833 _LIBCPP_INLINE_VISIBILITY
2834 const deleter_type& get_deleter() const _NOEXCEPT {
2835 return __ptr_.second();
2837 _LIBCPP_INLINE_VISIBILITY
2838 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2839 return __ptr_.first() != nullptr;
2842 _LIBCPP_INLINE_VISIBILITY
2843 pointer release() _NOEXCEPT {
2844 pointer __t = __ptr_.first();
2845 __ptr_.first() = pointer();
2849 template <class _Pp>
2850 _LIBCPP_INLINE_VISIBILITY
2852 _CheckArrayPointerConversion<_Pp>::value
2854 reset(_Pp __p) _NOEXCEPT {
2855 pointer __tmp = __ptr_.first();
2856 __ptr_.first() = __p;
2858 __ptr_.second()(__tmp);
2861 _LIBCPP_INLINE_VISIBILITY
2862 void reset(nullptr_t = nullptr) _NOEXCEPT {
2863 pointer __tmp = __ptr_.first();
2864 __ptr_.first() = nullptr;
2866 __ptr_.second()(__tmp);
2869 _LIBCPP_INLINE_VISIBILITY
2870 void swap(unique_ptr& __u) _NOEXCEPT {
2871 __ptr_.swap(__u.__ptr_);
2876 template <class _Tp, class _Dp>
2877 inline _LIBCPP_INLINE_VISIBILITY
2879 __is_swappable<_Dp>::value,
2882 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2884 template <class _T1, class _D1, class _T2, class _D2>
2885 inline _LIBCPP_INLINE_VISIBILITY
2887 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2889 template <class _T1, class _D1, class _T2, class _D2>
2890 inline _LIBCPP_INLINE_VISIBILITY
2892 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2894 template <class _T1, class _D1, class _T2, class _D2>
2895 inline _LIBCPP_INLINE_VISIBILITY
2897 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2899 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2900 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2901 typedef typename common_type<_P1, _P2>::type _Vp;
2902 return less<_Vp>()(__x.get(), __y.get());
2905 template <class _T1, class _D1, class _T2, class _D2>
2906 inline _LIBCPP_INLINE_VISIBILITY
2908 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2910 template <class _T1, class _D1, class _T2, class _D2>
2911 inline _LIBCPP_INLINE_VISIBILITY
2913 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2915 template <class _T1, class _D1, class _T2, class _D2>
2916 inline _LIBCPP_INLINE_VISIBILITY
2918 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2920 template <class _T1, class _D1>
2921 inline _LIBCPP_INLINE_VISIBILITY
2923 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2928 template <class _T1, class _D1>
2929 inline _LIBCPP_INLINE_VISIBILITY
2931 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2936 template <class _T1, class _D1>
2937 inline _LIBCPP_INLINE_VISIBILITY
2939 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2941 return static_cast<bool>(__x);
2944 template <class _T1, class _D1>
2945 inline _LIBCPP_INLINE_VISIBILITY
2947 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2949 return static_cast<bool>(__x);
2952 template <class _T1, class _D1>
2953 inline _LIBCPP_INLINE_VISIBILITY
2955 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2957 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2958 return less<_P1>()(__x.get(), nullptr);
2961 template <class _T1, class _D1>
2962 inline _LIBCPP_INLINE_VISIBILITY
2964 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2966 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2967 return less<_P1>()(nullptr, __x.get());
2970 template <class _T1, class _D1>
2971 inline _LIBCPP_INLINE_VISIBILITY
2973 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2975 return nullptr < __x;
2978 template <class _T1, class _D1>
2979 inline _LIBCPP_INLINE_VISIBILITY
2981 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2983 return __x < nullptr;
2986 template <class _T1, class _D1>
2987 inline _LIBCPP_INLINE_VISIBILITY
2989 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2991 return !(nullptr < __x);
2994 template <class _T1, class _D1>
2995 inline _LIBCPP_INLINE_VISIBILITY
2997 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2999 return !(__x < nullptr);
3002 template <class _T1, class _D1>
3003 inline _LIBCPP_INLINE_VISIBILITY
3005 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3007 return !(__x < nullptr);
3010 template <class _T1, class _D1>
3011 inline _LIBCPP_INLINE_VISIBILITY
3013 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3015 return !(nullptr < __x);
3018 #if _LIBCPP_STD_VER > 11
3023 typedef unique_ptr<_Tp> __unique_single;
3027 struct __unique_if<_Tp[]>
3029 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3032 template<class _Tp, size_t _Np>
3033 struct __unique_if<_Tp[_Np]>
3035 typedef void __unique_array_known_bound;
3038 template<class _Tp, class... _Args>
3039 inline _LIBCPP_INLINE_VISIBILITY
3040 typename __unique_if<_Tp>::__unique_single
3041 make_unique(_Args&&... __args)
3043 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3047 inline _LIBCPP_INLINE_VISIBILITY
3048 typename __unique_if<_Tp>::__unique_array_unknown_bound
3049 make_unique(size_t __n)
3051 typedef typename remove_extent<_Tp>::type _Up;
3052 return unique_ptr<_Tp>(new _Up[__n]());
3055 template<class _Tp, class... _Args>
3056 typename __unique_if<_Tp>::__unique_array_known_bound
3057 make_unique(_Args&&...) = delete;
3059 #endif // _LIBCPP_STD_VER > 11
3061 template <class _Tp, class _Dp>
3062 #ifdef _LIBCPP_CXX03_LANG
3063 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3065 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3066 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
3069 typedef unique_ptr<_Tp, _Dp> argument_type;
3070 typedef size_t result_type;
3071 _LIBCPP_INLINE_VISIBILITY
3072 result_type operator()(const argument_type& __ptr) const
3074 typedef typename argument_type::pointer pointer;
3075 return hash<pointer>()(__ptr.get());
3084 template <class _Tp>
3085 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3086 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3088 template <class _Tp>
3089 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3092 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3094 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3097 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3099 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3102 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3105 template <class _Tp>
3106 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3107 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3109 template <class _Tp>
3110 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3111 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3113 template <class _Tp>
3114 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3115 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3118 template <class _Alloc>
3119 class __allocator_destructor
3121 typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
3123 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
3124 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
3129 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3131 : __alloc_(__a), __s_(__s) {}
3132 _LIBCPP_INLINE_VISIBILITY
3133 void operator()(pointer __p) _NOEXCEPT
3134 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3137 template <class _InputIterator, class _ForwardIterator>
3139 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3141 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3142 #ifndef _LIBCPP_NO_EXCEPTIONS
3143 _ForwardIterator __s = __r;
3147 for (; __f != __l; ++__f, (void) ++__r)
3148 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3149 #ifndef _LIBCPP_NO_EXCEPTIONS
3153 for (; __s != __r; ++__s)
3161 template <class _InputIterator, class _Size, class _ForwardIterator>
3163 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3165 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3166 #ifndef _LIBCPP_NO_EXCEPTIONS
3167 _ForwardIterator __s = __r;
3171 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3172 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3173 #ifndef _LIBCPP_NO_EXCEPTIONS
3177 for (; __s != __r; ++__s)
3185 template <class _ForwardIterator, class _Tp>
3187 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3189 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3190 #ifndef _LIBCPP_NO_EXCEPTIONS
3191 _ForwardIterator __s = __f;
3195 for (; __f != __l; ++__f)
3196 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3197 #ifndef _LIBCPP_NO_EXCEPTIONS
3201 for (; __s != __f; ++__s)
3208 template <class _ForwardIterator, class _Size, class _Tp>
3210 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3212 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3213 #ifndef _LIBCPP_NO_EXCEPTIONS
3214 _ForwardIterator __s = __f;
3218 for (; __n > 0; ++__f, (void) --__n)
3219 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3220 #ifndef _LIBCPP_NO_EXCEPTIONS
3224 for (; __s != __f; ++__s)
3232 #if _LIBCPP_STD_VER > 14
3234 template <class _Tp>
3235 inline _LIBCPP_INLINE_VISIBILITY
3236 void destroy_at(_Tp* __loc) {
3237 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3241 template <class _ForwardIterator>
3242 inline _LIBCPP_INLINE_VISIBILITY
3243 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3244 for (; __first != __last; ++__first)
3245 _VSTD::destroy_at(_VSTD::addressof(*__first));
3248 template <class _ForwardIterator, class _Size>
3249 inline _LIBCPP_INLINE_VISIBILITY
3250 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3251 for (; __n > 0; (void)++__first, --__n)
3252 _VSTD::destroy_at(_VSTD::addressof(*__first));
3256 template <class _ForwardIterator>
3257 inline _LIBCPP_INLINE_VISIBILITY
3258 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3259 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3260 auto __idx = __first;
3261 #ifndef _LIBCPP_NO_EXCEPTIONS
3264 for (; __idx != __last; ++__idx)
3265 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3266 #ifndef _LIBCPP_NO_EXCEPTIONS
3268 _VSTD::destroy(__first, __idx);
3274 template <class _ForwardIterator, class _Size>
3275 inline _LIBCPP_INLINE_VISIBILITY
3276 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3277 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3278 auto __idx = __first;
3279 #ifndef _LIBCPP_NO_EXCEPTIONS
3282 for (; __n > 0; (void)++__idx, --__n)
3283 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3285 #ifndef _LIBCPP_NO_EXCEPTIONS
3287 _VSTD::destroy(__first, __idx);
3294 template <class _ForwardIterator>
3295 inline _LIBCPP_INLINE_VISIBILITY
3296 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3297 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3298 auto __idx = __first;
3299 #ifndef _LIBCPP_NO_EXCEPTIONS
3302 for (; __idx != __last; ++__idx)
3303 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3304 #ifndef _LIBCPP_NO_EXCEPTIONS
3306 _VSTD::destroy(__first, __idx);
3312 template <class _ForwardIterator, class _Size>
3313 inline _LIBCPP_INLINE_VISIBILITY
3314 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3315 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3316 auto __idx = __first;
3317 #ifndef _LIBCPP_NO_EXCEPTIONS
3320 for (; __n > 0; (void)++__idx, --__n)
3321 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3323 #ifndef _LIBCPP_NO_EXCEPTIONS
3325 _VSTD::destroy(__first, __idx);
3332 template <class _InputIt, class _ForwardIt>
3333 inline _LIBCPP_INLINE_VISIBILITY
3334 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3335 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3336 auto __idx = __first_res;
3337 #ifndef _LIBCPP_NO_EXCEPTIONS
3340 for (; __first != __last; (void)++__idx, ++__first)
3341 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3343 #ifndef _LIBCPP_NO_EXCEPTIONS
3345 _VSTD::destroy(__first_res, __idx);
3351 template <class _InputIt, class _Size, class _ForwardIt>
3352 inline _LIBCPP_INLINE_VISIBILITY
3353 pair<_InputIt, _ForwardIt>
3354 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3355 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3356 auto __idx = __first_res;
3357 #ifndef _LIBCPP_NO_EXCEPTIONS
3360 for (; __n > 0; ++__idx, (void)++__first, --__n)
3361 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3362 return {__first, __idx};
3363 #ifndef _LIBCPP_NO_EXCEPTIONS
3365 _VSTD::destroy(__first_res, __idx);
3372 #endif // _LIBCPP_STD_VER > 14
3374 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3375 // should be sufficient for thread safety.
3376 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3377 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3378 && defined(__ATOMIC_RELAXED) \
3379 && defined(__ATOMIC_ACQ_REL)
3380 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3381 #elif defined(_LIBCPP_COMPILER_GCC)
3382 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3385 template <class _Tp>
3386 inline _LIBCPP_INLINE_VISIBILITY _Tp
3387 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3389 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3390 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3396 template <class _Tp>
3397 inline _LIBCPP_INLINE_VISIBILITY _Tp
3398 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3400 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3401 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3407 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3408 : public std::exception
3411 virtual ~bad_weak_ptr() _NOEXCEPT;
3412 virtual const char* what() const _NOEXCEPT;
3415 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
3416 void __throw_bad_weak_ptr()
3418 #ifndef _LIBCPP_NO_EXCEPTIONS
3419 throw bad_weak_ptr();
3425 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3427 class _LIBCPP_TYPE_VIS __shared_count
3429 __shared_count(const __shared_count&);
3430 __shared_count& operator=(const __shared_count&);
3433 long __shared_owners_;
3434 virtual ~__shared_count();
3436 virtual void __on_zero_shared() _NOEXCEPT = 0;
3439 _LIBCPP_INLINE_VISIBILITY
3440 explicit __shared_count(long __refs = 0) _NOEXCEPT
3441 : __shared_owners_(__refs) {}
3443 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3444 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3445 void __add_shared() _NOEXCEPT;
3446 bool __release_shared() _NOEXCEPT;
3448 _LIBCPP_INLINE_VISIBILITY
3449 void __add_shared() _NOEXCEPT {
3450 __libcpp_atomic_refcount_increment(__shared_owners_);
3452 _LIBCPP_INLINE_VISIBILITY
3453 bool __release_shared() _NOEXCEPT {
3454 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3461 _LIBCPP_INLINE_VISIBILITY
3462 long use_count() const _NOEXCEPT {
3463 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3467 class _LIBCPP_TYPE_VIS __shared_weak_count
3468 : private __shared_count
3470 long __shared_weak_owners_;
3473 _LIBCPP_INLINE_VISIBILITY
3474 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3475 : __shared_count(__refs),
3476 __shared_weak_owners_(__refs) {}
3478 virtual ~__shared_weak_count();
3481 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3482 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3483 void __add_shared() _NOEXCEPT;
3484 void __add_weak() _NOEXCEPT;
3485 void __release_shared() _NOEXCEPT;
3487 _LIBCPP_INLINE_VISIBILITY
3488 void __add_shared() _NOEXCEPT {
3489 __shared_count::__add_shared();
3491 _LIBCPP_INLINE_VISIBILITY
3492 void __add_weak() _NOEXCEPT {
3493 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3495 _LIBCPP_INLINE_VISIBILITY
3496 void __release_shared() _NOEXCEPT {
3497 if (__shared_count::__release_shared())
3501 void __release_weak() _NOEXCEPT;
3502 _LIBCPP_INLINE_VISIBILITY
3503 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3504 __shared_weak_count* lock() _NOEXCEPT;
3506 // Define the function out only if we build static libc++ without RTTI.
3507 // Otherwise we may break clients who need to compile their projects with
3508 // -fno-rtti and yet link against a libc++.dylib compiled
3509 // without -fno-rtti.
3510 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3511 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3514 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3517 template <class _Tp, class _Dp, class _Alloc>
3518 class __shared_ptr_pointer
3519 : public __shared_weak_count
3521 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3523 _LIBCPP_INLINE_VISIBILITY
3524 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3525 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3527 #ifndef _LIBCPP_NO_RTTI
3528 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3532 virtual void __on_zero_shared() _NOEXCEPT;
3533 virtual void __on_zero_shared_weak() _NOEXCEPT;
3536 #ifndef _LIBCPP_NO_RTTI
3538 template <class _Tp, class _Dp, class _Alloc>
3540 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3542 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3545 #endif // _LIBCPP_NO_RTTI
3547 template <class _Tp, class _Dp, class _Alloc>
3549 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3551 __data_.first().second()(__data_.first().first());
3552 __data_.first().second().~_Dp();
3555 template <class _Tp, class _Dp, class _Alloc>
3557 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3559 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3560 typedef allocator_traits<_Al> _ATraits;
3561 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3563 _Al __a(__data_.second());
3564 __data_.second().~_Alloc();
3565 __a.deallocate(_PTraits::pointer_to(*this), 1);
3568 template <class _Tp, class _Alloc>
3569 class __shared_ptr_emplace
3570 : public __shared_weak_count
3572 __compressed_pair<_Alloc, _Tp> __data_;
3574 #ifndef _LIBCPP_HAS_NO_VARIADICS
3576 _LIBCPP_INLINE_VISIBILITY
3577 __shared_ptr_emplace(_Alloc __a)
3578 : __data_(_VSTD::move(__a)) {}
3580 template <class ..._Args>
3581 _LIBCPP_INLINE_VISIBILITY
3582 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3583 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3584 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3586 #else // _LIBCPP_HAS_NO_VARIADICS
3588 _LIBCPP_INLINE_VISIBILITY
3589 __shared_ptr_emplace(_Alloc __a)
3592 template <class _A0>
3593 _LIBCPP_INLINE_VISIBILITY
3594 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3595 : __data_(__a, _Tp(__a0)) {}
3597 template <class _A0, class _A1>
3598 _LIBCPP_INLINE_VISIBILITY
3599 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3600 : __data_(__a, _Tp(__a0, __a1)) {}
3602 template <class _A0, class _A1, class _A2>
3603 _LIBCPP_INLINE_VISIBILITY
3604 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3605 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3607 #endif // _LIBCPP_HAS_NO_VARIADICS
3610 virtual void __on_zero_shared() _NOEXCEPT;
3611 virtual void __on_zero_shared_weak() _NOEXCEPT;
3613 _LIBCPP_INLINE_VISIBILITY
3614 _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
3617 template <class _Tp, class _Alloc>
3619 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3621 __data_.second().~_Tp();
3624 template <class _Tp, class _Alloc>
3626 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3628 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3629 typedef allocator_traits<_Al> _ATraits;
3630 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3631 _Al __a(__data_.first());
3632 __data_.first().~_Alloc();
3633 __a.deallocate(_PTraits::pointer_to(*this), 1);
3636 struct __shared_ptr_dummy_rebind_allocator_type;
3638 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3641 template <class _Other>
3644 typedef allocator<_Other> other;
3648 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3651 class _LIBCPP_TEMPLATE_VIS shared_ptr
3654 typedef _Tp element_type;
3656 #if _LIBCPP_STD_VER > 14
3657 typedef weak_ptr<_Tp> weak_type;
3660 element_type* __ptr_;
3661 __shared_weak_count* __cntrl_;
3663 struct __nat {int __for_bool_;};
3665 _LIBCPP_INLINE_VISIBILITY
3666 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3667 _LIBCPP_INLINE_VISIBILITY
3668 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3670 explicit shared_ptr(_Yp* __p,
3671 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3672 template<class _Yp, class _Dp>
3673 shared_ptr(_Yp* __p, _Dp __d,
3674 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3675 template<class _Yp, class _Dp, class _Alloc>
3676 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3677 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3678 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3679 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3680 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3681 _LIBCPP_INLINE_VISIBILITY
3682 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3684 _LIBCPP_INLINE_VISIBILITY
3685 shared_ptr(const shared_ptr<_Yp>& __r,
3686 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3688 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3689 _LIBCPP_INLINE_VISIBILITY
3690 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3691 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3692 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3694 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3695 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3696 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3697 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3698 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3700 shared_ptr(auto_ptr<_Yp>&& __r,
3701 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3704 shared_ptr(auto_ptr<_Yp> __r,
3705 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3708 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3709 template <class _Yp, class _Dp>
3710 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3713 !is_lvalue_reference<_Dp>::value &&
3714 !is_array<_Yp>::value &&
3715 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3718 template <class _Yp, class _Dp>
3719 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3722 is_lvalue_reference<_Dp>::value &&
3723 !is_array<_Yp>::value &&
3724 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3727 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3728 template <class _Yp, class _Dp>
3729 shared_ptr(unique_ptr<_Yp, _Dp>,
3732 !is_lvalue_reference<_Dp>::value &&
3733 !is_array<_Yp>::value &&
3734 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3737 template <class _Yp, class _Dp>
3738 shared_ptr(unique_ptr<_Yp, _Dp>,
3741 is_lvalue_reference<_Dp>::value &&
3742 !is_array<_Yp>::value &&
3743 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3746 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3750 _LIBCPP_INLINE_VISIBILITY
3751 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3755 is_convertible<_Yp*, element_type*>::value,
3758 _LIBCPP_INLINE_VISIBILITY
3759 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3760 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3761 _LIBCPP_INLINE_VISIBILITY
3762 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3766 is_convertible<_Yp*, element_type*>::value,
3769 _LIBCPP_INLINE_VISIBILITY
3770 operator=(shared_ptr<_Yp>&& __r);
3771 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3773 _LIBCPP_INLINE_VISIBILITY
3776 !is_array<_Yp>::value &&
3777 is_convertible<_Yp*, element_type*>::value,
3780 operator=(auto_ptr<_Yp>&& __r);
3782 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3783 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3785 _LIBCPP_INLINE_VISIBILITY
3788 !is_array<_Yp>::value &&
3789 is_convertible<_Yp*, element_type*>::value,
3792 operator=(auto_ptr<_Yp> __r);
3795 template <class _Yp, class _Dp>
3798 !is_array<_Yp>::value &&
3799 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3802 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3803 _LIBCPP_INLINE_VISIBILITY
3804 operator=(unique_ptr<_Yp, _Dp>&& __r);
3805 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3806 _LIBCPP_INLINE_VISIBILITY
3807 operator=(unique_ptr<_Yp, _Dp> __r);
3810 _LIBCPP_INLINE_VISIBILITY
3811 void swap(shared_ptr& __r) _NOEXCEPT;
3812 _LIBCPP_INLINE_VISIBILITY
3813 void reset() _NOEXCEPT;
3817 is_convertible<_Yp*, element_type*>::value,
3820 _LIBCPP_INLINE_VISIBILITY
3822 template<class _Yp, class _Dp>
3825 is_convertible<_Yp*, element_type*>::value,
3828 _LIBCPP_INLINE_VISIBILITY
3829 reset(_Yp* __p, _Dp __d);
3830 template<class _Yp, class _Dp, class _Alloc>
3833 is_convertible<_Yp*, element_type*>::value,
3836 _LIBCPP_INLINE_VISIBILITY
3837 reset(_Yp* __p, _Dp __d, _Alloc __a);
3839 _LIBCPP_INLINE_VISIBILITY
3840 element_type* get() const _NOEXCEPT {return __ptr_;}
3841 _LIBCPP_INLINE_VISIBILITY
3842 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3844 _LIBCPP_INLINE_VISIBILITY
3845 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3846 _LIBCPP_INLINE_VISIBILITY
3847 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3848 _LIBCPP_INLINE_VISIBILITY
3849 bool unique() const _NOEXCEPT {return use_count() == 1;}
3850 _LIBCPP_INLINE_VISIBILITY
3851 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3852 template <class _Up>
3853 _LIBCPP_INLINE_VISIBILITY
3854 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3855 {return __cntrl_ < __p.__cntrl_;}
3856 template <class _Up>
3857 _LIBCPP_INLINE_VISIBILITY
3858 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3859 {return __cntrl_ < __p.__cntrl_;}
3860 _LIBCPP_INLINE_VISIBILITY
3862 __owner_equivalent(const shared_ptr& __p) const
3863 {return __cntrl_ == __p.__cntrl_;}
3865 #ifndef _LIBCPP_NO_RTTI
3866 template <class _Dp>
3867 _LIBCPP_INLINE_VISIBILITY
3868 _Dp* __get_deleter() const _NOEXCEPT
3869 {return static_cast<_Dp*>(__cntrl_
3870 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3872 #endif // _LIBCPP_NO_RTTI
3874 template<class _Yp, class _CntrlBlk>
3875 static shared_ptr<_Tp>
3876 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
3878 shared_ptr<_Tp> __r;
3880 __r.__cntrl_ = __cntrl;
3881 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
3885 template<class _Alloc, class ..._Args>
3888 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3891 template <class _Yp, bool = is_function<_Yp>::value>
3892 struct __shared_ptr_default_allocator
3894 typedef allocator<_Yp> type;
3897 template <class _Yp>
3898 struct __shared_ptr_default_allocator<_Yp, true>
3900 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3903 template <class _Yp, class _OrigPtr>
3904 _LIBCPP_INLINE_VISIBILITY
3905 typename enable_if<is_convertible<_OrigPtr*,
3906 const enable_shared_from_this<_Yp>*
3909 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3910 _OrigPtr* __ptr) _NOEXCEPT
3912 typedef typename remove_cv<_Yp>::type _RawYp;
3913 if (__e && __e->__weak_this_.expired())
3915 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3916 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
3920 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
3922 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3923 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
3930 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3939 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
3947 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3948 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3951 unique_ptr<_Yp> __hold(__p);
3952 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3953 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
3954 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
3956 __enable_weak_this(__p, __p);
3960 template<class _Yp, class _Dp>
3961 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
3962 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3965 #ifndef _LIBCPP_NO_EXCEPTIONS
3968 #endif // _LIBCPP_NO_EXCEPTIONS
3969 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3970 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
3971 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
3972 __enable_weak_this(__p, __p);
3973 #ifndef _LIBCPP_NO_EXCEPTIONS
3980 #endif // _LIBCPP_NO_EXCEPTIONS
3985 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
3988 #ifndef _LIBCPP_NO_EXCEPTIONS
3991 #endif // _LIBCPP_NO_EXCEPTIONS
3992 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
3993 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
3994 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
3995 #ifndef _LIBCPP_NO_EXCEPTIONS
4002 #endif // _LIBCPP_NO_EXCEPTIONS
4006 template<class _Yp, class _Dp, class _Alloc>
4007 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4008 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4011 #ifndef _LIBCPP_NO_EXCEPTIONS
4014 #endif // _LIBCPP_NO_EXCEPTIONS
4015 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4016 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4017 typedef __allocator_destructor<_A2> _D2;
4019 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4020 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4021 _CntrlBlk(__p, __d, __a);
4022 __cntrl_ = _VSTD::addressof(*__hold2.release());
4023 __enable_weak_this(__p, __p);
4024 #ifndef _LIBCPP_NO_EXCEPTIONS
4031 #endif // _LIBCPP_NO_EXCEPTIONS
4035 template<class _Dp, class _Alloc>
4036 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4039 #ifndef _LIBCPP_NO_EXCEPTIONS
4042 #endif // _LIBCPP_NO_EXCEPTIONS
4043 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4044 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4045 typedef __allocator_destructor<_A2> _D2;
4047 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4048 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4049 _CntrlBlk(__p, __d, __a);
4050 __cntrl_ = _VSTD::addressof(*__hold2.release());
4051 #ifndef _LIBCPP_NO_EXCEPTIONS
4058 #endif // _LIBCPP_NO_EXCEPTIONS
4064 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4066 __cntrl_(__r.__cntrl_)
4069 __cntrl_->__add_shared();
4074 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4075 : __ptr_(__r.__ptr_),
4076 __cntrl_(__r.__cntrl_)
4079 __cntrl_->__add_shared();
4085 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4086 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4088 : __ptr_(__r.__ptr_),
4089 __cntrl_(__r.__cntrl_)
4092 __cntrl_->__add_shared();
4095 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4099 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4100 : __ptr_(__r.__ptr_),
4101 __cntrl_(__r.__cntrl_)
4110 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4111 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4113 : __ptr_(__r.__ptr_),
4114 __cntrl_(__r.__cntrl_)
4120 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4122 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4125 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4126 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4128 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4130 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4133 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4134 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4135 __enable_weak_this(__r.get(), __r.get());
4141 template <class _Yp, class _Dp>
4142 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4143 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4145 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4149 !is_lvalue_reference<_Dp>::value &&
4150 !is_array<_Yp>::value &&
4151 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4156 #if _LIBCPP_STD_VER > 11
4157 if (__ptr_ == nullptr)
4162 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4163 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4164 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4165 __enable_weak_this(__r.get(), __r.get());
4171 template <class _Yp, class _Dp>
4172 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4173 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4175 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4179 is_lvalue_reference<_Dp>::value &&
4180 !is_array<_Yp>::value &&
4181 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4186 #if _LIBCPP_STD_VER > 11
4187 if (__ptr_ == nullptr)
4192 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4193 typedef __shared_ptr_pointer<_Yp*,
4194 reference_wrapper<typename remove_reference<_Dp>::type>,
4195 _AllocT > _CntrlBlk;
4196 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4197 __enable_weak_this(__r.get(), __r.get());
4203 template<class _Alloc, class ..._Args>
4205 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4207 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4208 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4209 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4210 typedef __allocator_destructor<_A2> _D2;
4212 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4213 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4214 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4215 shared_ptr<_Tp> __r;
4216 __r.__ptr_ = __hold2.get()->get();
4217 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4218 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4223 shared_ptr<_Tp>::~shared_ptr()
4226 __cntrl_->__release_shared();
4232 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4234 shared_ptr(__r).swap(*this);
4243 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4246 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4248 shared_ptr(__r).swap(*this);
4252 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4257 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4259 shared_ptr(_VSTD::move(__r)).swap(*this);
4268 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4271 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4273 shared_ptr(_VSTD::move(__r)).swap(*this);
4277 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4283 !is_array<_Yp>::value &&
4284 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4287 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4289 shared_ptr(_VSTD::move(__r)).swap(*this);
4295 template <class _Yp, class _Dp>
4299 !is_array<_Yp>::value &&
4300 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4301 typename shared_ptr<_Tp>::element_type*>::value,
4304 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4306 shared_ptr(_VSTD::move(__r)).swap(*this);
4310 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4312 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4315 inline _LIBCPP_INLINE_VISIBILITY
4318 !is_array<_Yp>::value &&
4319 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4322 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4324 shared_ptr(__r).swap(*this);
4330 template <class _Yp, class _Dp>
4331 inline _LIBCPP_INLINE_VISIBILITY
4334 !is_array<_Yp>::value &&
4335 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4336 typename shared_ptr<_Tp>::element_type*>::value,
4339 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4341 shared_ptr(_VSTD::move(__r)).swap(*this);
4345 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4350 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4352 _VSTD::swap(__ptr_, __r.__ptr_);
4353 _VSTD::swap(__cntrl_, __r.__cntrl_);
4359 shared_ptr<_Tp>::reset() _NOEXCEPT
4361 shared_ptr().swap(*this);
4369 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4372 shared_ptr<_Tp>::reset(_Yp* __p)
4374 shared_ptr(__p).swap(*this);
4378 template<class _Yp, class _Dp>
4382 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4385 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4387 shared_ptr(__p, __d).swap(*this);
4391 template<class _Yp, class _Dp, class _Alloc>
4395 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4398 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4400 shared_ptr(__p, __d, __a).swap(*this);
4403 template<class _Tp, class ..._Args>
4404 inline _LIBCPP_INLINE_VISIBILITY
4407 !is_array<_Tp>::value,
4410 make_shared(_Args&& ...__args)
4412 static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
4413 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4414 typedef allocator<_CntrlBlk> _A2;
4415 typedef __allocator_destructor<_A2> _D2;
4418 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4419 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4421 _Tp *__ptr = __hold2.get()->get();
4422 return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
4425 template<class _Tp, class _Alloc, class ..._Args>
4426 inline _LIBCPP_INLINE_VISIBILITY
4429 !is_array<_Tp>::value,
4432 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4434 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4437 template<class _Tp, class _Up>
4438 inline _LIBCPP_INLINE_VISIBILITY
4440 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4442 return __x.get() == __y.get();
4445 template<class _Tp, class _Up>
4446 inline _LIBCPP_INLINE_VISIBILITY
4448 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4450 return !(__x == __y);
4453 template<class _Tp, class _Up>
4454 inline _LIBCPP_INLINE_VISIBILITY
4456 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4458 #if _LIBCPP_STD_VER <= 11
4459 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4460 return less<_Vp>()(__x.get(), __y.get());
4462 return less<>()(__x.get(), __y.get());
4467 template<class _Tp, class _Up>
4468 inline _LIBCPP_INLINE_VISIBILITY
4470 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4475 template<class _Tp, class _Up>
4476 inline _LIBCPP_INLINE_VISIBILITY
4478 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4480 return !(__y < __x);
4483 template<class _Tp, class _Up>
4484 inline _LIBCPP_INLINE_VISIBILITY
4486 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4488 return !(__x < __y);
4492 inline _LIBCPP_INLINE_VISIBILITY
4494 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4500 inline _LIBCPP_INLINE_VISIBILITY
4502 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4508 inline _LIBCPP_INLINE_VISIBILITY
4510 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4512 return static_cast<bool>(__x);
4516 inline _LIBCPP_INLINE_VISIBILITY
4518 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4520 return static_cast<bool>(__x);
4524 inline _LIBCPP_INLINE_VISIBILITY
4526 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4528 return less<_Tp*>()(__x.get(), nullptr);
4532 inline _LIBCPP_INLINE_VISIBILITY
4534 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4536 return less<_Tp*>()(nullptr, __x.get());
4540 inline _LIBCPP_INLINE_VISIBILITY
4542 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4544 return nullptr < __x;
4548 inline _LIBCPP_INLINE_VISIBILITY
4550 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4552 return __x < nullptr;
4556 inline _LIBCPP_INLINE_VISIBILITY
4558 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4560 return !(nullptr < __x);
4564 inline _LIBCPP_INLINE_VISIBILITY
4566 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4568 return !(__x < nullptr);
4572 inline _LIBCPP_INLINE_VISIBILITY
4574 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4576 return !(__x < nullptr);
4580 inline _LIBCPP_INLINE_VISIBILITY
4582 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4584 return !(nullptr < __x);
4588 inline _LIBCPP_INLINE_VISIBILITY
4590 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4595 template<class _Tp, class _Up>
4596 inline _LIBCPP_INLINE_VISIBILITY
4599 !is_array<_Tp>::value && !is_array<_Up>::value,
4602 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4604 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4607 template<class _Tp, class _Up>
4608 inline _LIBCPP_INLINE_VISIBILITY
4611 !is_array<_Tp>::value && !is_array<_Up>::value,
4614 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4616 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4617 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4620 template<class _Tp, class _Up>
4623 is_array<_Tp>::value == is_array<_Up>::value,
4626 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4628 typedef typename remove_extent<_Tp>::type _RTp;
4629 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4632 #ifndef _LIBCPP_NO_RTTI
4634 template<class _Dp, class _Tp>
4635 inline _LIBCPP_INLINE_VISIBILITY
4637 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4639 return __p.template __get_deleter<_Dp>();
4642 #endif // _LIBCPP_NO_RTTI
4645 class _LIBCPP_TEMPLATE_VIS weak_ptr
4648 typedef _Tp element_type;
4650 element_type* __ptr_;
4651 __shared_weak_count* __cntrl_;
4654 _LIBCPP_INLINE_VISIBILITY
4655 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4656 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4657 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4659 _LIBCPP_INLINE_VISIBILITY
4660 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4661 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
4662 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4665 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4666 _LIBCPP_INLINE_VISIBILITY
4667 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4668 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
4669 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4671 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4674 _LIBCPP_INLINE_VISIBILITY
4675 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4679 is_convertible<_Yp*, element_type*>::value,
4682 _LIBCPP_INLINE_VISIBILITY
4683 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4685 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4687 _LIBCPP_INLINE_VISIBILITY
4688 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4692 is_convertible<_Yp*, element_type*>::value,
4695 _LIBCPP_INLINE_VISIBILITY
4696 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4698 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4703 is_convertible<_Yp*, element_type*>::value,
4706 _LIBCPP_INLINE_VISIBILITY
4707 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4709 _LIBCPP_INLINE_VISIBILITY
4710 void swap(weak_ptr& __r) _NOEXCEPT;
4711 _LIBCPP_INLINE_VISIBILITY
4712 void reset() _NOEXCEPT;
4714 _LIBCPP_INLINE_VISIBILITY
4715 long use_count() const _NOEXCEPT
4716 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4717 _LIBCPP_INLINE_VISIBILITY
4718 bool expired() const _NOEXCEPT
4719 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4720 shared_ptr<_Tp> lock() const _NOEXCEPT;
4722 _LIBCPP_INLINE_VISIBILITY
4723 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
4724 {return __cntrl_ < __r.__cntrl_;}
4726 _LIBCPP_INLINE_VISIBILITY
4727 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
4728 {return __cntrl_ < __r.__cntrl_;}
4730 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4731 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4737 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4745 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
4746 : __ptr_(__r.__ptr_),
4747 __cntrl_(__r.__cntrl_)
4750 __cntrl_->__add_weak();
4756 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
4757 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4759 : __ptr_(__r.__ptr_),
4760 __cntrl_(__r.__cntrl_)
4763 __cntrl_->__add_weak();
4769 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
4770 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4772 : __ptr_(__r.__ptr_),
4773 __cntrl_(__r.__cntrl_)
4776 __cntrl_->__add_weak();
4779 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4783 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
4784 : __ptr_(__r.__ptr_),
4785 __cntrl_(__r.__cntrl_)
4794 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
4795 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4797 : __ptr_(__r.__ptr_),
4798 __cntrl_(__r.__cntrl_)
4804 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4807 weak_ptr<_Tp>::~weak_ptr()
4810 __cntrl_->__release_weak();
4816 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
4818 weak_ptr(__r).swap(*this);
4827 is_convertible<_Yp*, _Tp*>::value,
4830 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
4832 weak_ptr(__r).swap(*this);
4836 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4841 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
4843 weak_ptr(_VSTD::move(__r)).swap(*this);
4852 is_convertible<_Yp*, _Tp*>::value,
4855 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
4857 weak_ptr(_VSTD::move(__r)).swap(*this);
4861 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4868 is_convertible<_Yp*, _Tp*>::value,
4871 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
4873 weak_ptr(__r).swap(*this);
4880 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
4882 _VSTD::swap(__ptr_, __r.__ptr_);
4883 _VSTD::swap(__cntrl_, __r.__cntrl_);
4887 inline _LIBCPP_INLINE_VISIBILITY
4889 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
4897 weak_ptr<_Tp>::reset() _NOEXCEPT
4899 weak_ptr().swap(*this);
4904 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
4905 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4906 : __ptr_(__r.__ptr_),
4907 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
4910 __throw_bad_weak_ptr();
4915 weak_ptr<_Tp>::lock() const _NOEXCEPT
4917 shared_ptr<_Tp> __r;
4918 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
4920 __r.__ptr_ = __ptr_;
4924 #if _LIBCPP_STD_VER > 14
4925 template <class _Tp = void> struct owner_less;
4927 template <class _Tp> struct owner_less;
4930 template <class _Tp>
4931 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
4932 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
4934 typedef bool result_type;
4935 _LIBCPP_INLINE_VISIBILITY
4936 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
4937 {return __x.owner_before(__y);}
4938 _LIBCPP_INLINE_VISIBILITY
4939 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
4940 {return __x.owner_before(__y);}
4941 _LIBCPP_INLINE_VISIBILITY
4942 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
4943 {return __x.owner_before(__y);}
4946 template <class _Tp>
4947 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
4948 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
4950 typedef bool result_type;
4951 _LIBCPP_INLINE_VISIBILITY
4952 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
4953 {return __x.owner_before(__y);}
4954 _LIBCPP_INLINE_VISIBILITY
4955 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
4956 {return __x.owner_before(__y);}
4957 _LIBCPP_INLINE_VISIBILITY
4958 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
4959 {return __x.owner_before(__y);}
4962 #if _LIBCPP_STD_VER > 14
4964 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
4966 template <class _Tp, class _Up>
4967 _LIBCPP_INLINE_VISIBILITY
4968 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
4969 {return __x.owner_before(__y);}
4970 template <class _Tp, class _Up>
4971 _LIBCPP_INLINE_VISIBILITY
4972 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
4973 {return __x.owner_before(__y);}
4974 template <class _Tp, class _Up>
4975 _LIBCPP_INLINE_VISIBILITY
4976 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
4977 {return __x.owner_before(__y);}
4978 template <class _Tp, class _Up>
4979 _LIBCPP_INLINE_VISIBILITY
4980 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
4981 {return __x.owner_before(__y);}
4982 typedef void is_transparent;
4987 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
4989 mutable weak_ptr<_Tp> __weak_this_;
4991 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4992 enable_shared_from_this() _NOEXCEPT {}
4993 _LIBCPP_INLINE_VISIBILITY
4994 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
4995 _LIBCPP_INLINE_VISIBILITY
4996 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
4998 _LIBCPP_INLINE_VISIBILITY
4999 ~enable_shared_from_this() {}
5001 _LIBCPP_INLINE_VISIBILITY
5002 shared_ptr<_Tp> shared_from_this()
5003 {return shared_ptr<_Tp>(__weak_this_);}
5004 _LIBCPP_INLINE_VISIBILITY
5005 shared_ptr<_Tp const> shared_from_this() const
5006 {return shared_ptr<const _Tp>(__weak_this_);}
5008 #if _LIBCPP_STD_VER > 14
5009 _LIBCPP_INLINE_VISIBILITY
5010 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5011 { return __weak_this_; }
5013 _LIBCPP_INLINE_VISIBILITY
5014 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5015 { return __weak_this_; }
5016 #endif // _LIBCPP_STD_VER > 14
5018 template <class _Up> friend class shared_ptr;
5021 template <class _Tp>
5022 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5024 typedef shared_ptr<_Tp> argument_type;
5025 typedef size_t result_type;
5027 _LIBCPP_INLINE_VISIBILITY
5028 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5030 return hash<_Tp*>()(__ptr.get());
5034 template<class _CharT, class _Traits, class _Yp>
5035 inline _LIBCPP_INLINE_VISIBILITY
5036 basic_ostream<_CharT, _Traits>&
5037 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5040 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5042 class _LIBCPP_TYPE_VIS __sp_mut
5046 void lock() _NOEXCEPT;
5047 void unlock() _NOEXCEPT;
5050 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5051 __sp_mut(const __sp_mut&);
5052 __sp_mut& operator=(const __sp_mut&);
5054 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5057 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5058 __sp_mut& __get_sp_mut(const void*);
5060 template <class _Tp>
5061 inline _LIBCPP_INLINE_VISIBILITY
5063 atomic_is_lock_free(const shared_ptr<_Tp>*)
5068 template <class _Tp>
5069 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5071 atomic_load(const shared_ptr<_Tp>* __p)
5073 __sp_mut& __m = __get_sp_mut(__p);
5075 shared_ptr<_Tp> __q = *__p;
5080 template <class _Tp>
5081 inline _LIBCPP_INLINE_VISIBILITY
5082 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5084 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5086 return atomic_load(__p);
5089 template <class _Tp>
5090 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5092 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5094 __sp_mut& __m = __get_sp_mut(__p);
5100 template <class _Tp>
5101 inline _LIBCPP_INLINE_VISIBILITY
5102 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5104 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5106 atomic_store(__p, __r);
5109 template <class _Tp>
5110 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5112 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5114 __sp_mut& __m = __get_sp_mut(__p);
5121 template <class _Tp>
5122 inline _LIBCPP_INLINE_VISIBILITY
5123 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5125 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5127 return atomic_exchange(__p, __r);
5130 template <class _Tp>
5131 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5133 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5135 shared_ptr<_Tp> __temp;
5136 __sp_mut& __m = __get_sp_mut(__p);
5138 if (__p->__owner_equivalent(*__v))
5140 _VSTD::swap(__temp, *__p);
5145 _VSTD::swap(__temp, *__v);
5151 template <class _Tp>
5152 inline _LIBCPP_INLINE_VISIBILITY
5153 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5155 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5157 return atomic_compare_exchange_strong(__p, __v, __w);
5160 template <class _Tp>
5161 inline _LIBCPP_INLINE_VISIBILITY
5162 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5164 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5165 shared_ptr<_Tp> __w, memory_order, memory_order)
5167 return atomic_compare_exchange_strong(__p, __v, __w);
5170 template <class _Tp>
5171 inline _LIBCPP_INLINE_VISIBILITY
5172 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5174 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5175 shared_ptr<_Tp> __w, memory_order, memory_order)
5177 return atomic_compare_exchange_weak(__p, __v, __w);
5180 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5183 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5184 # ifndef _LIBCPP_CXX03_LANG
5185 enum class pointer_safety : unsigned char {
5192 struct _LIBCPP_TYPE_VIS pointer_safety
5203 _LIBCPP_INLINE_VISIBILITY
5204 pointer_safety() : __v_() {}
5206 _LIBCPP_INLINE_VISIBILITY
5207 pointer_safety(__lx __v) : __v_(__v) {}
5208 _LIBCPP_INLINE_VISIBILITY
5209 operator int() const {return __v_;}
5213 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5214 defined(_LIBCPP_BUILDING_LIBRARY)
5215 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5217 // This function is only offered in C++03 under ABI v1.
5218 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5219 inline _LIBCPP_INLINE_VISIBILITY
5220 pointer_safety get_pointer_safety() _NOEXCEPT {
5221 return pointer_safety::relaxed;
5227 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5228 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5229 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5230 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5232 template <class _Tp>
5233 inline _LIBCPP_INLINE_VISIBILITY
5235 undeclare_reachable(_Tp* __p)
5237 return static_cast<_Tp*>(__undeclare_reachable(__p));
5240 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5242 // --- Helper for container swap --
5243 template <typename _Alloc>
5244 inline _LIBCPP_INLINE_VISIBILITY
5245 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5246 #if _LIBCPP_STD_VER >= 14
5249 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5252 __swap_allocator(__a1, __a2,
5253 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5256 template <typename _Alloc>
5257 _LIBCPP_INLINE_VISIBILITY
5258 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5259 #if _LIBCPP_STD_VER >= 14
5262 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5269 template <typename _Alloc>
5270 inline _LIBCPP_INLINE_VISIBILITY
5271 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5273 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5274 struct __noexcept_move_assign_container : public integral_constant<bool,
5275 _Traits::propagate_on_container_move_assignment::value
5276 #if _LIBCPP_STD_VER > 14
5277 || _Traits::is_always_equal::value
5279 && is_nothrow_move_assignable<_Alloc>::value
5284 #ifndef _LIBCPP_HAS_NO_VARIADICS
5285 template <class _Tp, class _Alloc>
5286 struct __temp_value {
5287 typedef allocator_traits<_Alloc> _Traits;
5289 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
5292 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5293 _Tp & get() { return *__addr(); }
5295 template<class... _Args>
5297 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
5298 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
5299 _VSTD::forward<_Args>(__args)...);
5302 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5306 template<typename _Alloc, typename = void, typename = void>
5307 struct __is_allocator : false_type {};
5309 template<typename _Alloc>
5310 struct __is_allocator<_Alloc,
5311 typename __void_t<typename _Alloc::value_type>::type,
5312 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
5316 // __builtin_new_allocator -- A non-templated helper for allocating and
5317 // deallocating memory using __builtin_operator_new and
5318 // __builtin_operator_delete. It should be used in preference to
5319 // `std::allocator<T>` to avoid additional instantiations.
5320 struct __builtin_new_allocator {
5321 struct __builtin_new_deleter {
5322 typedef void* pointer_type;
5324 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
5325 : __size_(__size), __align_(__align) {}
5327 void operator()(void* p) const _NOEXCEPT {
5328 std::__libcpp_deallocate(p, __size_, __align_);
5336 typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
5338 static __holder_t __allocate_bytes(size_t __s, size_t __align) {
5339 return __holder_t(std::__libcpp_allocate(__s, __align),
5340 __builtin_new_deleter(__s, __align));
5343 static void __deallocate_bytes(void* __p, size_t __s,
5344 size_t __align) _NOEXCEPT {
5345 std::__libcpp_deallocate(__p, __s, __align);
5348 template <class _Tp>
5349 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5350 static __holder_t __allocate_type(size_t __n) {
5351 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5354 template <class _Tp>
5355 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5356 static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
5357 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5362 _LIBCPP_END_NAMESPACE_STD
5366 #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
5367 # include <__pstl_memory>
5370 #endif // _LIBCPP_MEMORY