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>
666 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
671 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
672 #pragma GCC system_header
676 #include <__undef_macros>
679 _LIBCPP_BEGIN_NAMESPACE_STD
681 template <class _ValueType>
682 inline _LIBCPP_INLINE_VISIBILITY
683 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
684 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
685 defined(__ATOMIC_RELAXED) && \
686 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
687 return __atomic_load_n(__value, __ATOMIC_RELAXED);
693 template <class _ValueType>
694 inline _LIBCPP_INLINE_VISIBILITY
695 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
696 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
697 defined(__ATOMIC_ACQUIRE) && \
698 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
699 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
705 // addressof moved to <type_traits>
707 template <class _Tp> class allocator;
710 class _LIBCPP_TEMPLATE_VIS allocator<void>
713 typedef void* pointer;
714 typedef const void* const_pointer;
715 typedef void value_type;
717 template <class _Up> struct rebind {typedef allocator<_Up> other;};
721 class _LIBCPP_TEMPLATE_VIS allocator<const void>
724 typedef const void* pointer;
725 typedef const void* const_pointer;
726 typedef const void value_type;
728 template <class _Up> struct rebind {typedef allocator<_Up> other;};
733 template <class _Tp, class = void>
734 struct __has_element_type : false_type {};
737 struct __has_element_type<_Tp,
738 typename __void_t<typename _Tp::element_type>::type> : true_type {};
740 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
741 struct __pointer_traits_element_type;
743 template <class _Ptr>
744 struct __pointer_traits_element_type<_Ptr, true>
746 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
749 #ifndef _LIBCPP_HAS_NO_VARIADICS
751 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
752 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
754 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
757 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
758 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
760 typedef _LIBCPP_NODEBUG_TYPE _Tp type;
763 #else // _LIBCPP_HAS_NO_VARIADICS
765 template <template <class> class _Sp, class _Tp>
766 struct __pointer_traits_element_type<_Sp<_Tp>, true>
768 typedef typename _Sp<_Tp>::element_type type;
771 template <template <class> class _Sp, class _Tp>
772 struct __pointer_traits_element_type<_Sp<_Tp>, false>
777 template <template <class, class> class _Sp, class _Tp, class _A0>
778 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
780 typedef typename _Sp<_Tp, _A0>::element_type type;
783 template <template <class, class> class _Sp, class _Tp, class _A0>
784 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
789 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
790 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
792 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
795 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
796 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
801 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
802 class _A1, class _A2>
803 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
805 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
808 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
809 class _A1, class _A2>
810 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
815 #endif // _LIBCPP_HAS_NO_VARIADICS
817 template <class _Tp, class = void>
818 struct __has_difference_type : false_type {};
821 struct __has_difference_type<_Tp,
822 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
824 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
825 struct __pointer_traits_difference_type
827 typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
830 template <class _Ptr>
831 struct __pointer_traits_difference_type<_Ptr, true>
833 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
836 template <class _Tp, class _Up>
840 struct __two {char __lx; char __lxx;};
841 template <class _Xp> static __two __test(...);
842 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
844 static const bool value = sizeof(__test<_Tp>(0)) == 1;
847 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
848 struct __pointer_traits_rebind
850 #ifndef _LIBCPP_CXX03_LANG
851 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
853 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
857 #ifndef _LIBCPP_HAS_NO_VARIADICS
859 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
860 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
862 #ifndef _LIBCPP_CXX03_LANG
863 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
865 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
869 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
870 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
872 typedef _Sp<_Up, _Args...> type;
875 #else // _LIBCPP_HAS_NO_VARIADICS
877 template <template <class> class _Sp, class _Tp, class _Up>
878 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
880 #ifndef _LIBCPP_CXX03_LANG
881 typedef typename _Sp<_Tp>::template rebind<_Up> type;
883 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
887 template <template <class> class _Sp, class _Tp, class _Up>
888 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
890 typedef _Sp<_Up> type;
893 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
894 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
896 #ifndef _LIBCPP_CXX03_LANG
897 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
899 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
903 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
904 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
906 typedef _Sp<_Up, _A0> type;
909 template <template <class, class, class> class _Sp, class _Tp, class _A0,
910 class _A1, class _Up>
911 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
913 #ifndef _LIBCPP_CXX03_LANG
914 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
916 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
920 template <template <class, class, class> class _Sp, class _Tp, class _A0,
921 class _A1, class _Up>
922 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
924 typedef _Sp<_Up, _A0, _A1> type;
927 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
928 class _A1, class _A2, class _Up>
929 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
931 #ifndef _LIBCPP_CXX03_LANG
932 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
934 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
938 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
939 class _A1, class _A2, class _Up>
940 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
942 typedef _Sp<_Up, _A0, _A1, _A2> type;
945 #endif // _LIBCPP_HAS_NO_VARIADICS
947 template <class _Ptr>
948 struct _LIBCPP_TEMPLATE_VIS pointer_traits
950 typedef _Ptr pointer;
951 typedef typename __pointer_traits_element_type<pointer>::type element_type;
952 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
954 #ifndef _LIBCPP_CXX03_LANG
955 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
957 template <class _Up> struct rebind
958 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
959 #endif // _LIBCPP_CXX03_LANG
964 _LIBCPP_INLINE_VISIBILITY
965 static pointer pointer_to(typename conditional<is_void<element_type>::value,
966 __nat, element_type>::type& __r)
967 {return pointer::pointer_to(__r);}
971 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
973 typedef _Tp* pointer;
974 typedef _Tp element_type;
975 typedef ptrdiff_t difference_type;
977 #ifndef _LIBCPP_CXX03_LANG
978 template <class _Up> using rebind = _Up*;
980 template <class _Up> struct rebind {typedef _Up* other;};
986 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
987 static pointer pointer_to(typename conditional<is_void<element_type>::value,
988 __nat, element_type>::type& __r) _NOEXCEPT
989 {return _VSTD::addressof(__r);}
992 template <class _From, class _To>
993 struct __rebind_pointer {
994 #ifndef _LIBCPP_CXX03_LANG
995 typedef typename pointer_traits<_From>::template rebind<_To> type;
997 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
1003 template <class _Tp, class = void>
1004 struct __has_pointer_type : false_type {};
1006 template <class _Tp>
1007 struct __has_pointer_type<_Tp,
1008 typename __void_t<typename _Tp::pointer>::type> : true_type {};
1010 namespace __pointer_type_imp
1013 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1014 struct __pointer_type
1016 typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type;
1019 template <class _Tp, class _Dp>
1020 struct __pointer_type<_Tp, _Dp, false>
1022 typedef _LIBCPP_NODEBUG_TYPE _Tp* type;
1025 } // __pointer_type_imp
1027 template <class _Tp, class _Dp>
1028 struct __pointer_type
1030 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1033 template <class _Tp, class = void>
1034 struct __has_const_pointer : false_type {};
1036 template <class _Tp>
1037 struct __has_const_pointer<_Tp,
1038 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1040 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1041 struct __const_pointer
1043 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type;
1046 template <class _Tp, class _Ptr, class _Alloc>
1047 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1049 #ifndef _LIBCPP_CXX03_LANG
1050 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1052 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1056 template <class _Tp, class = void>
1057 struct __has_void_pointer : false_type {};
1059 template <class _Tp>
1060 struct __has_void_pointer<_Tp,
1061 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1063 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1064 struct __void_pointer
1066 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type;
1069 template <class _Ptr, class _Alloc>
1070 struct __void_pointer<_Ptr, _Alloc, false>
1072 #ifndef _LIBCPP_CXX03_LANG
1073 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;
1075 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type;
1079 template <class _Tp, class = void>
1080 struct __has_const_void_pointer : false_type {};
1082 template <class _Tp>
1083 struct __has_const_void_pointer<_Tp,
1084 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1086 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1087 struct __const_void_pointer
1089 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type;
1092 template <class _Ptr, class _Alloc>
1093 struct __const_void_pointer<_Ptr, _Alloc, false>
1095 #ifndef _LIBCPP_CXX03_LANG
1096 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;
1098 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1102 template <class _Tp>
1103 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1105 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1110 #if _LIBCPP_STD_VER <= 17
1111 template <class _Pointer>
1112 inline _LIBCPP_INLINE_VISIBILITY
1113 typename pointer_traits<_Pointer>::element_type*
1114 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1116 return _VSTD::__to_raw_pointer(__p.operator->());
1119 template <class _Pointer>
1120 inline _LIBCPP_INLINE_VISIBILITY
1122 __to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1123 -> decltype(pointer_traits<_Pointer>::to_address(__p))
1125 return pointer_traits<_Pointer>::to_address(__p);
1128 template <class _Pointer, class... _None>
1129 inline _LIBCPP_INLINE_VISIBILITY
1131 __to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1133 return _VSTD::__to_raw_pointer(__p.operator->());
1136 template <class _Tp>
1137 inline _LIBCPP_INLINE_VISIBILITY constexpr
1139 to_address(_Tp* __p) _NOEXCEPT
1141 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1145 template <class _Pointer>
1146 inline _LIBCPP_INLINE_VISIBILITY
1148 to_address(const _Pointer& __p) _NOEXCEPT
1150 return _VSTD::__to_raw_pointer(__p);
1154 template <class _Tp, class = void>
1155 struct __has_size_type : false_type {};
1157 template <class _Tp>
1158 struct __has_size_type<_Tp,
1159 typename __void_t<typename _Tp::size_type>::type> : true_type {};
1161 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1164 typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;
1167 template <class _Alloc, class _DiffType>
1168 struct __size_type<_Alloc, _DiffType, true>
1170 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type;
1173 template <class _Tp, class = void>
1174 struct __has_propagate_on_container_copy_assignment : false_type {};
1176 template <class _Tp>
1177 struct __has_propagate_on_container_copy_assignment<_Tp,
1178 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1181 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1182 struct __propagate_on_container_copy_assignment
1184 typedef _LIBCPP_NODEBUG_TYPE false_type type;
1187 template <class _Alloc>
1188 struct __propagate_on_container_copy_assignment<_Alloc, true>
1190 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;
1193 template <class _Tp, class = void>
1194 struct __has_propagate_on_container_move_assignment : false_type {};
1196 template <class _Tp>
1197 struct __has_propagate_on_container_move_assignment<_Tp,
1198 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1201 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1202 struct __propagate_on_container_move_assignment
1204 typedef false_type type;
1207 template <class _Alloc>
1208 struct __propagate_on_container_move_assignment<_Alloc, true>
1210 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;
1213 template <class _Tp, class = void>
1214 struct __has_propagate_on_container_swap : false_type {};
1216 template <class _Tp>
1217 struct __has_propagate_on_container_swap<_Tp,
1218 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1221 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1222 struct __propagate_on_container_swap
1224 typedef false_type type;
1227 template <class _Alloc>
1228 struct __propagate_on_container_swap<_Alloc, true>
1230 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;
1233 template <class _Tp, class = void>
1234 struct __has_is_always_equal : false_type {};
1236 template <class _Tp>
1237 struct __has_is_always_equal<_Tp,
1238 typename __void_t<typename _Tp::is_always_equal>::type>
1241 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1242 struct __is_always_equal
1244 typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type;
1247 template <class _Alloc>
1248 struct __is_always_equal<_Alloc, true>
1250 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type;
1253 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1254 struct __has_rebind_other
1257 struct __two {char __lx; char __lxx;};
1258 template <class _Xp> static __two __test(...);
1259 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1261 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1264 template <class _Tp, class _Up>
1265 struct __has_rebind_other<_Tp, _Up, false>
1267 static const bool value = false;
1270 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1271 struct __allocator_traits_rebind
1273 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
1276 #ifndef _LIBCPP_HAS_NO_VARIADICS
1278 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1279 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1281 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1284 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1285 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1287 typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
1290 #else // _LIBCPP_HAS_NO_VARIADICS
1292 template <template <class> class _Alloc, class _Tp, class _Up>
1293 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1295 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1298 template <template <class> class _Alloc, class _Tp, class _Up>
1299 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1301 typedef _Alloc<_Up> type;
1304 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1305 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1307 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1310 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1311 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1313 typedef _Alloc<_Up, _A0> type;
1316 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1317 class _A1, class _Up>
1318 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1320 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1323 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1324 class _A1, class _Up>
1325 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1327 typedef _Alloc<_Up, _A0, _A1> type;
1330 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1331 class _A1, class _A2, class _Up>
1332 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1334 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1337 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1338 class _A1, class _A2, class _Up>
1339 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1341 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1344 #endif // _LIBCPP_HAS_NO_VARIADICS
1346 #ifndef _LIBCPP_CXX03_LANG
1348 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1351 -> decltype((void)__a.allocate(__sz, __p), true_type());
1353 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1355 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1358 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1359 struct __has_allocate_hint
1360 : integral_constant<bool,
1362 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1363 declval<_SizeType>(),
1364 declval<_ConstVoidPtr>())),
1369 #else // _LIBCPP_CXX03_LANG
1371 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1372 struct __has_allocate_hint
1377 #endif // _LIBCPP_CXX03_LANG
1379 #if !defined(_LIBCPP_CXX03_LANG)
1381 template <class _Alloc, class _Tp, class ..._Args>
1382 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1383 _VSTD::declval<_Args>()...),
1385 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1387 template <class _Alloc, class _Pointer, class ..._Args>
1389 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1391 template <class _Alloc, class _Pointer, class ..._Args>
1392 struct __has_construct
1393 : integral_constant<bool,
1395 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1396 declval<_Pointer>(),
1397 declval<_Args>()...)),
1402 template <class _Alloc, class _Pointer>
1404 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1405 -> decltype(__a.destroy(__p), true_type());
1407 template <class _Alloc, class _Pointer>
1409 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1412 template <class _Alloc, class _Pointer>
1413 struct __has_destroy
1414 : integral_constant<bool,
1416 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1417 declval<_Pointer>())),
1422 template <class _Alloc>
1424 __has_max_size_test(_Alloc&& __a)
1425 -> decltype(__a.max_size(), true_type());
1427 template <class _Alloc>
1429 __has_max_size_test(const volatile _Alloc& __a)
1432 template <class _Alloc>
1433 struct __has_max_size
1434 : integral_constant<bool,
1436 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1441 template <class _Alloc>
1443 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1444 -> decltype(__a.select_on_container_copy_construction(), true_type());
1446 template <class _Alloc>
1448 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1451 template <class _Alloc>
1452 struct __has_select_on_container_copy_construction
1453 : integral_constant<bool,
1455 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1460 #else // _LIBCPP_CXX03_LANG
1462 template <class _Alloc, class _Pointer, class _Tp, class = void>
1463 struct __has_construct : std::false_type {};
1465 template <class _Alloc, class _Pointer, class _Tp>
1466 struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
1467 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
1468 >::type> : std::true_type {};
1470 template <class _Alloc, class _Pointer, class = void>
1471 struct __has_destroy : false_type {};
1473 template <class _Alloc, class _Pointer>
1474 struct __has_destroy<_Alloc, _Pointer, typename __void_t<
1475 decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
1476 >::type> : std::true_type {};
1478 template <class _Alloc>
1479 struct __has_max_size
1484 template <class _Alloc>
1485 struct __has_select_on_container_copy_construction
1490 #endif // _LIBCPP_CXX03_LANG
1492 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1493 struct __alloc_traits_difference_type
1495 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;
1498 template <class _Alloc, class _Ptr>
1499 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1501 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type;
1504 template <class _Tp>
1505 struct __is_default_allocator : false_type {};
1507 template <class _Tp>
1508 struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
1510 template <class _Alloc>
1511 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1513 typedef _Alloc allocator_type;
1514 typedef typename allocator_type::value_type value_type;
1516 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1517 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1518 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1519 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1521 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1522 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1524 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1525 propagate_on_container_copy_assignment;
1526 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1527 propagate_on_container_move_assignment;
1528 typedef typename __propagate_on_container_swap<allocator_type>::type
1529 propagate_on_container_swap;
1530 typedef typename __is_always_equal<allocator_type>::type
1533 #ifndef _LIBCPP_CXX03_LANG
1534 template <class _Tp> using rebind_alloc =
1535 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1536 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >;
1537 #else // _LIBCPP_CXX03_LANG
1538 template <class _Tp> struct rebind_alloc
1539 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1540 template <class _Tp> struct rebind_traits
1541 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1542 #endif // _LIBCPP_CXX03_LANG
1544 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1545 static pointer allocate(allocator_type& __a, size_type __n)
1546 {return __a.allocate(__n);}
1547 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1548 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1549 {return __allocate(__a, __n, __hint,
1550 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1552 _LIBCPP_INLINE_VISIBILITY
1553 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1554 {__a.deallocate(__p, __n);}
1556 #ifndef _LIBCPP_HAS_NO_VARIADICS
1557 template <class _Tp, class... _Args>
1558 _LIBCPP_INLINE_VISIBILITY
1559 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1560 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1561 __a, __p, _VSTD::forward<_Args>(__args)...);}
1562 #else // _LIBCPP_HAS_NO_VARIADICS
1563 template <class _Tp>
1564 _LIBCPP_INLINE_VISIBILITY
1565 static void construct(allocator_type&, _Tp* __p)
1567 ::new ((void*)__p) _Tp();
1569 template <class _Tp, class _A0>
1570 _LIBCPP_INLINE_VISIBILITY
1571 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1573 __construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
1576 template <class _Tp, class _A0, class _A1>
1577 _LIBCPP_INLINE_VISIBILITY
1578 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1581 ::new ((void*)__p) _Tp(__a0, __a1);
1583 template <class _Tp, class _A0, class _A1, class _A2>
1584 _LIBCPP_INLINE_VISIBILITY
1585 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1586 const _A1& __a1, const _A2& __a2)
1588 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1590 #endif // _LIBCPP_HAS_NO_VARIADICS
1592 template <class _Tp>
1593 _LIBCPP_INLINE_VISIBILITY
1594 static void destroy(allocator_type& __a, _Tp* __p)
1595 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1597 _LIBCPP_INLINE_VISIBILITY
1598 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1599 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1601 _LIBCPP_INLINE_VISIBILITY
1602 static allocator_type
1603 select_on_container_copy_construction(const allocator_type& __a)
1604 {return __select_on_container_copy_construction(
1605 __has_select_on_container_copy_construction<const allocator_type>(),
1608 template <class _Ptr>
1609 _LIBCPP_INLINE_VISIBILITY
1612 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1614 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1615 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1618 template <class _Tp>
1619 _LIBCPP_INLINE_VISIBILITY
1623 (__is_default_allocator<allocator_type>::value
1624 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1625 is_trivially_move_constructible<_Tp>::value,
1628 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1630 ptrdiff_t _Np = __end1 - __begin1;
1633 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1638 template <class _Iter, class _Ptr>
1639 _LIBCPP_INLINE_VISIBILITY
1642 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1644 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1645 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1648 template <class _SourceTp, class _DestTp,
1649 class _RawSourceTp = typename remove_const<_SourceTp>::type,
1650 class _RawDestTp = typename remove_const<_DestTp>::type>
1651 _LIBCPP_INLINE_VISIBILITY
1655 is_trivially_move_constructible<_DestTp>::value &&
1656 is_same<_RawSourceTp, _RawDestTp>::value &&
1657 (__is_default_allocator<allocator_type>::value ||
1658 !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
1661 __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
1663 ptrdiff_t _Np = __end1 - __begin1;
1666 _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
1671 template <class _Ptr>
1672 _LIBCPP_INLINE_VISIBILITY
1675 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1677 while (__end1 != __begin1)
1679 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1684 template <class _Tp>
1685 _LIBCPP_INLINE_VISIBILITY
1689 (__is_default_allocator<allocator_type>::value
1690 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1691 is_trivially_move_constructible<_Tp>::value,
1694 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1696 ptrdiff_t _Np = __end1 - __begin1;
1699 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1704 _LIBCPP_INLINE_VISIBILITY
1705 static pointer __allocate(allocator_type& __a, size_type __n,
1706 const_void_pointer __hint, true_type)
1707 {return __a.allocate(__n, __hint);}
1708 _LIBCPP_INLINE_VISIBILITY
1709 static pointer __allocate(allocator_type& __a, size_type __n,
1710 const_void_pointer, false_type)
1711 {return __a.allocate(__n);}
1713 #ifndef _LIBCPP_HAS_NO_VARIADICS
1714 template <class _Tp, class... _Args>
1715 _LIBCPP_INLINE_VISIBILITY
1716 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1717 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1718 template <class _Tp, class... _Args>
1719 _LIBCPP_INLINE_VISIBILITY
1720 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1722 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1724 #else // _LIBCPP_HAS_NO_VARIADICS
1725 template <class _Tp, class _A0>
1726 _LIBCPP_INLINE_VISIBILITY
1727 static void __construct(true_type, allocator_type& __a, _Tp* __p,
1729 {__a.construct(__p, __a0);}
1730 template <class _Tp, class _A0>
1731 _LIBCPP_INLINE_VISIBILITY
1732 static void __construct(false_type, allocator_type&, _Tp* __p,
1735 ::new ((void*)__p) _Tp(__a0);
1737 #endif // _LIBCPP_HAS_NO_VARIADICS
1739 template <class _Tp>
1740 _LIBCPP_INLINE_VISIBILITY
1741 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1743 template <class _Tp>
1744 _LIBCPP_INLINE_VISIBILITY
1745 static void __destroy(false_type, allocator_type&, _Tp* __p)
1750 _LIBCPP_INLINE_VISIBILITY
1751 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1752 {return __a.max_size();}
1753 _LIBCPP_INLINE_VISIBILITY
1754 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
1755 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1757 _LIBCPP_INLINE_VISIBILITY
1758 static allocator_type
1759 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1760 {return __a.select_on_container_copy_construction();}
1761 _LIBCPP_INLINE_VISIBILITY
1762 static allocator_type
1763 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1767 template <class _Traits, class _Tp>
1768 struct __rebind_alloc_helper
1770 #ifndef _LIBCPP_CXX03_LANG
1771 typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type;
1773 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1779 template <class _Tp>
1780 class _LIBCPP_TEMPLATE_VIS allocator
1783 typedef size_t size_type;
1784 typedef ptrdiff_t difference_type;
1785 typedef _Tp* pointer;
1786 typedef const _Tp* const_pointer;
1787 typedef _Tp& reference;
1788 typedef const _Tp& const_reference;
1789 typedef _Tp value_type;
1791 typedef true_type propagate_on_container_move_assignment;
1792 typedef true_type is_always_equal;
1794 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1796 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1797 allocator() _NOEXCEPT {}
1799 template <class _Up>
1800 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1801 allocator(const allocator<_Up>&) _NOEXCEPT {}
1803 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1804 {return _VSTD::addressof(__x);}
1805 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1806 {return _VSTD::addressof(__x);}
1807 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1808 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1810 if (__n > max_size())
1811 __throw_length_error("allocator<T>::allocate(size_t n)"
1812 " 'n' exceeds maximum supported size");
1813 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1815 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1816 {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1817 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1818 {return size_type(~0) / sizeof(_Tp);}
1819 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1820 template <class _Up, class... _Args>
1821 _LIBCPP_INLINE_VISIBILITY
1823 construct(_Up* __p, _Args&&... __args)
1825 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1827 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1828 _LIBCPP_INLINE_VISIBILITY
1830 construct(pointer __p)
1832 ::new((void*)__p) _Tp();
1834 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1836 template <class _A0>
1837 _LIBCPP_INLINE_VISIBILITY
1839 construct(pointer __p, _A0& __a0)
1841 ::new((void*)__p) _Tp(__a0);
1843 template <class _A0>
1844 _LIBCPP_INLINE_VISIBILITY
1846 construct(pointer __p, const _A0& __a0)
1848 ::new((void*)__p) _Tp(__a0);
1850 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1851 template <class _A0, class _A1>
1852 _LIBCPP_INLINE_VISIBILITY
1854 construct(pointer __p, _A0& __a0, _A1& __a1)
1856 ::new((void*)__p) _Tp(__a0, __a1);
1858 template <class _A0, class _A1>
1859 _LIBCPP_INLINE_VISIBILITY
1861 construct(pointer __p, const _A0& __a0, _A1& __a1)
1863 ::new((void*)__p) _Tp(__a0, __a1);
1865 template <class _A0, class _A1>
1866 _LIBCPP_INLINE_VISIBILITY
1868 construct(pointer __p, _A0& __a0, const _A1& __a1)
1870 ::new((void*)__p) _Tp(__a0, __a1);
1872 template <class _A0, class _A1>
1873 _LIBCPP_INLINE_VISIBILITY
1875 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1877 ::new((void*)__p) _Tp(__a0, __a1);
1879 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1880 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1883 template <class _Tp>
1884 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1887 typedef size_t size_type;
1888 typedef ptrdiff_t difference_type;
1889 typedef const _Tp* pointer;
1890 typedef const _Tp* const_pointer;
1891 typedef const _Tp& reference;
1892 typedef const _Tp& const_reference;
1893 typedef const _Tp value_type;
1895 typedef true_type propagate_on_container_move_assignment;
1896 typedef true_type is_always_equal;
1898 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1900 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1901 allocator() _NOEXCEPT {}
1903 template <class _Up>
1904 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1905 allocator(const allocator<_Up>&) _NOEXCEPT {}
1907 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1908 {return _VSTD::addressof(__x);}
1909 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1911 if (__n > max_size())
1912 __throw_length_error("allocator<const T>::allocate(size_t n)"
1913 " 'n' exceeds maximum supported size");
1914 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1916 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1917 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1918 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1919 {return size_type(~0) / sizeof(_Tp);}
1920 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1921 template <class _Up, class... _Args>
1922 _LIBCPP_INLINE_VISIBILITY
1924 construct(_Up* __p, _Args&&... __args)
1926 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1928 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1929 _LIBCPP_INLINE_VISIBILITY
1931 construct(pointer __p)
1933 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1935 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1937 template <class _A0>
1938 _LIBCPP_INLINE_VISIBILITY
1940 construct(pointer __p, _A0& __a0)
1942 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1944 template <class _A0>
1945 _LIBCPP_INLINE_VISIBILITY
1947 construct(pointer __p, const _A0& __a0)
1949 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1951 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1952 template <class _A0, class _A1>
1953 _LIBCPP_INLINE_VISIBILITY
1955 construct(pointer __p, _A0& __a0, _A1& __a1)
1957 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1959 template <class _A0, class _A1>
1960 _LIBCPP_INLINE_VISIBILITY
1962 construct(pointer __p, const _A0& __a0, _A1& __a1)
1964 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1966 template <class _A0, class _A1>
1967 _LIBCPP_INLINE_VISIBILITY
1969 construct(pointer __p, _A0& __a0, const _A1& __a1)
1971 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1973 template <class _A0, class _A1>
1974 _LIBCPP_INLINE_VISIBILITY
1976 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1978 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1980 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1981 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1984 template <class _Tp, class _Up>
1985 inline _LIBCPP_INLINE_VISIBILITY
1986 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1988 template <class _Tp, class _Up>
1989 inline _LIBCPP_INLINE_VISIBILITY
1990 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1992 template <class _OutputIterator, class _Tp>
1993 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1994 : public iterator<output_iterator_tag,
1995 _Tp, // purposefully not C++03
1996 ptrdiff_t, // purposefully not C++03
1997 _Tp*, // purposefully not C++03
1998 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
2001 _OutputIterator __x_;
2003 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
2004 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
2005 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
2006 {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
2007 #if _LIBCPP_STD_VER >= 14
2008 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
2009 {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
2011 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
2012 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
2013 {raw_storage_iterator __t(*this); ++__x_; return __t;}
2014 #if _LIBCPP_STD_VER >= 14
2015 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
2019 template <class _Tp>
2020 _LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
2021 pair<_Tp*, ptrdiff_t>
2022 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
2024 pair<_Tp*, ptrdiff_t> __r(0, 0);
2025 const ptrdiff_t __m = (~ptrdiff_t(0) ^
2026 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2032 #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2033 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
2035 std::align_val_t __al =
2036 std::align_val_t(std::alignment_of<_Tp>::value);
2037 __r.first = static_cast<_Tp*>(::operator new(
2038 __n * sizeof(_Tp), __al, nothrow));
2040 __r.first = static_cast<_Tp*>(::operator new(
2041 __n * sizeof(_Tp), nothrow));
2044 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
2046 // Since aligned operator new is unavailable, return an empty
2047 // buffer rather than one with invalid alignment.
2051 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2064 template <class _Tp>
2065 inline _LIBCPP_INLINE_VISIBILITY
2066 void return_temporary_buffer(_Tp* __p) _NOEXCEPT
2068 _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
2071 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2072 template <class _Tp>
2073 struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
2079 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
2084 typedef _Tp element_type;
2086 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2087 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2088 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2089 : __ptr_(__p.release()) {}
2090 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2091 {reset(__p.release()); return *this;}
2092 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2093 {reset(__p.release()); return *this;}
2094 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2095 {reset(__p.__ptr_); return *this;}
2096 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2098 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2100 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2101 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2102 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2108 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2115 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2116 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2117 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2118 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2119 {return auto_ptr<_Up>(release());}
2123 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
2126 typedef void element_type;
2130 template <class _Tp, int _Idx,
2131 bool _CanBeEmptyBase =
2132 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2133 struct __compressed_pair_elem {
2134 typedef _Tp _ParamT;
2135 typedef _Tp& reference;
2136 typedef const _Tp& const_reference;
2138 #ifndef _LIBCPP_CXX03_LANG
2139 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
2141 template <class _Up, class = typename enable_if<
2142 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2144 _LIBCPP_INLINE_VISIBILITY
2146 __compressed_pair_elem(_Up&& __u)
2147 : __value_(_VSTD::forward<_Up>(__u))
2151 template <class... _Args, size_t... _Indexes>
2152 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2153 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2154 __tuple_indices<_Indexes...>)
2155 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2157 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2158 _LIBCPP_INLINE_VISIBILITY
2159 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2162 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2163 _LIBCPP_INLINE_VISIBILITY
2164 const_reference __get() const _NOEXCEPT { return __value_; }
2170 template <class _Tp, int _Idx>
2171 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2172 typedef _Tp _ParamT;
2173 typedef _Tp& reference;
2174 typedef const _Tp& const_reference;
2175 typedef _Tp __value_type;
2177 #ifndef _LIBCPP_CXX03_LANG
2178 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
2180 template <class _Up, class = typename enable_if<
2181 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2183 _LIBCPP_INLINE_VISIBILITY
2185 __compressed_pair_elem(_Up&& __u)
2186 : __value_type(_VSTD::forward<_Up>(__u))
2189 template <class... _Args, size_t... _Indexes>
2190 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2191 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2192 __tuple_indices<_Indexes...>)
2193 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2195 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2196 _LIBCPP_INLINE_VISIBILITY
2197 __compressed_pair_elem(_ParamT __p)
2198 : __value_type(std::forward<_ParamT>(__p)) {}
2201 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2202 _LIBCPP_INLINE_VISIBILITY
2203 const_reference __get() const _NOEXCEPT { return *this; }
2206 // Tag used to construct the second element of the compressed pair.
2207 struct __second_tag {};
2209 template <class _T1, class _T2>
2210 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2211 private __compressed_pair_elem<_T2, 1> {
2212 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
2213 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
2215 // NOTE: This static assert should never fire because __compressed_pair
2216 // is *almost never* used in a scenario where it's possible for T1 == T2.
2217 // (The exception is std::function where it is possible that the function
2218 // object and the allocator have the same type).
2219 static_assert((!is_same<_T1, _T2>::value),
2220 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2221 "The current implementation is NOT ABI-compatible with the previous "
2222 "implementation for this configuration");
2225 #ifndef _LIBCPP_CXX03_LANG
2226 template <bool _Dummy = true,
2227 class = typename enable_if<
2228 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2229 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2232 _LIBCPP_INLINE_VISIBILITY
2233 constexpr __compressed_pair() {}
2235 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2236 __compressed_pair>::value,
2238 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2239 __compressed_pair(_Tp&& __t)
2240 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2242 template <class _Tp>
2243 _LIBCPP_INLINE_VISIBILITY constexpr
2244 __compressed_pair(__second_tag, _Tp&& __t)
2245 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2247 template <class _U1, class _U2>
2248 _LIBCPP_INLINE_VISIBILITY constexpr
2249 __compressed_pair(_U1&& __t1, _U2&& __t2)
2250 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2252 template <class... _Args1, class... _Args2>
2253 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2254 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2255 tuple<_Args2...> __second_args)
2256 : _Base1(__pc, _VSTD::move(__first_args),
2257 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2258 _Base2(__pc, _VSTD::move(__second_args),
2259 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2262 _LIBCPP_INLINE_VISIBILITY
2263 __compressed_pair() {}
2265 _LIBCPP_INLINE_VISIBILITY explicit
2266 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2268 _LIBCPP_INLINE_VISIBILITY
2269 __compressed_pair(__second_tag, _T2 __t2)
2270 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2272 _LIBCPP_INLINE_VISIBILITY
2273 __compressed_pair(_T1 __t1, _T2 __t2)
2274 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2277 _LIBCPP_INLINE_VISIBILITY
2278 typename _Base1::reference first() _NOEXCEPT {
2279 return static_cast<_Base1&>(*this).__get();
2282 _LIBCPP_INLINE_VISIBILITY
2283 typename _Base1::const_reference first() const _NOEXCEPT {
2284 return static_cast<_Base1 const&>(*this).__get();
2287 _LIBCPP_INLINE_VISIBILITY
2288 typename _Base2::reference second() _NOEXCEPT {
2289 return static_cast<_Base2&>(*this).__get();
2292 _LIBCPP_INLINE_VISIBILITY
2293 typename _Base2::const_reference second() const _NOEXCEPT {
2294 return static_cast<_Base2 const&>(*this).__get();
2297 _LIBCPP_INLINE_VISIBILITY
2298 void swap(__compressed_pair& __x)
2299 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2300 __is_nothrow_swappable<_T2>::value)
2303 swap(first(), __x.first());
2304 swap(second(), __x.second());
2308 template <class _T1, class _T2>
2309 inline _LIBCPP_INLINE_VISIBILITY
2310 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2311 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2312 __is_nothrow_swappable<_T2>::value) {
2318 template <class _Tp>
2319 struct _LIBCPP_TEMPLATE_VIS default_delete {
2320 static_assert(!is_function<_Tp>::value,
2321 "default_delete cannot be instantiated for function types");
2322 #ifndef _LIBCPP_CXX03_LANG
2323 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
2325 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2327 template <class _Up>
2328 _LIBCPP_INLINE_VISIBILITY
2329 default_delete(const default_delete<_Up>&,
2330 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2333 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2334 static_assert(sizeof(_Tp) > 0,
2335 "default_delete can not delete incomplete type");
2336 static_assert(!is_void<_Tp>::value,
2337 "default_delete can not delete incomplete type");
2342 template <class _Tp>
2343 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2345 template <class _Up>
2346 struct _EnableIfConvertible
2347 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2350 #ifndef _LIBCPP_CXX03_LANG
2351 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
2353 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2356 template <class _Up>
2357 _LIBCPP_INLINE_VISIBILITY
2358 default_delete(const default_delete<_Up[]>&,
2359 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2361 template <class _Up>
2362 _LIBCPP_INLINE_VISIBILITY
2363 typename _EnableIfConvertible<_Up>::type
2364 operator()(_Up* __ptr) const _NOEXCEPT {
2365 static_assert(sizeof(_Tp) > 0,
2366 "default_delete can not delete incomplete type");
2367 static_assert(!is_void<_Tp>::value,
2368 "default_delete can not delete void type");
2373 template <class _Deleter>
2374 struct __unique_ptr_deleter_sfinae {
2375 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2376 typedef const _Deleter& __lval_ref_type;
2377 typedef _Deleter&& __good_rval_ref_type;
2378 typedef true_type __enable_rval_overload;
2381 template <class _Deleter>
2382 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2383 typedef const _Deleter& __lval_ref_type;
2384 typedef const _Deleter&& __bad_rval_ref_type;
2385 typedef false_type __enable_rval_overload;
2388 template <class _Deleter>
2389 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2390 typedef _Deleter& __lval_ref_type;
2391 typedef _Deleter&& __bad_rval_ref_type;
2392 typedef false_type __enable_rval_overload;
2395 template <class _Tp, class _Dp = default_delete<_Tp> >
2396 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2398 typedef _Tp element_type;
2399 typedef _Dp deleter_type;
2400 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer;
2402 static_assert(!is_rvalue_reference<deleter_type>::value,
2403 "the specified deleter type cannot be an rvalue reference");
2406 __compressed_pair<pointer, deleter_type> __ptr_;
2408 struct __nat { int __for_bool_; };
2410 typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2412 template <bool _Dummy>
2413 using _LValRefType _LIBCPP_NODEBUG_TYPE =
2414 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2416 template <bool _Dummy>
2417 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
2418 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2420 template <bool _Dummy>
2421 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
2422 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2424 template <bool _Dummy, class _Deleter = typename __dependent_type<
2425 __identity<deleter_type>, _Dummy>::type>
2426 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
2427 typename enable_if<is_default_constructible<_Deleter>::value &&
2428 !is_pointer<_Deleter>::value>::type;
2430 template <class _ArgType>
2431 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
2432 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2434 template <class _UPtr, class _Up>
2435 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2436 is_convertible<typename _UPtr::pointer, pointer>::value &&
2437 !is_array<_Up>::value
2440 template <class _UDel>
2441 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2442 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2443 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2446 template <class _UDel>
2447 using _EnableIfDeleterAssignable = typename enable_if<
2448 is_assignable<_Dp&, _UDel&&>::value
2452 template <bool _Dummy = true,
2453 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2454 _LIBCPP_INLINE_VISIBILITY
2455 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
2457 template <bool _Dummy = true,
2458 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2459 _LIBCPP_INLINE_VISIBILITY
2460 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
2462 template <bool _Dummy = true,
2463 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2464 _LIBCPP_INLINE_VISIBILITY
2465 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {}
2467 template <bool _Dummy = true,
2468 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
2469 _LIBCPP_INLINE_VISIBILITY
2470 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
2471 : __ptr_(__p, __d) {}
2473 template <bool _Dummy = true,
2474 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
2475 _LIBCPP_INLINE_VISIBILITY
2476 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2477 : __ptr_(__p, _VSTD::move(__d)) {
2478 static_assert(!is_reference<deleter_type>::value,
2479 "rvalue deleter bound to reference");
2482 template <bool _Dummy = true,
2483 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
2484 _LIBCPP_INLINE_VISIBILITY
2485 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2487 _LIBCPP_INLINE_VISIBILITY
2488 unique_ptr(unique_ptr&& __u) _NOEXCEPT
2489 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2492 template <class _Up, class _Ep,
2493 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2494 class = _EnableIfDeleterConvertible<_Ep>
2496 _LIBCPP_INLINE_VISIBILITY
2497 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2498 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2500 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2501 template <class _Up>
2502 _LIBCPP_INLINE_VISIBILITY
2503 unique_ptr(auto_ptr<_Up>&& __p,
2504 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2505 is_same<_Dp, default_delete<_Tp> >::value,
2506 __nat>::type = __nat()) _NOEXCEPT
2507 : __ptr_(__p.release()) {}
2510 _LIBCPP_INLINE_VISIBILITY
2511 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2512 reset(__u.release());
2513 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2517 template <class _Up, class _Ep,
2518 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2519 class = _EnableIfDeleterAssignable<_Ep>
2521 _LIBCPP_INLINE_VISIBILITY
2522 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2523 reset(__u.release());
2524 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2528 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2529 template <class _Up>
2530 _LIBCPP_INLINE_VISIBILITY
2531 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2532 is_same<_Dp, default_delete<_Tp> >::value,
2534 operator=(auto_ptr<_Up> __p) {
2535 reset(__p.release());
2540 #ifdef _LIBCPP_CXX03_LANG
2541 unique_ptr(unique_ptr const&) = delete;
2542 unique_ptr& operator=(unique_ptr const&) = delete;
2546 _LIBCPP_INLINE_VISIBILITY
2547 ~unique_ptr() { reset(); }
2549 _LIBCPP_INLINE_VISIBILITY
2550 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2555 _LIBCPP_INLINE_VISIBILITY
2556 typename add_lvalue_reference<_Tp>::type
2558 return *__ptr_.first();
2560 _LIBCPP_INLINE_VISIBILITY
2561 pointer operator->() const _NOEXCEPT {
2562 return __ptr_.first();
2564 _LIBCPP_INLINE_VISIBILITY
2565 pointer get() const _NOEXCEPT {
2566 return __ptr_.first();
2568 _LIBCPP_INLINE_VISIBILITY
2569 deleter_type& get_deleter() _NOEXCEPT {
2570 return __ptr_.second();
2572 _LIBCPP_INLINE_VISIBILITY
2573 const deleter_type& get_deleter() const _NOEXCEPT {
2574 return __ptr_.second();
2576 _LIBCPP_INLINE_VISIBILITY
2577 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2578 return __ptr_.first() != nullptr;
2581 _LIBCPP_INLINE_VISIBILITY
2582 pointer release() _NOEXCEPT {
2583 pointer __t = __ptr_.first();
2584 __ptr_.first() = pointer();
2588 _LIBCPP_INLINE_VISIBILITY
2589 void reset(pointer __p = pointer()) _NOEXCEPT {
2590 pointer __tmp = __ptr_.first();
2591 __ptr_.first() = __p;
2593 __ptr_.second()(__tmp);
2596 _LIBCPP_INLINE_VISIBILITY
2597 void swap(unique_ptr& __u) _NOEXCEPT {
2598 __ptr_.swap(__u.__ptr_);
2603 template <class _Tp, class _Dp>
2604 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2606 typedef _Tp element_type;
2607 typedef _Dp deleter_type;
2608 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2611 __compressed_pair<pointer, deleter_type> __ptr_;
2613 template <class _From>
2614 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2616 template <class _FromElem>
2617 struct _CheckArrayPointerConversion<_FromElem*>
2618 : integral_constant<bool,
2619 is_same<_FromElem*, pointer>::value ||
2620 (is_same<pointer, element_type*>::value &&
2621 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2625 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2627 template <bool _Dummy>
2628 using _LValRefType _LIBCPP_NODEBUG_TYPE =
2629 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2631 template <bool _Dummy>
2632 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
2633 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2635 template <bool _Dummy>
2636 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
2637 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2639 template <bool _Dummy, class _Deleter = typename __dependent_type<
2640 __identity<deleter_type>, _Dummy>::type>
2641 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
2642 typename enable_if<is_default_constructible<_Deleter>::value &&
2643 !is_pointer<_Deleter>::value>::type;
2645 template <class _ArgType>
2646 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
2647 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2649 template <class _Pp>
2650 using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2651 _CheckArrayPointerConversion<_Pp>::value
2654 template <class _UPtr, class _Up,
2655 class _ElemT = typename _UPtr::element_type>
2656 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2657 is_array<_Up>::value &&
2658 is_same<pointer, element_type*>::value &&
2659 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2660 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2663 template <class _UDel>
2664 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
2665 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2666 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2669 template <class _UDel>
2670 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
2671 is_assignable<_Dp&, _UDel&&>::value
2675 template <bool _Dummy = true,
2676 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2677 _LIBCPP_INLINE_VISIBILITY
2678 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
2680 template <bool _Dummy = true,
2681 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
2682 _LIBCPP_INLINE_VISIBILITY
2683 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
2685 template <class _Pp, bool _Dummy = true,
2686 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2687 class = _EnableIfPointerConvertible<_Pp> >
2688 _LIBCPP_INLINE_VISIBILITY
2689 explicit unique_ptr(_Pp __p) _NOEXCEPT
2692 template <class _Pp, bool _Dummy = true,
2693 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
2694 class = _EnableIfPointerConvertible<_Pp> >
2695 _LIBCPP_INLINE_VISIBILITY
2696 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
2697 : __ptr_(__p, __d) {}
2699 template <bool _Dummy = true,
2700 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
2701 _LIBCPP_INLINE_VISIBILITY
2702 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
2703 : __ptr_(nullptr, __d) {}
2705 template <class _Pp, bool _Dummy = true,
2706 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
2707 class = _EnableIfPointerConvertible<_Pp> >
2708 _LIBCPP_INLINE_VISIBILITY
2709 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2710 : __ptr_(__p, _VSTD::move(__d)) {
2711 static_assert(!is_reference<deleter_type>::value,
2712 "rvalue deleter bound to reference");
2715 template <bool _Dummy = true,
2716 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
2717 _LIBCPP_INLINE_VISIBILITY
2718 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
2719 : __ptr_(nullptr, _VSTD::move(__d)) {
2720 static_assert(!is_reference<deleter_type>::value,
2721 "rvalue deleter bound to reference");
2724 template <class _Pp, bool _Dummy = true,
2725 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
2726 class = _EnableIfPointerConvertible<_Pp> >
2727 _LIBCPP_INLINE_VISIBILITY
2728 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2730 _LIBCPP_INLINE_VISIBILITY
2731 unique_ptr(unique_ptr&& __u) _NOEXCEPT
2732 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2735 _LIBCPP_INLINE_VISIBILITY
2736 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2737 reset(__u.release());
2738 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2742 template <class _Up, class _Ep,
2743 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2744 class = _EnableIfDeleterConvertible<_Ep>
2746 _LIBCPP_INLINE_VISIBILITY
2747 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2748 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2751 template <class _Up, class _Ep,
2752 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2753 class = _EnableIfDeleterAssignable<_Ep>
2755 _LIBCPP_INLINE_VISIBILITY
2757 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2758 reset(__u.release());
2759 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2763 #ifdef _LIBCPP_CXX03_LANG
2764 unique_ptr(unique_ptr const&) = delete;
2765 unique_ptr& operator=(unique_ptr const&) = delete;
2769 _LIBCPP_INLINE_VISIBILITY
2770 ~unique_ptr() { reset(); }
2772 _LIBCPP_INLINE_VISIBILITY
2773 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2778 _LIBCPP_INLINE_VISIBILITY
2779 typename add_lvalue_reference<_Tp>::type
2780 operator[](size_t __i) const {
2781 return __ptr_.first()[__i];
2783 _LIBCPP_INLINE_VISIBILITY
2784 pointer get() const _NOEXCEPT {
2785 return __ptr_.first();
2788 _LIBCPP_INLINE_VISIBILITY
2789 deleter_type& get_deleter() _NOEXCEPT {
2790 return __ptr_.second();
2793 _LIBCPP_INLINE_VISIBILITY
2794 const deleter_type& get_deleter() const _NOEXCEPT {
2795 return __ptr_.second();
2797 _LIBCPP_INLINE_VISIBILITY
2798 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2799 return __ptr_.first() != nullptr;
2802 _LIBCPP_INLINE_VISIBILITY
2803 pointer release() _NOEXCEPT {
2804 pointer __t = __ptr_.first();
2805 __ptr_.first() = pointer();
2809 template <class _Pp>
2810 _LIBCPP_INLINE_VISIBILITY
2812 _CheckArrayPointerConversion<_Pp>::value
2814 reset(_Pp __p) _NOEXCEPT {
2815 pointer __tmp = __ptr_.first();
2816 __ptr_.first() = __p;
2818 __ptr_.second()(__tmp);
2821 _LIBCPP_INLINE_VISIBILITY
2822 void reset(nullptr_t = nullptr) _NOEXCEPT {
2823 pointer __tmp = __ptr_.first();
2824 __ptr_.first() = nullptr;
2826 __ptr_.second()(__tmp);
2829 _LIBCPP_INLINE_VISIBILITY
2830 void swap(unique_ptr& __u) _NOEXCEPT {
2831 __ptr_.swap(__u.__ptr_);
2836 template <class _Tp, class _Dp>
2837 inline _LIBCPP_INLINE_VISIBILITY
2839 __is_swappable<_Dp>::value,
2842 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2844 template <class _T1, class _D1, class _T2, class _D2>
2845 inline _LIBCPP_INLINE_VISIBILITY
2847 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2849 template <class _T1, class _D1, class _T2, class _D2>
2850 inline _LIBCPP_INLINE_VISIBILITY
2852 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2854 template <class _T1, class _D1, class _T2, class _D2>
2855 inline _LIBCPP_INLINE_VISIBILITY
2857 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2859 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2860 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2861 typedef typename common_type<_P1, _P2>::type _Vp;
2862 return less<_Vp>()(__x.get(), __y.get());
2865 template <class _T1, class _D1, class _T2, class _D2>
2866 inline _LIBCPP_INLINE_VISIBILITY
2868 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2870 template <class _T1, class _D1, class _T2, class _D2>
2871 inline _LIBCPP_INLINE_VISIBILITY
2873 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2875 template <class _T1, class _D1, class _T2, class _D2>
2876 inline _LIBCPP_INLINE_VISIBILITY
2878 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2880 template <class _T1, class _D1>
2881 inline _LIBCPP_INLINE_VISIBILITY
2883 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2888 template <class _T1, class _D1>
2889 inline _LIBCPP_INLINE_VISIBILITY
2891 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2896 template <class _T1, class _D1>
2897 inline _LIBCPP_INLINE_VISIBILITY
2899 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2901 return static_cast<bool>(__x);
2904 template <class _T1, class _D1>
2905 inline _LIBCPP_INLINE_VISIBILITY
2907 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2909 return static_cast<bool>(__x);
2912 template <class _T1, class _D1>
2913 inline _LIBCPP_INLINE_VISIBILITY
2915 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2917 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2918 return less<_P1>()(__x.get(), nullptr);
2921 template <class _T1, class _D1>
2922 inline _LIBCPP_INLINE_VISIBILITY
2924 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2926 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2927 return less<_P1>()(nullptr, __x.get());
2930 template <class _T1, class _D1>
2931 inline _LIBCPP_INLINE_VISIBILITY
2933 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2935 return nullptr < __x;
2938 template <class _T1, class _D1>
2939 inline _LIBCPP_INLINE_VISIBILITY
2941 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2943 return __x < nullptr;
2946 template <class _T1, class _D1>
2947 inline _LIBCPP_INLINE_VISIBILITY
2949 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2951 return !(nullptr < __x);
2954 template <class _T1, class _D1>
2955 inline _LIBCPP_INLINE_VISIBILITY
2957 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2959 return !(__x < nullptr);
2962 template <class _T1, class _D1>
2963 inline _LIBCPP_INLINE_VISIBILITY
2965 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2967 return !(__x < nullptr);
2970 template <class _T1, class _D1>
2971 inline _LIBCPP_INLINE_VISIBILITY
2973 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2975 return !(nullptr < __x);
2978 #if _LIBCPP_STD_VER > 11
2983 typedef unique_ptr<_Tp> __unique_single;
2987 struct __unique_if<_Tp[]>
2989 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
2992 template<class _Tp, size_t _Np>
2993 struct __unique_if<_Tp[_Np]>
2995 typedef void __unique_array_known_bound;
2998 template<class _Tp, class... _Args>
2999 inline _LIBCPP_INLINE_VISIBILITY
3000 typename __unique_if<_Tp>::__unique_single
3001 make_unique(_Args&&... __args)
3003 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3007 inline _LIBCPP_INLINE_VISIBILITY
3008 typename __unique_if<_Tp>::__unique_array_unknown_bound
3009 make_unique(size_t __n)
3011 typedef typename remove_extent<_Tp>::type _Up;
3012 return unique_ptr<_Tp>(new _Up[__n]());
3015 template<class _Tp, class... _Args>
3016 typename __unique_if<_Tp>::__unique_array_known_bound
3017 make_unique(_Args&&...) = delete;
3019 #endif // _LIBCPP_STD_VER > 11
3021 template <class _Tp, class _Dp>
3022 #ifdef _LIBCPP_CXX03_LANG
3023 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3025 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3026 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
3029 typedef unique_ptr<_Tp, _Dp> argument_type;
3030 typedef size_t result_type;
3031 _LIBCPP_INLINE_VISIBILITY
3032 result_type operator()(const argument_type& __ptr) const
3034 typedef typename argument_type::pointer pointer;
3035 return hash<pointer>()(__ptr.get());
3044 template <class _Tp>
3045 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3046 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3048 template <class _Tp>
3049 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3052 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3054 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3057 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3059 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3062 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3065 template <class _Tp>
3066 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3067 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3069 template <class _Tp>
3070 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3071 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3073 template <class _Tp>
3074 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3075 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3078 template <class _Alloc>
3079 class __allocator_destructor
3081 typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
3083 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
3084 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
3089 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3091 : __alloc_(__a), __s_(__s) {}
3092 _LIBCPP_INLINE_VISIBILITY
3093 void operator()(pointer __p) _NOEXCEPT
3094 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3097 template <class _InputIterator, class _ForwardIterator>
3099 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3101 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3102 #ifndef _LIBCPP_NO_EXCEPTIONS
3103 _ForwardIterator __s = __r;
3107 for (; __f != __l; ++__f, (void) ++__r)
3108 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3109 #ifndef _LIBCPP_NO_EXCEPTIONS
3113 for (; __s != __r; ++__s)
3121 template <class _InputIterator, class _Size, class _ForwardIterator>
3123 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3125 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3126 #ifndef _LIBCPP_NO_EXCEPTIONS
3127 _ForwardIterator __s = __r;
3131 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3132 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3133 #ifndef _LIBCPP_NO_EXCEPTIONS
3137 for (; __s != __r; ++__s)
3145 template <class _ForwardIterator, class _Tp>
3147 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3149 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3150 #ifndef _LIBCPP_NO_EXCEPTIONS
3151 _ForwardIterator __s = __f;
3155 for (; __f != __l; ++__f)
3156 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3157 #ifndef _LIBCPP_NO_EXCEPTIONS
3161 for (; __s != __f; ++__s)
3168 template <class _ForwardIterator, class _Size, class _Tp>
3170 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3172 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3173 #ifndef _LIBCPP_NO_EXCEPTIONS
3174 _ForwardIterator __s = __f;
3178 for (; __n > 0; ++__f, (void) --__n)
3179 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3180 #ifndef _LIBCPP_NO_EXCEPTIONS
3184 for (; __s != __f; ++__s)
3192 #if _LIBCPP_STD_VER > 14
3194 template <class _Tp>
3195 inline _LIBCPP_INLINE_VISIBILITY
3196 void destroy_at(_Tp* __loc) {
3197 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3201 template <class _ForwardIterator>
3202 inline _LIBCPP_INLINE_VISIBILITY
3203 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3204 for (; __first != __last; ++__first)
3205 _VSTD::destroy_at(_VSTD::addressof(*__first));
3208 template <class _ForwardIterator, class _Size>
3209 inline _LIBCPP_INLINE_VISIBILITY
3210 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3211 for (; __n > 0; (void)++__first, --__n)
3212 _VSTD::destroy_at(_VSTD::addressof(*__first));
3216 template <class _ForwardIterator>
3217 inline _LIBCPP_INLINE_VISIBILITY
3218 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3219 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3220 auto __idx = __first;
3221 #ifndef _LIBCPP_NO_EXCEPTIONS
3224 for (; __idx != __last; ++__idx)
3225 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3226 #ifndef _LIBCPP_NO_EXCEPTIONS
3228 _VSTD::destroy(__first, __idx);
3234 template <class _ForwardIterator, class _Size>
3235 inline _LIBCPP_INLINE_VISIBILITY
3236 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3237 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3238 auto __idx = __first;
3239 #ifndef _LIBCPP_NO_EXCEPTIONS
3242 for (; __n > 0; (void)++__idx, --__n)
3243 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3245 #ifndef _LIBCPP_NO_EXCEPTIONS
3247 _VSTD::destroy(__first, __idx);
3254 template <class _ForwardIterator>
3255 inline _LIBCPP_INLINE_VISIBILITY
3256 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3257 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3258 auto __idx = __first;
3259 #ifndef _LIBCPP_NO_EXCEPTIONS
3262 for (; __idx != __last; ++__idx)
3263 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3264 #ifndef _LIBCPP_NO_EXCEPTIONS
3266 _VSTD::destroy(__first, __idx);
3272 template <class _ForwardIterator, class _Size>
3273 inline _LIBCPP_INLINE_VISIBILITY
3274 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3275 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3276 auto __idx = __first;
3277 #ifndef _LIBCPP_NO_EXCEPTIONS
3280 for (; __n > 0; (void)++__idx, --__n)
3281 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3283 #ifndef _LIBCPP_NO_EXCEPTIONS
3285 _VSTD::destroy(__first, __idx);
3292 template <class _InputIt, class _ForwardIt>
3293 inline _LIBCPP_INLINE_VISIBILITY
3294 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3295 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3296 auto __idx = __first_res;
3297 #ifndef _LIBCPP_NO_EXCEPTIONS
3300 for (; __first != __last; (void)++__idx, ++__first)
3301 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3303 #ifndef _LIBCPP_NO_EXCEPTIONS
3305 _VSTD::destroy(__first_res, __idx);
3311 template <class _InputIt, class _Size, class _ForwardIt>
3312 inline _LIBCPP_INLINE_VISIBILITY
3313 pair<_InputIt, _ForwardIt>
3314 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3315 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3316 auto __idx = __first_res;
3317 #ifndef _LIBCPP_NO_EXCEPTIONS
3320 for (; __n > 0; ++__idx, (void)++__first, --__n)
3321 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3322 return {__first, __idx};
3323 #ifndef _LIBCPP_NO_EXCEPTIONS
3325 _VSTD::destroy(__first_res, __idx);
3332 #endif // _LIBCPP_STD_VER > 14
3334 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3335 // should be sufficient for thread safety.
3336 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3337 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3338 && defined(__ATOMIC_RELAXED) \
3339 && defined(__ATOMIC_ACQ_REL)
3340 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3341 #elif defined(_LIBCPP_COMPILER_GCC)
3342 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3345 template <class _Tp>
3346 inline _LIBCPP_INLINE_VISIBILITY _Tp
3347 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3349 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3350 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3356 template <class _Tp>
3357 inline _LIBCPP_INLINE_VISIBILITY _Tp
3358 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3360 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3361 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3367 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3368 : public std::exception
3371 virtual ~bad_weak_ptr() _NOEXCEPT;
3372 virtual const char* what() const _NOEXCEPT;
3375 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
3376 void __throw_bad_weak_ptr()
3378 #ifndef _LIBCPP_NO_EXCEPTIONS
3379 throw bad_weak_ptr();
3385 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3387 class _LIBCPP_TYPE_VIS __shared_count
3389 __shared_count(const __shared_count&);
3390 __shared_count& operator=(const __shared_count&);
3393 long __shared_owners_;
3394 virtual ~__shared_count();
3396 virtual void __on_zero_shared() _NOEXCEPT = 0;
3399 _LIBCPP_INLINE_VISIBILITY
3400 explicit __shared_count(long __refs = 0) _NOEXCEPT
3401 : __shared_owners_(__refs) {}
3403 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3404 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3405 void __add_shared() _NOEXCEPT;
3406 bool __release_shared() _NOEXCEPT;
3408 _LIBCPP_INLINE_VISIBILITY
3409 void __add_shared() _NOEXCEPT {
3410 __libcpp_atomic_refcount_increment(__shared_owners_);
3412 _LIBCPP_INLINE_VISIBILITY
3413 bool __release_shared() _NOEXCEPT {
3414 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3421 _LIBCPP_INLINE_VISIBILITY
3422 long use_count() const _NOEXCEPT {
3423 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3427 class _LIBCPP_TYPE_VIS __shared_weak_count
3428 : private __shared_count
3430 long __shared_weak_owners_;
3433 _LIBCPP_INLINE_VISIBILITY
3434 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3435 : __shared_count(__refs),
3436 __shared_weak_owners_(__refs) {}
3438 virtual ~__shared_weak_count();
3441 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3442 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3443 void __add_shared() _NOEXCEPT;
3444 void __add_weak() _NOEXCEPT;
3445 void __release_shared() _NOEXCEPT;
3447 _LIBCPP_INLINE_VISIBILITY
3448 void __add_shared() _NOEXCEPT {
3449 __shared_count::__add_shared();
3451 _LIBCPP_INLINE_VISIBILITY
3452 void __add_weak() _NOEXCEPT {
3453 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3455 _LIBCPP_INLINE_VISIBILITY
3456 void __release_shared() _NOEXCEPT {
3457 if (__shared_count::__release_shared())
3461 void __release_weak() _NOEXCEPT;
3462 _LIBCPP_INLINE_VISIBILITY
3463 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3464 __shared_weak_count* lock() _NOEXCEPT;
3466 // Define the function out only if we build static libc++ without RTTI.
3467 // Otherwise we may break clients who need to compile their projects with
3468 // -fno-rtti and yet link against a libc++.dylib compiled
3469 // without -fno-rtti.
3470 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3471 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3474 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3477 template <class _Tp, class _Dp, class _Alloc>
3478 class __shared_ptr_pointer
3479 : public __shared_weak_count
3481 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3483 _LIBCPP_INLINE_VISIBILITY
3484 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3485 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3487 #ifndef _LIBCPP_NO_RTTI
3488 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3492 virtual void __on_zero_shared() _NOEXCEPT;
3493 virtual void __on_zero_shared_weak() _NOEXCEPT;
3496 #ifndef _LIBCPP_NO_RTTI
3498 template <class _Tp, class _Dp, class _Alloc>
3500 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3502 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3505 #endif // _LIBCPP_NO_RTTI
3507 template <class _Tp, class _Dp, class _Alloc>
3509 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3511 __data_.first().second()(__data_.first().first());
3512 __data_.first().second().~_Dp();
3515 template <class _Tp, class _Dp, class _Alloc>
3517 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3519 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3520 typedef allocator_traits<_Al> _ATraits;
3521 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3523 _Al __a(__data_.second());
3524 __data_.second().~_Alloc();
3525 __a.deallocate(_PTraits::pointer_to(*this), 1);
3528 template <class _Tp, class _Alloc>
3529 class __shared_ptr_emplace
3530 : public __shared_weak_count
3532 __compressed_pair<_Alloc, _Tp> __data_;
3534 #ifndef _LIBCPP_HAS_NO_VARIADICS
3536 _LIBCPP_INLINE_VISIBILITY
3537 __shared_ptr_emplace(_Alloc __a)
3538 : __data_(_VSTD::move(__a)) {}
3540 template <class ..._Args>
3541 _LIBCPP_INLINE_VISIBILITY
3542 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3543 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3544 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3546 #else // _LIBCPP_HAS_NO_VARIADICS
3548 _LIBCPP_INLINE_VISIBILITY
3549 __shared_ptr_emplace(_Alloc __a)
3552 template <class _A0>
3553 _LIBCPP_INLINE_VISIBILITY
3554 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3555 : __data_(__a, _Tp(__a0)) {}
3557 template <class _A0, class _A1>
3558 _LIBCPP_INLINE_VISIBILITY
3559 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3560 : __data_(__a, _Tp(__a0, __a1)) {}
3562 template <class _A0, class _A1, class _A2>
3563 _LIBCPP_INLINE_VISIBILITY
3564 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3565 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3567 #endif // _LIBCPP_HAS_NO_VARIADICS
3570 virtual void __on_zero_shared() _NOEXCEPT;
3571 virtual void __on_zero_shared_weak() _NOEXCEPT;
3573 _LIBCPP_INLINE_VISIBILITY
3574 _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
3577 template <class _Tp, class _Alloc>
3579 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3581 __data_.second().~_Tp();
3584 template <class _Tp, class _Alloc>
3586 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3588 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3589 typedef allocator_traits<_Al> _ATraits;
3590 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3591 _Al __a(__data_.first());
3592 __data_.first().~_Alloc();
3593 __a.deallocate(_PTraits::pointer_to(*this), 1);
3596 struct __shared_ptr_dummy_rebind_allocator_type;
3598 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3601 template <class _Other>
3604 typedef allocator<_Other> other;
3608 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3611 class _LIBCPP_TEMPLATE_VIS shared_ptr
3614 typedef _Tp element_type;
3616 #if _LIBCPP_STD_VER > 14
3617 typedef weak_ptr<_Tp> weak_type;
3620 element_type* __ptr_;
3621 __shared_weak_count* __cntrl_;
3623 struct __nat {int __for_bool_;};
3625 _LIBCPP_INLINE_VISIBILITY
3626 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3627 _LIBCPP_INLINE_VISIBILITY
3628 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3630 explicit shared_ptr(_Yp* __p,
3631 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3632 template<class _Yp, class _Dp>
3633 shared_ptr(_Yp* __p, _Dp __d,
3634 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3635 template<class _Yp, class _Dp, class _Alloc>
3636 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3637 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3638 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3639 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3640 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3641 _LIBCPP_INLINE_VISIBILITY
3642 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3644 _LIBCPP_INLINE_VISIBILITY
3645 shared_ptr(const shared_ptr<_Yp>& __r,
3646 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3648 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3649 _LIBCPP_INLINE_VISIBILITY
3650 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3651 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3652 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3654 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3655 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3656 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3657 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3658 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3660 shared_ptr(auto_ptr<_Yp>&& __r,
3661 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3664 shared_ptr(auto_ptr<_Yp> __r,
3665 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3668 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3669 template <class _Yp, class _Dp>
3670 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3673 !is_lvalue_reference<_Dp>::value &&
3674 !is_array<_Yp>::value &&
3675 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3678 template <class _Yp, class _Dp>
3679 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3682 is_lvalue_reference<_Dp>::value &&
3683 !is_array<_Yp>::value &&
3684 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3687 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3688 template <class _Yp, class _Dp>
3689 shared_ptr(unique_ptr<_Yp, _Dp>,
3692 !is_lvalue_reference<_Dp>::value &&
3693 !is_array<_Yp>::value &&
3694 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3697 template <class _Yp, class _Dp>
3698 shared_ptr(unique_ptr<_Yp, _Dp>,
3701 is_lvalue_reference<_Dp>::value &&
3702 !is_array<_Yp>::value &&
3703 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3706 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3710 _LIBCPP_INLINE_VISIBILITY
3711 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3715 is_convertible<_Yp*, element_type*>::value,
3718 _LIBCPP_INLINE_VISIBILITY
3719 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3720 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3721 _LIBCPP_INLINE_VISIBILITY
3722 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3726 is_convertible<_Yp*, element_type*>::value,
3729 _LIBCPP_INLINE_VISIBILITY
3730 operator=(shared_ptr<_Yp>&& __r);
3731 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3733 _LIBCPP_INLINE_VISIBILITY
3736 !is_array<_Yp>::value &&
3737 is_convertible<_Yp*, element_type*>::value,
3740 operator=(auto_ptr<_Yp>&& __r);
3742 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3743 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3745 _LIBCPP_INLINE_VISIBILITY
3748 !is_array<_Yp>::value &&
3749 is_convertible<_Yp*, element_type*>::value,
3752 operator=(auto_ptr<_Yp> __r);
3755 template <class _Yp, class _Dp>
3758 !is_array<_Yp>::value &&
3759 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3762 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3763 _LIBCPP_INLINE_VISIBILITY
3764 operator=(unique_ptr<_Yp, _Dp>&& __r);
3765 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3766 _LIBCPP_INLINE_VISIBILITY
3767 operator=(unique_ptr<_Yp, _Dp> __r);
3770 _LIBCPP_INLINE_VISIBILITY
3771 void swap(shared_ptr& __r) _NOEXCEPT;
3772 _LIBCPP_INLINE_VISIBILITY
3773 void reset() _NOEXCEPT;
3777 is_convertible<_Yp*, element_type*>::value,
3780 _LIBCPP_INLINE_VISIBILITY
3782 template<class _Yp, class _Dp>
3785 is_convertible<_Yp*, element_type*>::value,
3788 _LIBCPP_INLINE_VISIBILITY
3789 reset(_Yp* __p, _Dp __d);
3790 template<class _Yp, class _Dp, class _Alloc>
3793 is_convertible<_Yp*, element_type*>::value,
3796 _LIBCPP_INLINE_VISIBILITY
3797 reset(_Yp* __p, _Dp __d, _Alloc __a);
3799 _LIBCPP_INLINE_VISIBILITY
3800 element_type* get() const _NOEXCEPT {return __ptr_;}
3801 _LIBCPP_INLINE_VISIBILITY
3802 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3804 _LIBCPP_INLINE_VISIBILITY
3805 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3806 _LIBCPP_INLINE_VISIBILITY
3807 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3808 _LIBCPP_INLINE_VISIBILITY
3809 bool unique() const _NOEXCEPT {return use_count() == 1;}
3810 _LIBCPP_INLINE_VISIBILITY
3811 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3812 template <class _Up>
3813 _LIBCPP_INLINE_VISIBILITY
3814 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3815 {return __cntrl_ < __p.__cntrl_;}
3816 template <class _Up>
3817 _LIBCPP_INLINE_VISIBILITY
3818 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3819 {return __cntrl_ < __p.__cntrl_;}
3820 _LIBCPP_INLINE_VISIBILITY
3822 __owner_equivalent(const shared_ptr& __p) const
3823 {return __cntrl_ == __p.__cntrl_;}
3825 #ifndef _LIBCPP_NO_RTTI
3826 template <class _Dp>
3827 _LIBCPP_INLINE_VISIBILITY
3828 _Dp* __get_deleter() const _NOEXCEPT
3829 {return static_cast<_Dp*>(__cntrl_
3830 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3832 #endif // _LIBCPP_NO_RTTI
3834 #ifndef _LIBCPP_HAS_NO_VARIADICS
3836 template<class ..._Args>
3839 make_shared(_Args&& ...__args);
3841 template<class _Alloc, class ..._Args>
3844 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3846 #else // _LIBCPP_HAS_NO_VARIADICS
3848 static shared_ptr<_Tp> make_shared();
3851 static shared_ptr<_Tp> make_shared(_A0&);
3853 template<class _A0, class _A1>
3854 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3856 template<class _A0, class _A1, class _A2>
3857 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3859 template<class _Alloc>
3860 static shared_ptr<_Tp>
3861 allocate_shared(const _Alloc& __a);
3863 template<class _Alloc, class _A0>
3864 static shared_ptr<_Tp>
3865 allocate_shared(const _Alloc& __a, _A0& __a0);
3867 template<class _Alloc, class _A0, class _A1>
3868 static shared_ptr<_Tp>
3869 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3871 template<class _Alloc, class _A0, class _A1, class _A2>
3872 static shared_ptr<_Tp>
3873 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3875 #endif // _LIBCPP_HAS_NO_VARIADICS
3878 template <class _Yp, bool = is_function<_Yp>::value>
3879 struct __shared_ptr_default_allocator
3881 typedef allocator<_Yp> type;
3884 template <class _Yp>
3885 struct __shared_ptr_default_allocator<_Yp, true>
3887 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3890 template <class _Yp, class _OrigPtr>
3891 _LIBCPP_INLINE_VISIBILITY
3892 typename enable_if<is_convertible<_OrigPtr*,
3893 const enable_shared_from_this<_Yp>*
3896 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3897 _OrigPtr* __ptr) _NOEXCEPT
3899 typedef typename remove_cv<_Yp>::type _RawYp;
3900 if (__e && __e->__weak_this_.expired())
3902 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3903 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
3907 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
3909 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3910 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
3917 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3926 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
3934 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3935 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3938 unique_ptr<_Yp> __hold(__p);
3939 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3940 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
3941 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
3943 __enable_weak_this(__p, __p);
3947 template<class _Yp, class _Dp>
3948 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
3949 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3952 #ifndef _LIBCPP_NO_EXCEPTIONS
3955 #endif // _LIBCPP_NO_EXCEPTIONS
3956 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3957 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
3958 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
3959 __enable_weak_this(__p, __p);
3960 #ifndef _LIBCPP_NO_EXCEPTIONS
3967 #endif // _LIBCPP_NO_EXCEPTIONS
3972 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
3975 #ifndef _LIBCPP_NO_EXCEPTIONS
3978 #endif // _LIBCPP_NO_EXCEPTIONS
3979 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
3980 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
3981 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
3982 #ifndef _LIBCPP_NO_EXCEPTIONS
3989 #endif // _LIBCPP_NO_EXCEPTIONS
3993 template<class _Yp, class _Dp, class _Alloc>
3994 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3995 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3998 #ifndef _LIBCPP_NO_EXCEPTIONS
4001 #endif // _LIBCPP_NO_EXCEPTIONS
4002 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4003 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4004 typedef __allocator_destructor<_A2> _D2;
4006 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4007 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4008 _CntrlBlk(__p, __d, __a);
4009 __cntrl_ = _VSTD::addressof(*__hold2.release());
4010 __enable_weak_this(__p, __p);
4011 #ifndef _LIBCPP_NO_EXCEPTIONS
4018 #endif // _LIBCPP_NO_EXCEPTIONS
4022 template<class _Dp, class _Alloc>
4023 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4026 #ifndef _LIBCPP_NO_EXCEPTIONS
4029 #endif // _LIBCPP_NO_EXCEPTIONS
4030 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4031 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4032 typedef __allocator_destructor<_A2> _D2;
4034 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4035 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4036 _CntrlBlk(__p, __d, __a);
4037 __cntrl_ = _VSTD::addressof(*__hold2.release());
4038 #ifndef _LIBCPP_NO_EXCEPTIONS
4045 #endif // _LIBCPP_NO_EXCEPTIONS
4051 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4053 __cntrl_(__r.__cntrl_)
4056 __cntrl_->__add_shared();
4061 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4062 : __ptr_(__r.__ptr_),
4063 __cntrl_(__r.__cntrl_)
4066 __cntrl_->__add_shared();
4072 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4073 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4075 : __ptr_(__r.__ptr_),
4076 __cntrl_(__r.__cntrl_)
4079 __cntrl_->__add_shared();
4082 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4086 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4087 : __ptr_(__r.__ptr_),
4088 __cntrl_(__r.__cntrl_)
4097 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4098 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4100 : __ptr_(__r.__ptr_),
4101 __cntrl_(__r.__cntrl_)
4107 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4109 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4112 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4113 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4115 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4117 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4120 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4121 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4122 __enable_weak_this(__r.get(), __r.get());
4128 template <class _Yp, class _Dp>
4129 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4130 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4132 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4136 !is_lvalue_reference<_Dp>::value &&
4137 !is_array<_Yp>::value &&
4138 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4143 #if _LIBCPP_STD_VER > 11
4144 if (__ptr_ == nullptr)
4149 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4150 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4151 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4152 __enable_weak_this(__r.get(), __r.get());
4158 template <class _Yp, class _Dp>
4159 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4160 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4162 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4166 is_lvalue_reference<_Dp>::value &&
4167 !is_array<_Yp>::value &&
4168 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4173 #if _LIBCPP_STD_VER > 11
4174 if (__ptr_ == nullptr)
4179 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4180 typedef __shared_ptr_pointer<_Yp*,
4181 reference_wrapper<typename remove_reference<_Dp>::type>,
4182 _AllocT > _CntrlBlk;
4183 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4184 __enable_weak_this(__r.get(), __r.get());
4189 #ifndef _LIBCPP_HAS_NO_VARIADICS
4192 template<class ..._Args>
4194 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4196 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
4197 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4198 typedef allocator<_CntrlBlk> _A2;
4199 typedef __allocator_destructor<_A2> _D2;
4201 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4202 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4203 shared_ptr<_Tp> __r;
4204 __r.__ptr_ = __hold2.get()->get();
4205 __r.__cntrl_ = __hold2.release();
4206 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4211 template<class _Alloc, class ..._Args>
4213 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4215 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4216 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4217 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4218 typedef __allocator_destructor<_A2> _D2;
4220 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4221 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4222 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4223 shared_ptr<_Tp> __r;
4224 __r.__ptr_ = __hold2.get()->get();
4225 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4226 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4230 #else // _LIBCPP_HAS_NO_VARIADICS
4234 shared_ptr<_Tp>::make_shared()
4236 static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
4237 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4238 typedef allocator<_CntrlBlk> _Alloc2;
4239 typedef __allocator_destructor<_Alloc2> _D2;
4241 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4242 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4243 shared_ptr<_Tp> __r;
4244 __r.__ptr_ = __hold2.get()->get();
4245 __r.__cntrl_ = __hold2.release();
4246 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4253 shared_ptr<_Tp>::make_shared(_A0& __a0)
4255 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
4256 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4257 typedef allocator<_CntrlBlk> _Alloc2;
4258 typedef __allocator_destructor<_Alloc2> _D2;
4260 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4261 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4262 shared_ptr<_Tp> __r;
4263 __r.__ptr_ = __hold2.get()->get();
4264 __r.__cntrl_ = __hold2.release();
4265 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4270 template<class _A0, class _A1>
4272 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4274 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
4275 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4276 typedef allocator<_CntrlBlk> _Alloc2;
4277 typedef __allocator_destructor<_Alloc2> _D2;
4279 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4280 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4281 shared_ptr<_Tp> __r;
4282 __r.__ptr_ = __hold2.get()->get();
4283 __r.__cntrl_ = __hold2.release();
4284 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4289 template<class _A0, class _A1, class _A2>
4291 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4293 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
4294 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4295 typedef allocator<_CntrlBlk> _Alloc2;
4296 typedef __allocator_destructor<_Alloc2> _D2;
4298 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4299 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4300 shared_ptr<_Tp> __r;
4301 __r.__ptr_ = __hold2.get()->get();
4302 __r.__cntrl_ = __hold2.release();
4303 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4308 template<class _Alloc>
4310 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4312 static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
4313 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4314 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4315 typedef __allocator_destructor<_Alloc2> _D2;
4316 _Alloc2 __alloc2(__a);
4317 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4318 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4320 shared_ptr<_Tp> __r;
4321 __r.__ptr_ = __hold2.get()->get();
4322 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4323 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4328 template<class _Alloc, class _A0>
4330 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4332 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
4333 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4334 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4335 typedef __allocator_destructor<_Alloc2> _D2;
4336 _Alloc2 __alloc2(__a);
4337 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4338 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4339 _CntrlBlk(__a, __a0);
4340 shared_ptr<_Tp> __r;
4341 __r.__ptr_ = __hold2.get()->get();
4342 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4343 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4348 template<class _Alloc, class _A0, class _A1>
4350 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4352 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
4353 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4354 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4355 typedef __allocator_destructor<_Alloc2> _D2;
4356 _Alloc2 __alloc2(__a);
4357 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4358 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4359 _CntrlBlk(__a, __a0, __a1);
4360 shared_ptr<_Tp> __r;
4361 __r.__ptr_ = __hold2.get()->get();
4362 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4363 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4368 template<class _Alloc, class _A0, class _A1, class _A2>
4370 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4372 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
4373 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4374 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4375 typedef __allocator_destructor<_Alloc2> _D2;
4376 _Alloc2 __alloc2(__a);
4377 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4378 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4379 _CntrlBlk(__a, __a0, __a1, __a2);
4380 shared_ptr<_Tp> __r;
4381 __r.__ptr_ = __hold2.get()->get();
4382 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4383 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4387 #endif // _LIBCPP_HAS_NO_VARIADICS
4390 shared_ptr<_Tp>::~shared_ptr()
4393 __cntrl_->__release_shared();
4399 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4401 shared_ptr(__r).swap(*this);
4410 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4413 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4415 shared_ptr(__r).swap(*this);
4419 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4424 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4426 shared_ptr(_VSTD::move(__r)).swap(*this);
4435 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4438 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4440 shared_ptr(_VSTD::move(__r)).swap(*this);
4444 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4450 !is_array<_Yp>::value &&
4451 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4454 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4456 shared_ptr(_VSTD::move(__r)).swap(*this);
4462 template <class _Yp, class _Dp>
4466 !is_array<_Yp>::value &&
4467 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4468 typename shared_ptr<_Tp>::element_type*>::value,
4471 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4473 shared_ptr(_VSTD::move(__r)).swap(*this);
4477 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4479 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4482 inline _LIBCPP_INLINE_VISIBILITY
4485 !is_array<_Yp>::value &&
4486 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4489 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4491 shared_ptr(__r).swap(*this);
4497 template <class _Yp, class _Dp>
4498 inline _LIBCPP_INLINE_VISIBILITY
4501 !is_array<_Yp>::value &&
4502 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4503 typename shared_ptr<_Tp>::element_type*>::value,
4506 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4508 shared_ptr(_VSTD::move(__r)).swap(*this);
4512 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4517 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4519 _VSTD::swap(__ptr_, __r.__ptr_);
4520 _VSTD::swap(__cntrl_, __r.__cntrl_);
4526 shared_ptr<_Tp>::reset() _NOEXCEPT
4528 shared_ptr().swap(*this);
4536 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4539 shared_ptr<_Tp>::reset(_Yp* __p)
4541 shared_ptr(__p).swap(*this);
4545 template<class _Yp, class _Dp>
4549 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4552 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4554 shared_ptr(__p, __d).swap(*this);
4558 template<class _Yp, class _Dp, class _Alloc>
4562 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4565 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4567 shared_ptr(__p, __d, __a).swap(*this);
4570 #ifndef _LIBCPP_HAS_NO_VARIADICS
4572 template<class _Tp, class ..._Args>
4573 inline _LIBCPP_INLINE_VISIBILITY
4576 !is_array<_Tp>::value,
4579 make_shared(_Args&& ...__args)
4581 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4584 template<class _Tp, class _Alloc, class ..._Args>
4585 inline _LIBCPP_INLINE_VISIBILITY
4588 !is_array<_Tp>::value,
4591 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4593 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4596 #else // _LIBCPP_HAS_NO_VARIADICS
4599 inline _LIBCPP_INLINE_VISIBILITY
4603 return shared_ptr<_Tp>::make_shared();
4606 template<class _Tp, class _A0>
4607 inline _LIBCPP_INLINE_VISIBILITY
4609 make_shared(_A0& __a0)
4611 return shared_ptr<_Tp>::make_shared(__a0);
4614 template<class _Tp, class _A0, class _A1>
4615 inline _LIBCPP_INLINE_VISIBILITY
4617 make_shared(_A0& __a0, _A1& __a1)
4619 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4622 template<class _Tp, class _A0, class _A1, class _A2>
4623 inline _LIBCPP_INLINE_VISIBILITY
4625 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4627 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4630 template<class _Tp, class _Alloc>
4631 inline _LIBCPP_INLINE_VISIBILITY
4633 allocate_shared(const _Alloc& __a)
4635 return shared_ptr<_Tp>::allocate_shared(__a);
4638 template<class _Tp, class _Alloc, class _A0>
4639 inline _LIBCPP_INLINE_VISIBILITY
4641 allocate_shared(const _Alloc& __a, _A0& __a0)
4643 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4646 template<class _Tp, class _Alloc, class _A0, class _A1>
4647 inline _LIBCPP_INLINE_VISIBILITY
4649 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4651 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4654 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4655 inline _LIBCPP_INLINE_VISIBILITY
4657 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4659 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4662 #endif // _LIBCPP_HAS_NO_VARIADICS
4664 template<class _Tp, class _Up>
4665 inline _LIBCPP_INLINE_VISIBILITY
4667 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4669 return __x.get() == __y.get();
4672 template<class _Tp, class _Up>
4673 inline _LIBCPP_INLINE_VISIBILITY
4675 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4677 return !(__x == __y);
4680 template<class _Tp, class _Up>
4681 inline _LIBCPP_INLINE_VISIBILITY
4683 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4685 #if _LIBCPP_STD_VER <= 11
4686 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4687 return less<_Vp>()(__x.get(), __y.get());
4689 return less<>()(__x.get(), __y.get());
4694 template<class _Tp, class _Up>
4695 inline _LIBCPP_INLINE_VISIBILITY
4697 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4702 template<class _Tp, class _Up>
4703 inline _LIBCPP_INLINE_VISIBILITY
4705 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4707 return !(__y < __x);
4710 template<class _Tp, class _Up>
4711 inline _LIBCPP_INLINE_VISIBILITY
4713 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4715 return !(__x < __y);
4719 inline _LIBCPP_INLINE_VISIBILITY
4721 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4727 inline _LIBCPP_INLINE_VISIBILITY
4729 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4735 inline _LIBCPP_INLINE_VISIBILITY
4737 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4739 return static_cast<bool>(__x);
4743 inline _LIBCPP_INLINE_VISIBILITY
4745 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4747 return static_cast<bool>(__x);
4751 inline _LIBCPP_INLINE_VISIBILITY
4753 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4755 return less<_Tp*>()(__x.get(), nullptr);
4759 inline _LIBCPP_INLINE_VISIBILITY
4761 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4763 return less<_Tp*>()(nullptr, __x.get());
4767 inline _LIBCPP_INLINE_VISIBILITY
4769 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4771 return nullptr < __x;
4775 inline _LIBCPP_INLINE_VISIBILITY
4777 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4779 return __x < nullptr;
4783 inline _LIBCPP_INLINE_VISIBILITY
4785 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4787 return !(nullptr < __x);
4791 inline _LIBCPP_INLINE_VISIBILITY
4793 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4795 return !(__x < nullptr);
4799 inline _LIBCPP_INLINE_VISIBILITY
4801 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4803 return !(__x < nullptr);
4807 inline _LIBCPP_INLINE_VISIBILITY
4809 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4811 return !(nullptr < __x);
4815 inline _LIBCPP_INLINE_VISIBILITY
4817 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4822 template<class _Tp, class _Up>
4823 inline _LIBCPP_INLINE_VISIBILITY
4826 !is_array<_Tp>::value && !is_array<_Up>::value,
4829 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4831 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4834 template<class _Tp, class _Up>
4835 inline _LIBCPP_INLINE_VISIBILITY
4838 !is_array<_Tp>::value && !is_array<_Up>::value,
4841 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4843 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4844 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4847 template<class _Tp, class _Up>
4850 is_array<_Tp>::value == is_array<_Up>::value,
4853 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4855 typedef typename remove_extent<_Tp>::type _RTp;
4856 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4859 #ifndef _LIBCPP_NO_RTTI
4861 template<class _Dp, class _Tp>
4862 inline _LIBCPP_INLINE_VISIBILITY
4864 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4866 return __p.template __get_deleter<_Dp>();
4869 #endif // _LIBCPP_NO_RTTI
4872 class _LIBCPP_TEMPLATE_VIS weak_ptr
4875 typedef _Tp element_type;
4877 element_type* __ptr_;
4878 __shared_weak_count* __cntrl_;
4881 _LIBCPP_INLINE_VISIBILITY
4882 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4883 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4884 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4886 _LIBCPP_INLINE_VISIBILITY
4887 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4888 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
4889 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4892 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4893 _LIBCPP_INLINE_VISIBILITY
4894 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4895 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
4896 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4898 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4901 _LIBCPP_INLINE_VISIBILITY
4902 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4906 is_convertible<_Yp*, element_type*>::value,
4909 _LIBCPP_INLINE_VISIBILITY
4910 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4912 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4914 _LIBCPP_INLINE_VISIBILITY
4915 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4919 is_convertible<_Yp*, element_type*>::value,
4922 _LIBCPP_INLINE_VISIBILITY
4923 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4925 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4930 is_convertible<_Yp*, element_type*>::value,
4933 _LIBCPP_INLINE_VISIBILITY
4934 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4936 _LIBCPP_INLINE_VISIBILITY
4937 void swap(weak_ptr& __r) _NOEXCEPT;
4938 _LIBCPP_INLINE_VISIBILITY
4939 void reset() _NOEXCEPT;
4941 _LIBCPP_INLINE_VISIBILITY
4942 long use_count() const _NOEXCEPT
4943 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4944 _LIBCPP_INLINE_VISIBILITY
4945 bool expired() const _NOEXCEPT
4946 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4947 shared_ptr<_Tp> lock() const _NOEXCEPT;
4949 _LIBCPP_INLINE_VISIBILITY
4950 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
4951 {return __cntrl_ < __r.__cntrl_;}
4953 _LIBCPP_INLINE_VISIBILITY
4954 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
4955 {return __cntrl_ < __r.__cntrl_;}
4957 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4958 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4964 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4972 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
4973 : __ptr_(__r.__ptr_),
4974 __cntrl_(__r.__cntrl_)
4977 __cntrl_->__add_weak();
4983 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
4984 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4986 : __ptr_(__r.__ptr_),
4987 __cntrl_(__r.__cntrl_)
4990 __cntrl_->__add_weak();
4996 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
4997 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4999 : __ptr_(__r.__ptr_),
5000 __cntrl_(__r.__cntrl_)
5003 __cntrl_->__add_weak();
5006 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5010 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5011 : __ptr_(__r.__ptr_),
5012 __cntrl_(__r.__cntrl_)
5021 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5022 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5024 : __ptr_(__r.__ptr_),
5025 __cntrl_(__r.__cntrl_)
5031 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5034 weak_ptr<_Tp>::~weak_ptr()
5037 __cntrl_->__release_weak();
5043 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5045 weak_ptr(__r).swap(*this);
5054 is_convertible<_Yp*, _Tp*>::value,
5057 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5059 weak_ptr(__r).swap(*this);
5063 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5068 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5070 weak_ptr(_VSTD::move(__r)).swap(*this);
5079 is_convertible<_Yp*, _Tp*>::value,
5082 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5084 weak_ptr(_VSTD::move(__r)).swap(*this);
5088 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5095 is_convertible<_Yp*, _Tp*>::value,
5098 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5100 weak_ptr(__r).swap(*this);
5107 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5109 _VSTD::swap(__ptr_, __r.__ptr_);
5110 _VSTD::swap(__cntrl_, __r.__cntrl_);
5114 inline _LIBCPP_INLINE_VISIBILITY
5116 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5124 weak_ptr<_Tp>::reset() _NOEXCEPT
5126 weak_ptr().swap(*this);
5131 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5132 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5133 : __ptr_(__r.__ptr_),
5134 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5137 __throw_bad_weak_ptr();
5142 weak_ptr<_Tp>::lock() const _NOEXCEPT
5144 shared_ptr<_Tp> __r;
5145 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5147 __r.__ptr_ = __ptr_;
5151 #if _LIBCPP_STD_VER > 14
5152 template <class _Tp = void> struct owner_less;
5154 template <class _Tp> struct owner_less;
5157 template <class _Tp>
5158 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5159 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5161 typedef bool result_type;
5162 _LIBCPP_INLINE_VISIBILITY
5163 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5164 {return __x.owner_before(__y);}
5165 _LIBCPP_INLINE_VISIBILITY
5166 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5167 {return __x.owner_before(__y);}
5168 _LIBCPP_INLINE_VISIBILITY
5169 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5170 {return __x.owner_before(__y);}
5173 template <class _Tp>
5174 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5175 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5177 typedef bool result_type;
5178 _LIBCPP_INLINE_VISIBILITY
5179 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5180 {return __x.owner_before(__y);}
5181 _LIBCPP_INLINE_VISIBILITY
5182 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5183 {return __x.owner_before(__y);}
5184 _LIBCPP_INLINE_VISIBILITY
5185 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5186 {return __x.owner_before(__y);}
5189 #if _LIBCPP_STD_VER > 14
5191 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5193 template <class _Tp, class _Up>
5194 _LIBCPP_INLINE_VISIBILITY
5195 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5196 {return __x.owner_before(__y);}
5197 template <class _Tp, class _Up>
5198 _LIBCPP_INLINE_VISIBILITY
5199 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5200 {return __x.owner_before(__y);}
5201 template <class _Tp, class _Up>
5202 _LIBCPP_INLINE_VISIBILITY
5203 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5204 {return __x.owner_before(__y);}
5205 template <class _Tp, class _Up>
5206 _LIBCPP_INLINE_VISIBILITY
5207 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5208 {return __x.owner_before(__y);}
5209 typedef void is_transparent;
5214 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5216 mutable weak_ptr<_Tp> __weak_this_;
5218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5219 enable_shared_from_this() _NOEXCEPT {}
5220 _LIBCPP_INLINE_VISIBILITY
5221 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5222 _LIBCPP_INLINE_VISIBILITY
5223 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5225 _LIBCPP_INLINE_VISIBILITY
5226 ~enable_shared_from_this() {}
5228 _LIBCPP_INLINE_VISIBILITY
5229 shared_ptr<_Tp> shared_from_this()
5230 {return shared_ptr<_Tp>(__weak_this_);}
5231 _LIBCPP_INLINE_VISIBILITY
5232 shared_ptr<_Tp const> shared_from_this() const
5233 {return shared_ptr<const _Tp>(__weak_this_);}
5235 #if _LIBCPP_STD_VER > 14
5236 _LIBCPP_INLINE_VISIBILITY
5237 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5238 { return __weak_this_; }
5240 _LIBCPP_INLINE_VISIBILITY
5241 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5242 { return __weak_this_; }
5243 #endif // _LIBCPP_STD_VER > 14
5245 template <class _Up> friend class shared_ptr;
5248 template <class _Tp>
5249 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5251 typedef shared_ptr<_Tp> argument_type;
5252 typedef size_t result_type;
5254 _LIBCPP_INLINE_VISIBILITY
5255 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5257 return hash<_Tp*>()(__ptr.get());
5261 template<class _CharT, class _Traits, class _Yp>
5262 inline _LIBCPP_INLINE_VISIBILITY
5263 basic_ostream<_CharT, _Traits>&
5264 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5267 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5269 class _LIBCPP_TYPE_VIS __sp_mut
5273 void lock() _NOEXCEPT;
5274 void unlock() _NOEXCEPT;
5277 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5278 __sp_mut(const __sp_mut&);
5279 __sp_mut& operator=(const __sp_mut&);
5281 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5284 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5285 __sp_mut& __get_sp_mut(const void*);
5287 template <class _Tp>
5288 inline _LIBCPP_INLINE_VISIBILITY
5290 atomic_is_lock_free(const shared_ptr<_Tp>*)
5295 template <class _Tp>
5296 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5298 atomic_load(const shared_ptr<_Tp>* __p)
5300 __sp_mut& __m = __get_sp_mut(__p);
5302 shared_ptr<_Tp> __q = *__p;
5307 template <class _Tp>
5308 inline _LIBCPP_INLINE_VISIBILITY
5309 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5311 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5313 return atomic_load(__p);
5316 template <class _Tp>
5317 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5319 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5321 __sp_mut& __m = __get_sp_mut(__p);
5327 template <class _Tp>
5328 inline _LIBCPP_INLINE_VISIBILITY
5329 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5331 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5333 atomic_store(__p, __r);
5336 template <class _Tp>
5337 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5339 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5341 __sp_mut& __m = __get_sp_mut(__p);
5348 template <class _Tp>
5349 inline _LIBCPP_INLINE_VISIBILITY
5350 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5352 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5354 return atomic_exchange(__p, __r);
5357 template <class _Tp>
5358 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5360 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5362 shared_ptr<_Tp> __temp;
5363 __sp_mut& __m = __get_sp_mut(__p);
5365 if (__p->__owner_equivalent(*__v))
5367 _VSTD::swap(__temp, *__p);
5372 _VSTD::swap(__temp, *__v);
5378 template <class _Tp>
5379 inline _LIBCPP_INLINE_VISIBILITY
5380 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5382 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5384 return atomic_compare_exchange_strong(__p, __v, __w);
5387 template <class _Tp>
5388 inline _LIBCPP_INLINE_VISIBILITY
5389 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5391 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5392 shared_ptr<_Tp> __w, memory_order, memory_order)
5394 return atomic_compare_exchange_strong(__p, __v, __w);
5397 template <class _Tp>
5398 inline _LIBCPP_INLINE_VISIBILITY
5399 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5401 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5402 shared_ptr<_Tp> __w, memory_order, memory_order)
5404 return atomic_compare_exchange_weak(__p, __v, __w);
5407 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5410 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5411 # ifndef _LIBCPP_CXX03_LANG
5412 enum class pointer_safety : unsigned char {
5419 struct _LIBCPP_TYPE_VIS pointer_safety
5430 _LIBCPP_INLINE_VISIBILITY
5431 pointer_safety() : __v_() {}
5433 _LIBCPP_INLINE_VISIBILITY
5434 pointer_safety(__lx __v) : __v_(__v) {}
5435 _LIBCPP_INLINE_VISIBILITY
5436 operator int() const {return __v_;}
5440 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5441 defined(_LIBCPP_BUILDING_LIBRARY)
5442 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5444 // This function is only offered in C++03 under ABI v1.
5445 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5446 inline _LIBCPP_INLINE_VISIBILITY
5447 pointer_safety get_pointer_safety() _NOEXCEPT {
5448 return pointer_safety::relaxed;
5454 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5455 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5456 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5457 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5459 template <class _Tp>
5460 inline _LIBCPP_INLINE_VISIBILITY
5462 undeclare_reachable(_Tp* __p)
5464 return static_cast<_Tp*>(__undeclare_reachable(__p));
5467 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5469 // --- Helper for container swap --
5470 template <typename _Alloc>
5471 inline _LIBCPP_INLINE_VISIBILITY
5472 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5473 #if _LIBCPP_STD_VER >= 14
5476 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5479 __swap_allocator(__a1, __a2,
5480 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5483 template <typename _Alloc>
5484 _LIBCPP_INLINE_VISIBILITY
5485 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5486 #if _LIBCPP_STD_VER >= 14
5489 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5496 template <typename _Alloc>
5497 inline _LIBCPP_INLINE_VISIBILITY
5498 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5500 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5501 struct __noexcept_move_assign_container : public integral_constant<bool,
5502 _Traits::propagate_on_container_move_assignment::value
5503 #if _LIBCPP_STD_VER > 14
5504 || _Traits::is_always_equal::value
5506 && is_nothrow_move_assignable<_Alloc>::value
5511 #ifndef _LIBCPP_HAS_NO_VARIADICS
5512 template <class _Tp, class _Alloc>
5513 struct __temp_value {
5514 typedef allocator_traits<_Alloc> _Traits;
5516 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
5519 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5520 _Tp & get() { return *__addr(); }
5522 template<class... _Args>
5524 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
5525 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
5526 _VSTD::forward<_Args>(__args)...);
5529 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5533 template<typename _Alloc, typename = void, typename = void>
5534 struct __is_allocator : false_type {};
5536 template<typename _Alloc>
5537 struct __is_allocator<_Alloc,
5538 typename __void_t<typename _Alloc::value_type>::type,
5539 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
5543 // __builtin_new_allocator -- A non-templated helper for allocating and
5544 // deallocating memory using __builtin_operator_new and
5545 // __builtin_operator_delete. It should be used in preference to
5546 // `std::allocator<T>` to avoid additional instantiations.
5547 struct __builtin_new_allocator {
5548 struct __builtin_new_deleter {
5549 typedef void* pointer_type;
5551 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
5552 : __size_(__size), __align_(__align) {}
5554 void operator()(void* p) const _NOEXCEPT {
5555 std::__libcpp_deallocate(p, __size_, __align_);
5563 typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
5565 static __holder_t __allocate_bytes(size_t __s, size_t __align) {
5566 return __holder_t(std::__libcpp_allocate(__s, __align),
5567 __builtin_new_deleter(__s, __align));
5570 static void __deallocate_bytes(void* __p, size_t __s,
5571 size_t __align) _NOEXCEPT {
5572 std::__libcpp_deallocate(__p, __s, __align);
5575 template <class _Tp>
5576 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5577 static __holder_t __allocate_type(size_t __n) {
5578 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5581 template <class _Tp>
5582 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5583 static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
5584 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5589 _LIBCPP_END_NAMESPACE_STD
5593 #endif // _LIBCPP_MEMORY