diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-05-09 01:52:26 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-05-09 01:52:26 -0700 |
| commit | bcb534c295d5cc6fd63caa570cc08e6b148a507c (patch) | |
| tree | 0b17cb1e632d894f50f25e550d5113f232b0e877 /lib/libcxx/include/__memory | |
| parent | d9b00ee4ba48717ff6b306a6f9419e7b604ac04b (diff) | |
| parent | 74f52954b9cb40d59d80b839b45bb859146731a7 (diff) | |
| download | zig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.tar.gz zig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.zip | |
Merge branch 'llvm18'
Upgrades the LLVM, Clang, and LLD dependencies to LLVM 18.x
Related to #16270
Diffstat (limited to 'lib/libcxx/include/__memory')
28 files changed, 2497 insertions, 3102 deletions
diff --git a/lib/libcxx/include/__memory/addressof.h b/lib/libcxx/include/__memory/addressof.h index d4c69b83a8..fa590212c4 100644 --- a/lib/libcxx/include/__memory/addressof.h +++ b/lib/libcxx/include/__memory/addressof.h @@ -19,12 +19,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -inline _LIBCPP_CONSTEXPR_SINCE_CXX17 -_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY -_Tp* -addressof(_Tp& __x) _NOEXCEPT -{ - return __builtin_addressof(__x); +inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* addressof(_Tp& __x) _NOEXCEPT { + return __builtin_addressof(__x); } #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) @@ -33,42 +29,31 @@ addressof(_Tp& __x) _NOEXCEPT // _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler // itself is providing these definitions. Otherwise, we provide them. template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__strong _Tp* -addressof(__strong _Tp& __x) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT { return &__x; } -#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +# ifdef _LIBCPP_HAS_OBJC_ARC_WEAK template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__weak _Tp* -addressof(__weak _Tp& __x) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT { return &__x; } -#endif +# endif template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__autoreleasing _Tp* -addressof(__autoreleasing _Tp& __x) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI __autoreleasing _Tp* addressof(__autoreleasing _Tp& __x) _NOEXCEPT { return &__x; } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__unsafe_unretained _Tp* -addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI __unsafe_unretained _Tp* addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT { return &__x; } #endif #if !defined(_LIBCPP_CXX03_LANG) -template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete; +template <class _Tp> +_Tp* addressof(const _Tp&&) noexcept = delete; #endif _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/aligned_alloc.h b/lib/libcxx/include/__memory/aligned_alloc.h index 786963c72d..cb424328bc 100644 --- a/lib/libcxx/include/__memory/aligned_alloc.h +++ b/lib/libcxx/include/__memory/aligned_alloc.h @@ -27,36 +27,34 @@ _LIBCPP_BEGIN_NAMESPACE_STD // chances are that you want to use `__libcpp_allocate` instead. // // Returns the allocated memory, or `nullptr` on failure. -inline _LIBCPP_HIDE_FROM_ABI -void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { +inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { # if defined(_LIBCPP_MSVCRT_LIKE) - return ::_aligned_malloc(__size, __alignment); + return ::_aligned_malloc(__size, __alignment); # elif _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC) - // aligned_alloc() requires that __size is a multiple of __alignment, - // but for C++ [new.delete.general], only states "if the value of an - // alignment argument passed to any of these functions is not a valid - // alignment value, the behavior is undefined". - // To handle calls such as ::operator new(1, std::align_val_t(128)), we - // round __size up to the next multiple of __alignment. - size_t __rounded_size = (__size + __alignment - 1) & ~(__alignment - 1); - // Rounding up could have wrapped around to zero, so we have to add another - // max() ternary to the actual call site to avoid succeeded in that case. - return ::aligned_alloc(__alignment, __size > __rounded_size ? __size : __rounded_size); + // aligned_alloc() requires that __size is a multiple of __alignment, + // but for C++ [new.delete.general], only states "if the value of an + // alignment argument passed to any of these functions is not a valid + // alignment value, the behavior is undefined". + // To handle calls such as ::operator new(1, std::align_val_t(128)), we + // round __size up to the next multiple of __alignment. + size_t __rounded_size = (__size + __alignment - 1) & ~(__alignment - 1); + // Rounding up could have wrapped around to zero, so we have to add another + // max() ternary to the actual call site to avoid succeeded in that case. + return ::aligned_alloc(__alignment, __size > __rounded_size ? __size : __rounded_size); # else - void* __result = nullptr; - (void)::posix_memalign(&__result, __alignment, __size); - // If posix_memalign fails, __result is unmodified so we still return `nullptr`. - return __result; + void* __result = nullptr; + (void)::posix_memalign(&__result, __alignment, __size); + // If posix_memalign fails, __result is unmodified so we still return `nullptr`. + return __result; # endif } -inline _LIBCPP_HIDE_FROM_ABI -void __libcpp_aligned_free(void* __ptr) { -#if defined(_LIBCPP_MSVCRT_LIKE) +inline _LIBCPP_HIDE_FROM_ABI void __libcpp_aligned_free(void* __ptr) { +# if defined(_LIBCPP_MSVCRT_LIKE) ::_aligned_free(__ptr); -#else +# else ::free(__ptr); -#endif +# endif } #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION diff --git a/lib/libcxx/include/__memory/allocate_at_least.h b/lib/libcxx/include/__memory/allocate_at_least.h index 8d8ad071e2..05cbdee828 100644 --- a/lib/libcxx/include/__memory/allocate_at_least.h +++ b/lib/libcxx/include/__memory/allocate_at_least.h @@ -28,8 +28,8 @@ struct allocation_result { _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result); template <class _Alloc> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr -allocation_result<typename allocator_traits<_Alloc>::pointer> allocate_at_least(_Alloc& __alloc, size_t __n) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<typename allocator_traits<_Alloc>::pointer> +allocate_at_least(_Alloc& __alloc, size_t __n) { if constexpr (requires { __alloc.allocate_at_least(__n); }) { return __alloc.allocate_at_least(__n); } else { @@ -38,8 +38,7 @@ allocation_result<typename allocator_traits<_Alloc>::pointer> allocate_at_least( } template <class _Alloc> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr -auto __allocate_at_least(_Alloc& __alloc, size_t __n) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto __allocate_at_least(_Alloc& __alloc, size_t __n) { return std::allocate_at_least(__alloc, __n); } #else @@ -51,7 +50,8 @@ struct __allocation_result { template <class _Alloc> _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR -__allocation_result<typename allocator_traits<_Alloc>::pointer> __allocate_at_least(_Alloc& __alloc, size_t __n) { + __allocation_result<typename allocator_traits<_Alloc>::pointer> + __allocate_at_least(_Alloc& __alloc, size_t __n) { return {__alloc.allocate(__n), __n}; } diff --git a/lib/libcxx/include/__memory/allocation_guard.h b/lib/libcxx/include/__memory/allocation_guard.h index f63b17430e..cb870af7be 100644 --- a/lib/libcxx/include/__memory/allocation_guard.h +++ b/lib/libcxx/include/__memory/allocation_guard.h @@ -44,69 +44,61 @@ _LIBCPP_BEGIN_NAMESPACE_STD // // This is similar to a unique_ptr, except it's easier to use with a // custom allocator. -template<class _Alloc> +template <class _Alloc> struct __allocation_guard { - using _Pointer = typename allocator_traits<_Alloc>::pointer; - using _Size = typename allocator_traits<_Alloc>::size_type; - - template<class _AllocT> // we perform the allocator conversion inside the constructor - _LIBCPP_HIDE_FROM_ABI - explicit __allocation_guard(_AllocT __alloc, _Size __n) - : __alloc_(_VSTD::move(__alloc)) - , __n_(__n) - , __ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important - { } - - _LIBCPP_HIDE_FROM_ABI - ~__allocation_guard() _NOEXCEPT { - __destroy(); - } - - _LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete; - _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT - : __alloc_(std::move(__other.__alloc_)) - , __n_(__other.__n_) - , __ptr_(__other.__ptr_) { + using _Pointer = typename allocator_traits<_Alloc>::pointer; + using _Size = typename allocator_traits<_Alloc>::size_type; + + template <class _AllocT> // we perform the allocator conversion inside the constructor + _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n) + : __alloc_(std::move(__alloc)), + __n_(__n), + __ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important + {} + + _LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); } + + _LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete; + _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT + : __alloc_(std::move(__other.__alloc_)), + __n_(__other.__n_), + __ptr_(__other.__ptr_) { + __other.__ptr_ = nullptr; + } + + _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete; + _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT { + if (std::addressof(__other) != this) { + __destroy(); + + __alloc_ = std::move(__other.__alloc_); + __n_ = __other.__n_; + __ptr_ = __other.__ptr_; __other.__ptr_ = nullptr; } - _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete; - _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT { - if (std::addressof(__other) != this) { - __destroy(); + return *this; + } - __alloc_ = std::move(__other.__alloc_); - __n_ = __other.__n_; - __ptr_ = __other.__ptr_; - __other.__ptr_ = nullptr; - } - - return *this; - } + _LIBCPP_HIDE_FROM_ABI _Pointer + __release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++ + _Pointer __tmp = __ptr_; + __ptr_ = nullptr; + return __tmp; + } - _LIBCPP_HIDE_FROM_ABI - _Pointer __release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++ - _Pointer __tmp = __ptr_; - __ptr_ = nullptr; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI - _Pointer __get() const _NOEXCEPT { - return __ptr_; - } + _LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; } private: - _LIBCPP_HIDE_FROM_ABI - void __destroy() _NOEXCEPT { - if (__ptr_ != nullptr) { - allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_); - } + _LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT { + if (__ptr_ != nullptr) { + allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_); } + } - _Alloc __alloc_; - _Size __n_; - _Pointer __ptr_; + _Alloc __alloc_; + _Size __n_; + _Pointer __ptr_; }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/allocator.h b/lib/libcxx/include/__memory/allocator.h index 47e1ef926a..4e6303914c 100644 --- a/lib/libcxx/include/__memory/allocator.h +++ b/lib/libcxx/include/__memory/allocator.h @@ -28,35 +28,48 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Tp> class allocator; +template <class _Tp> +class allocator; + +#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) +# pragma clang deprecated( \ + _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS, \ + "_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS is deprecated in LLVM 18 and will be removed in LLVM 19") +#endif #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION) // These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17. // Specializing allocator<void> is deprecated, but not using it. template <> -class _LIBCPP_TEMPLATE_VIS allocator<void> -{ -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) -public: - _LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef void value_type; +class _LIBCPP_TEMPLATE_VIS allocator<void> { +# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) - template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;}; -#endif +public: + _LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef void value_type; + + template <class _Up> + struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { + typedef allocator<_Up> other; + }; +# endif }; template <> -class _LIBCPP_TEMPLATE_VIS allocator<const void> -{ -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) -public: - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type; +class _LIBCPP_TEMPLATE_VIS allocator<const void> { +# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) - template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;}; -#endif +public: + _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type; + + template <class _Up> + struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { + typedef allocator<_Up> other; + }; +# endif }; #endif @@ -73,12 +86,11 @@ public: // By making those __non_trivial_if base classes unique, we work around this problem and // it is safe to start deriving from __non_trivial_if in existing classes. template <bool _Cond, class _Unique> -struct __non_trivial_if { }; +struct __non_trivial_if {}; template <class _Unique> struct __non_trivial_if<true, _Unique> { - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR __non_trivial_if() _NOEXCEPT { } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __non_trivial_if() _NOEXCEPT {} }; // allocator @@ -87,186 +99,173 @@ struct __non_trivial_if<true, _Unique> { // allocator<void> trivial in C++20. template <class _Tp> -class _LIBCPP_TEMPLATE_VIS allocator - : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > -{ - static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp value_type; - typedef true_type propagate_on_container_move_assignment; - typedef true_type is_always_equal; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default; - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - allocator(const allocator<_Up>&) _NOEXCEPT { } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - _Tp* allocate(size_t __n) { - if (__n > allocator_traits<allocator>::max_size(*this)) - __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { - return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } - } +class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > { + static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); -#if _LIBCPP_STD_VER >= 23 - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr - allocation_result<_Tp*> allocate_at_least(size_t __n) { - return {allocate(__n), __n}; - } +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp value_type; + typedef true_type propagate_on_container_move_assignment; +#if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS) + _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal; #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { - if (__libcpp_is_constant_evaluated()) { - ::operator delete(__p); - } else { - _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default; - // C++20 Removed members -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; - - template <class _Up> - struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { - typedef allocator<_Up> other; - }; - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - pointer address(reference __x) const _NOEXCEPT { - return _VSTD::addressof(__x); - } - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - const_pointer address(const_reference __x) const _NOEXCEPT { - return _VSTD::addressof(__x); - } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {} - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 - _Tp* allocate(size_t __n, const void*) { - return allocate(__n); + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) { + if (__n > allocator_traits<allocator>::max_size(*this)) + __throw_bad_array_new_length(); + if (__libcpp_is_constant_evaluated()) { + return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); + } else { + return static_cast<_Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } + } - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return size_type(~0) / sizeof(_Tp); - } +#if _LIBCPP_STD_VER >= 23 + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<_Tp*> allocate_at_least(size_t __n) { + return {allocate(__n), __n}; + } +#endif - template <class _Up, class... _Args> - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - void construct(_Up* __p, _Args&&... __args) { - ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { + if (__libcpp_is_constant_evaluated()) { + ::operator delete(__p); + } else { + std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); } + } - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - void destroy(pointer __p) { - __p->~_Tp(); - } + // C++20 Removed members +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) + _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; + + template <class _Up> + struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { + typedef allocator<_Up> other; + }; + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI pointer address(reference __x) const _NOEXCEPT { + return std::addressof(__x); + } + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT { + return std::addressof(__x); + } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* + allocate(size_t __n, const void*) { + return allocate(__n); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { + return size_type(~0) / sizeof(_Tp); + } + + template <class _Up, class... _Args> + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) { + ::new ((void*)__p) _Up(std::forward<_Args>(__args)...); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); } #endif }; template <class _Tp> class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> - : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > -{ - static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef const _Tp value_type; - typedef true_type propagate_on_container_move_assignment; - typedef true_type is_always_equal; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default; - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - allocator(const allocator<_Up>&) _NOEXCEPT { } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - const _Tp* allocate(size_t __n) { - if (__n > allocator_traits<allocator>::max_size(*this)) - __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { - return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast<const _Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } - } + : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > { + static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); -#if _LIBCPP_STD_VER >= 23 - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr - allocation_result<const _Tp*> allocate_at_least(size_t __n) { - return {allocate(__n), __n}; - } +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef const _Tp value_type; + typedef true_type propagate_on_container_move_assignment; +#if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS) + _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal; #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - void deallocate(const _Tp* __p, size_t __n) { - if (__libcpp_is_constant_evaluated()) { - ::operator delete(const_cast<_Tp*>(__p)); - } else { - _VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default; - // C++20 Removed members -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; - - template <class _Up> - struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { - typedef allocator<_Up> other; - }; - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - const_pointer address(const_reference __x) const _NOEXCEPT { - return _VSTD::addressof(__x); - } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {} - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 - const _Tp* allocate(size_t __n, const void*) { - return allocate(__n); + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const _Tp* allocate(size_t __n) { + if (__n > allocator_traits<allocator>::max_size(*this)) + __throw_bad_array_new_length(); + if (__libcpp_is_constant_evaluated()) { + return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp))); + } else { + return static_cast<const _Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } + } - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return size_type(~0) / sizeof(_Tp); - } +#if _LIBCPP_STD_VER >= 23 + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<const _Tp*> allocate_at_least(size_t __n) { + return {allocate(__n), __n}; + } +#endif - template <class _Up, class... _Args> - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - void construct(_Up* __p, _Args&&... __args) { - ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) { + if (__libcpp_is_constant_evaluated()) { + ::operator delete(const_cast<_Tp*>(__p)); + } else { + std::__libcpp_deallocate((void*)const_cast<_Tp*>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); } + } - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - void destroy(pointer __p) { - __p->~_Tp(); - } + // C++20 Removed members +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference; + _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; + + template <class _Up> + struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { + typedef allocator<_Up> other; + }; + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT { + return std::addressof(__x); + } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 const _Tp* + allocate(size_t __n, const void*) { + return allocate(__n); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { + return size_type(~0) / sizeof(_Tp); + } + + template <class _Up, class... _Args> + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) { + ::new ((void*)__p) _Up(std::forward<_Args>(__args)...); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); } #endif }; template <class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 -bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT { + return true; +} #if _LIBCPP_STD_VER <= 17 template <class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT { + return false; +} #endif diff --git a/lib/libcxx/include/__memory/allocator_arg_t.h b/lib/libcxx/include/__memory/allocator_arg_t.h index 4d9c115f72..7e66da740c 100644 --- a/lib/libcxx/include/__memory/allocator_arg_t.h +++ b/lib/libcxx/include/__memory/allocator_arg_t.h @@ -23,7 +23,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; +struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { + explicit allocator_arg_t() = default; +}; #if _LIBCPP_STD_VER >= 17 inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); @@ -35,42 +37,35 @@ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); // allocator construction -template <class _Tp, class _Alloc, class ..._Args> -struct __uses_alloc_ctor_imp -{ - typedef _LIBCPP_NODEBUG __remove_cvref_t<_Alloc> _RawAlloc; - static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; - static const bool __ic = - is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; - static const int value = __ua ? 2 - __ic : 0; +template <class _Tp, class _Alloc, class... _Args> +struct __uses_alloc_ctor_imp { + typedef _LIBCPP_NODEBUG __remove_cvref_t<_Alloc> _RawAlloc; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; + static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + static const int value = __ua ? 2 - __ic : 0; }; -template <class _Tp, class _Alloc, class ..._Args> -struct __uses_alloc_ctor - : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> - {}; +template <class _Tp, class _Alloc, class... _Args> +struct __uses_alloc_ctor : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> {}; template <class _Tp, class _Allocator, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY -void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args ) -{ - new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); +inline _LIBCPP_HIDE_FROM_ABI void +__user_alloc_construct_impl(integral_constant<int, 0>, _Tp* __storage, const _Allocator&, _Args&&... __args) { + new (__storage) _Tp(std::forward<_Args>(__args)...); } // FIXME: This should have a version which takes a non-const alloc. template <class _Tp, class _Allocator, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY -void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) -{ - new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); +inline _LIBCPP_HIDE_FROM_ABI void +__user_alloc_construct_impl(integral_constant<int, 1>, _Tp* __storage, const _Allocator& __a, _Args&&... __args) { + new (__storage) _Tp(allocator_arg, __a, std::forward<_Args>(__args)...); } // FIXME: This should have a version which takes a non-const alloc. template <class _Tp, class _Allocator, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY -void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) -{ - new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); +inline _LIBCPP_HIDE_FROM_ABI void +__user_alloc_construct_impl(integral_constant<int, 2>, _Tp* __storage, const _Allocator& __a, _Args&&... __args) { + new (__storage) _Tp(std::forward<_Args>(__args)..., __a); } #endif // _LIBCPP_CXX03_LANG diff --git a/lib/libcxx/include/__memory/allocator_destructor.h b/lib/libcxx/include/__memory/allocator_destructor.h index 623ad8ad80..ed3d8918f5 100644 --- a/lib/libcxx/include/__memory/allocator_destructor.h +++ b/lib/libcxx/include/__memory/allocator_destructor.h @@ -19,22 +19,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Alloc> -class __allocator_destructor -{ - typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits; +class __allocator_destructor { + typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits; + public: - typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer; - typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type; + typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer; + typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type; + private: - _Alloc& __alloc_; - size_type __s_; + _Alloc& __alloc_; + size_type __s_; + public: - _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) - _NOEXCEPT - : __alloc_(__a), __s_(__s) {} - _LIBCPP_INLINE_VISIBILITY - void operator()(pointer __p) _NOEXCEPT - {__alloc_traits::deallocate(__alloc_, __p, __s_);} + _LIBCPP_HIDE_FROM_ABI __allocator_destructor(_Alloc& __a, size_type __s) _NOEXCEPT : __alloc_(__a), __s_(__s) {} + _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc_, __p, __s_); } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/allocator_traits.h b/lib/libcxx/include/__memory/allocator_traits.h index 4658098d64..c4482872ea 100644 --- a/lib/libcxx/include/__memory/allocator_traits.h +++ b/lib/libcxx/include/__memory/allocator_traits.h @@ -33,326 +33,312 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -#define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ - template <class _Tp, class = void> struct NAME : false_type { }; \ - template <class _Tp> struct NAME<_Tp, __void_t<typename _Tp:: PROPERTY > > : true_type { } +#define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ + template <class _Tp, class = void> \ + struct NAME : false_type {}; \ + template <class _Tp> \ + struct NAME<_Tp, __void_t<typename _Tp::PROPERTY > > : true_type {} // __pointer _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer); -template <class _Tp, class _Alloc, +template <class _Tp, + class _Alloc, class _RawAlloc = __libcpp_remove_reference_t<_Alloc>, - bool = __has_pointer<_RawAlloc>::value> + bool = __has_pointer<_RawAlloc>::value> struct __pointer { - using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer; + using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer; }; template <class _Tp, class _Alloc, class _RawAlloc> struct __pointer<_Tp, _Alloc, _RawAlloc, false> { - using type _LIBCPP_NODEBUG = _Tp*; + using type _LIBCPP_NODEBUG = _Tp*; }; // __const_pointer _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer); -template <class _Tp, class _Ptr, class _Alloc, - bool = __has_const_pointer<_Alloc>::value> +template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> struct __const_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer; + using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer; }; template <class _Tp, class _Ptr, class _Alloc> struct __const_pointer<_Tp, _Ptr, _Alloc, false> { #ifdef _LIBCPP_CXX03_LANG - using type = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other; + using type = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other; #else - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>; #endif }; // __void_pointer _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer); -template <class _Ptr, class _Alloc, - bool = __has_void_pointer<_Alloc>::value> +template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> struct __void_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer; + using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer; }; template <class _Ptr, class _Alloc> struct __void_pointer<_Ptr, _Alloc, false> { #ifdef _LIBCPP_CXX03_LANG - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other; #else - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>; #endif }; // __const_void_pointer _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer); -template <class _Ptr, class _Alloc, - bool = __has_const_void_pointer<_Alloc>::value> +template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> struct __const_void_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer; + using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer; }; template <class _Ptr, class _Alloc> struct __const_void_pointer<_Ptr, _Alloc, false> { #ifdef _LIBCPP_CXX03_LANG - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other; #else - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>; #endif }; // __size_type _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_size_type, size_type); template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> -struct __size_type : make_unsigned<_DiffType> { }; +struct __size_type : make_unsigned<_DiffType> {}; template <class _Alloc, class _DiffType> struct __size_type<_Alloc, _DiffType, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::size_type; + using type _LIBCPP_NODEBUG = typename _Alloc::size_type; }; // __alloc_traits_difference_type _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type); template <class _Alloc, class _Ptr, bool = __has_alloc_traits_difference_type<_Alloc>::value> struct __alloc_traits_difference_type { - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type; }; template <class _Alloc, class _Ptr> struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::difference_type; + using type _LIBCPP_NODEBUG = typename _Alloc::difference_type; }; // __propagate_on_container_copy_assignment _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment); template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> -struct __propagate_on_container_copy_assignment : false_type { }; +struct __propagate_on_container_copy_assignment : false_type {}; template <class _Alloc> struct __propagate_on_container_copy_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment; + using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment; }; // __propagate_on_container_move_assignment _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_move_assignment, propagate_on_container_move_assignment); template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> -struct __propagate_on_container_move_assignment : false_type { }; +struct __propagate_on_container_move_assignment : false_type {}; template <class _Alloc> struct __propagate_on_container_move_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment; + using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment; }; // __propagate_on_container_swap _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_swap, propagate_on_container_swap); template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> -struct __propagate_on_container_swap : false_type { }; +struct __propagate_on_container_swap : false_type {}; template <class _Alloc> struct __propagate_on_container_swap<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap; + using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap; }; // __is_always_equal _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_is_always_equal, is_always_equal); template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> -struct __is_always_equal : is_empty<_Alloc> { }; +struct __is_always_equal : is_empty<_Alloc> {}; template <class _Alloc> struct __is_always_equal<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal; + using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal; }; // __allocator_traits_rebind _LIBCPP_SUPPRESS_DEPRECATED_PUSH template <class _Tp, class _Up, class = void> -struct __has_rebind_other : false_type { }; +struct __has_rebind_other : false_type {}; template <class _Tp, class _Up> -struct __has_rebind_other<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > : true_type { }; +struct __has_rebind_other<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > : true_type {}; template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> struct __allocator_traits_rebind { static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind"); using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other; }; -template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> +template <template <class, class...> class _Alloc, class _Tp, class... _Args, class _Up> struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> { - using type _LIBCPP_NODEBUG = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other; + using type _LIBCPP_NODEBUG = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other; }; -template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> +template <template <class, class...> class _Alloc, class _Tp, class... _Args, class _Up> struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> { - using type _LIBCPP_NODEBUG = _Alloc<_Up, _Args...>; + using type _LIBCPP_NODEBUG = _Alloc<_Up, _Args...>; }; _LIBCPP_SUPPRESS_DEPRECATED_POP -template<class _Alloc, class _Tp> +template <class _Alloc, class _Tp> using __allocator_traits_rebind_t = typename __allocator_traits_rebind<_Alloc, _Tp>::type; _LIBCPP_SUPPRESS_DEPRECATED_PUSH // __has_allocate_hint template <class _Alloc, class _SizeType, class _ConstVoidPtr, class = void> -struct __has_allocate_hint : false_type { }; +struct __has_allocate_hint : false_type {}; template <class _Alloc, class _SizeType, class _ConstVoidPtr> -struct __has_allocate_hint<_Alloc, _SizeType, _ConstVoidPtr, decltype( - (void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()) -)> : true_type { }; +struct __has_allocate_hint< + _Alloc, + _SizeType, + _ConstVoidPtr, + decltype((void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()))> + : true_type {}; // __has_construct -template <class, class _Alloc, class ..._Args> -struct __has_construct_impl : false_type { }; +template <class, class _Alloc, class... _Args> +struct __has_construct_impl : false_type {}; -template <class _Alloc, class ..._Args> -struct __has_construct_impl<decltype( - (void)std::declval<_Alloc>().construct(std::declval<_Args>()...) -), _Alloc, _Args...> : true_type { }; +template <class _Alloc, class... _Args> +struct __has_construct_impl<decltype((void)std::declval<_Alloc>().construct(std::declval<_Args>()...)), + _Alloc, + _Args...> : true_type {}; -template <class _Alloc, class ..._Args> -struct __has_construct : __has_construct_impl<void, _Alloc, _Args...> { }; +template <class _Alloc, class... _Args> +struct __has_construct : __has_construct_impl<void, _Alloc, _Args...> {}; // __has_destroy template <class _Alloc, class _Pointer, class = void> -struct __has_destroy : false_type { }; +struct __has_destroy : false_type {}; template <class _Alloc, class _Pointer> -struct __has_destroy<_Alloc, _Pointer, decltype( - (void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()) -)> : true_type { }; +struct __has_destroy<_Alloc, _Pointer, decltype((void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()))> + : true_type {}; // __has_max_size template <class _Alloc, class = void> -struct __has_max_size : false_type { }; +struct __has_max_size : false_type {}; template <class _Alloc> -struct __has_max_size<_Alloc, decltype( - (void)std::declval<_Alloc&>().max_size() -)> : true_type { }; +struct __has_max_size<_Alloc, decltype((void)std::declval<_Alloc&>().max_size())> : true_type {}; // __has_select_on_container_copy_construction template <class _Alloc, class = void> -struct __has_select_on_container_copy_construction : false_type { }; +struct __has_select_on_container_copy_construction : false_type {}; template <class _Alloc> -struct __has_select_on_container_copy_construction<_Alloc, decltype( - (void)std::declval<_Alloc>().select_on_container_copy_construction() -)> : true_type { }; +struct __has_select_on_container_copy_construction< + _Alloc, + decltype((void)std::declval<_Alloc>().select_on_container_copy_construction())> : true_type {}; _LIBCPP_SUPPRESS_DEPRECATED_POP template <class _Alloc> -struct _LIBCPP_TEMPLATE_VIS allocator_traits -{ - using allocator_type = _Alloc; - using value_type = typename allocator_type::value_type; - using pointer = typename __pointer<value_type, allocator_type>::type; - using const_pointer = typename __const_pointer<value_type, pointer, allocator_type>::type; - using void_pointer = typename __void_pointer<pointer, allocator_type>::type; - using const_void_pointer = typename __const_void_pointer<pointer, allocator_type>::type; - using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type; - using size_type = typename __size_type<allocator_type, difference_type>::type; - using propagate_on_container_copy_assignment = typename __propagate_on_container_copy_assignment<allocator_type>::type; - using propagate_on_container_move_assignment = typename __propagate_on_container_move_assignment<allocator_type>::type; - using propagate_on_container_swap = typename __propagate_on_container_swap<allocator_type>::type; - using is_always_equal = typename __is_always_equal<allocator_type>::type; +struct _LIBCPP_TEMPLATE_VIS allocator_traits { + using allocator_type = _Alloc; + using value_type = typename allocator_type::value_type; + using pointer = typename __pointer<value_type, allocator_type>::type; + using const_pointer = typename __const_pointer<value_type, pointer, allocator_type>::type; + using void_pointer = typename __void_pointer<pointer, allocator_type>::type; + using const_void_pointer = typename __const_void_pointer<pointer, allocator_type>::type; + using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type; + using size_type = typename __size_type<allocator_type, difference_type>::type; + using propagate_on_container_copy_assignment = + typename __propagate_on_container_copy_assignment<allocator_type>::type; + using propagate_on_container_move_assignment = + typename __propagate_on_container_move_assignment<allocator_type>::type; + using propagate_on_container_swap = typename __propagate_on_container_swap<allocator_type>::type; + using is_always_equal = typename __is_always_equal<allocator_type>::type; #ifndef _LIBCPP_CXX03_LANG - template <class _Tp> - using rebind_alloc = __allocator_traits_rebind_t<allocator_type, _Tp>; - template <class _Tp> - using rebind_traits = allocator_traits<rebind_alloc<_Tp> >; + template <class _Tp> + using rebind_alloc = __allocator_traits_rebind_t<allocator_type, _Tp>; + template <class _Tp> + using rebind_traits = allocator_traits<rebind_alloc<_Tp> >; #else // _LIBCPP_CXX03_LANG - template <class _Tp> - struct rebind_alloc { - using other = __allocator_traits_rebind_t<allocator_type, _Tp>; - }; - template <class _Tp> - struct rebind_traits { - using other = allocator_traits<typename rebind_alloc<_Tp>::other>; - }; + template <class _Tp> + struct rebind_alloc { + using other = __allocator_traits_rebind_t<allocator_type, _Tp>; + }; + template <class _Tp> + struct rebind_traits { + using other = allocator_traits<typename rebind_alloc<_Tp>::other>; + }; #endif // _LIBCPP_CXX03_LANG - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static pointer allocate(allocator_type& __a, size_type __n) { - return __a.allocate(__n); - } - - template <class _Ap = _Alloc, class = - __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> > - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) { - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - return __a.allocate(__n, __hint); - _LIBCPP_SUPPRESS_DEPRECATED_POP - } - template <class _Ap = _Alloc, class = void, class = - __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> > - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) { - return __a.allocate(__n); - } - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT { - __a.deallocate(__p, __n); - } - - template <class _Tp, class... _Args, class = - __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) { - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __a.construct(__p, _VSTD::forward<_Args>(__args)...); - _LIBCPP_SUPPRESS_DEPRECATED_POP - } - template <class _Tp, class... _Args, class = void, class = - __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static void construct(allocator_type&, _Tp* __p, _Args&&... __args) { -#if _LIBCPP_STD_VER >= 20 - _VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...); -#else - ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); -#endif - } - - template <class _Tp, class = - __enable_if_t<__has_destroy<allocator_type, _Tp*>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static void destroy(allocator_type& __a, _Tp* __p) { - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __a.destroy(__p); - _LIBCPP_SUPPRESS_DEPRECATED_POP - } - template <class _Tp, class = void, class = - __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static void destroy(allocator_type&, _Tp* __p) { -#if _LIBCPP_STD_VER >= 20 - _VSTD::destroy_at(__p); -#else - __p->~_Tp(); -#endif - } - - template <class _Ap = _Alloc, class = - __enable_if_t<__has_max_size<const _Ap>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static size_type max_size(const allocator_type& __a) _NOEXCEPT { - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - return __a.max_size(); - _LIBCPP_SUPPRESS_DEPRECATED_POP - } - template <class _Ap = _Alloc, class = void, class = - __enable_if_t<!__has_max_size<const _Ap>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static size_type max_size(const allocator_type&) _NOEXCEPT { - return numeric_limits<size_type>::max() / sizeof(value_type); - } - - template <class _Ap = _Alloc, class = - __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static allocator_type select_on_container_copy_construction(const allocator_type& __a) { - return __a.select_on_container_copy_construction(); - } - template <class _Ap = _Alloc, class = void, class = - __enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static allocator_type select_on_container_copy_construction(const allocator_type& __a) { - return __a; - } + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + allocate(allocator_type& __a, size_type __n) { + return __a.allocate(__n); + } + + template <class _Ap = _Alloc, class = __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> > + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + return __a.allocate(__n, __hint); + _LIBCPP_SUPPRESS_DEPRECATED_POP + } + template <class _Ap = _Alloc, + class = void, + class = __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> > + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + allocate(allocator_type& __a, size_type __n, const_void_pointer) { + return __a.allocate(__n); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void + deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT { + __a.deallocate(__p, __n); + } + + template <class _Tp, class... _Args, class = __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void + construct(allocator_type& __a, _Tp* __p, _Args&&... __args) { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + __a.construct(__p, std::forward<_Args>(__args)...); + _LIBCPP_SUPPRESS_DEPRECATED_POP + } + template <class _Tp, + class... _Args, + class = void, + class = __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void + construct(allocator_type&, _Tp* __p, _Args&&... __args) { + std::__construct_at(__p, std::forward<_Args>(__args)...); + } + + template <class _Tp, class = __enable_if_t<__has_destroy<allocator_type, _Tp*>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type& __a, _Tp* __p) { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + __a.destroy(__p); + _LIBCPP_SUPPRESS_DEPRECATED_POP + } + template <class _Tp, class = void, class = __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type&, _Tp* __p) { + std::__destroy_at(__p); + } + + template <class _Ap = _Alloc, class = __enable_if_t<__has_max_size<const _Ap>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type& __a) _NOEXCEPT { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + return __a.max_size(); + _LIBCPP_SUPPRESS_DEPRECATED_POP + } + template <class _Ap = _Alloc, class = void, class = __enable_if_t<!__has_max_size<const _Ap>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type&) _NOEXCEPT { + return numeric_limits<size_type>::max() / sizeof(value_type); + } + + template <class _Ap = _Alloc, class = __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type + select_on_container_copy_construction(const allocator_type& __a) { + return __a.select_on_container_copy_construction(); + } + template <class _Ap = _Alloc, + class = void, + class = __enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type + select_on_container_copy_construction(const allocator_type& __a) { + return __a; + } }; #ifndef _LIBCPP_CXX03_LANG @@ -365,57 +351,47 @@ using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other; // __is_default_allocator template <class _Tp> -struct __is_default_allocator : false_type { }; +struct __is_default_allocator : false_type {}; -template <class> class allocator; +template <class> +class allocator; template <class _Tp> -struct __is_default_allocator<allocator<_Tp> > : true_type { }; +struct __is_default_allocator<allocator<_Tp> > : true_type {}; // __is_cpp17_move_insertable template <class _Alloc, class = void> -struct __is_cpp17_move_insertable - : is_move_constructible<typename _Alloc::value_type> -{ }; +struct __is_cpp17_move_insertable : is_move_constructible<typename _Alloc::value_type> {}; template <class _Alloc> -struct __is_cpp17_move_insertable<_Alloc, __enable_if_t< - !__is_default_allocator<_Alloc>::value && - __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value -> > : true_type { }; +struct __is_cpp17_move_insertable< + _Alloc, + __enable_if_t< !__is_default_allocator<_Alloc>::value && + __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value > > + : true_type {}; // __is_cpp17_copy_insertable template <class _Alloc, class = void> struct __is_cpp17_copy_insertable : integral_constant<bool, - is_copy_constructible<typename _Alloc::value_type>::value && - __is_cpp17_move_insertable<_Alloc>::value - > -{ }; + is_copy_constructible<typename _Alloc::value_type>::value && + __is_cpp17_move_insertable<_Alloc>::value > {}; template <class _Alloc> -struct __is_cpp17_copy_insertable<_Alloc, __enable_if_t< - !__is_default_allocator<_Alloc>::value && - __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value -> > - : __is_cpp17_move_insertable<_Alloc> -{ }; +struct __is_cpp17_copy_insertable< + _Alloc, + __enable_if_t< !__is_default_allocator<_Alloc>::value && + __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value > > + : __is_cpp17_move_insertable<_Alloc> {}; // ASan choices #ifndef _LIBCPP_HAS_NO_ASAN -# define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1 +# define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1 #endif #ifdef _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS template <class _Alloc> -struct __asan_annotate_container_with_allocator -# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1600 - : true_type {}; -# else - // TODO(LLVM-18): Remove the special-casing - : false_type {}; -# endif - +struct __asan_annotate_container_with_allocator : true_type {}; template <class _Tp> struct __asan_annotate_container_with_allocator<allocator<_Tp> > : true_type {}; #endif diff --git a/lib/libcxx/include/__memory/assume_aligned.h b/lib/libcxx/include/__memory/assume_aligned.h index 00c2928dcc..526eb3334f 100644 --- a/lib/libcxx/include/__memory/assume_aligned.h +++ b/lib/libcxx/include/__memory/assume_aligned.h @@ -22,23 +22,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 - template <size_t _Np, class _Tp> -[[nodiscard]] -_LIBCPP_HIDE_FROM_ABI -constexpr _Tp* assume_aligned(_Tp* __ptr) { - static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, - "std::assume_aligned<N>(p) requires N to be a power of two"); +_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) { + static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two"); - if (is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) { + (void)__builtin_assume_aligned(__ptr, _Np); return __ptr; } else { - _LIBCPP_ASSERT_UNCATEGORIZED(reinterpret_cast<uintptr_t>(__ptr) % _Np == 0, "Alignment assumption is violated"); + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( + reinterpret_cast<uintptr_t>(__ptr) % _Np == 0, "Alignment assumption is violated"); return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Np)); } } +#if _LIBCPP_STD_VER >= 20 + +template <size_t _Np, class _Tp> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* assume_aligned(_Tp* __ptr) { + return std::__assume_aligned<_Np>(__ptr); +} + #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/auto_ptr.h b/lib/libcxx/include/__memory/auto_ptr.h index c007b4d21a..752143616b 100644 --- a/lib/libcxx/include/__memory/auto_ptr.h +++ b/lib/libcxx/include/__memory/auto_ptr.h @@ -21,60 +21,68 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref -{ - _Tp* __ptr_; +struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref { + _Tp* __ptr_; }; -template<class _Tp> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr -{ +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr { private: - _Tp* __ptr_; + _Tp* __ptr_; + public: - typedef _Tp element_type; + typedef _Tp element_type; - _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {} - _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {} - template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT - : __ptr_(__p.release()) {} - _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT - {reset(__p.release()); return *this;} - template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT - {reset(__p.release()); return *this;} - _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT - {reset(__p.__ptr_); return *this;} - _LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;} + _LIBCPP_HIDE_FROM_ABI explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {} + _LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {} + template <class _Up> + _LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT : __ptr_(__p.release()) {} + _LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT { + reset(__p.release()); + return *this; + } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT { + reset(__p.release()); + return *this; + } + _LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT { + reset(__p.__ptr_); + return *this; + } + _LIBCPP_HIDE_FROM_ABI ~auto_ptr() _NOEXCEPT { delete __ptr_; } - _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT - {return *__ptr_;} - _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;} - _LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;} - _LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT - { - _Tp* __t = __ptr_; - __ptr_ = nullptr; - return __t; - } - _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT - { - if (__ptr_ != __p) - delete __ptr_; - __ptr_ = __p; - } + _LIBCPP_HIDE_FROM_ABI _Tp& operator*() const _NOEXCEPT { return *__ptr_; } + _LIBCPP_HIDE_FROM_ABI _Tp* operator->() const _NOEXCEPT { return __ptr_; } + _LIBCPP_HIDE_FROM_ABI _Tp* get() const _NOEXCEPT { return __ptr_; } + _LIBCPP_HIDE_FROM_ABI _Tp* release() _NOEXCEPT { + _Tp* __t = __ptr_; + __ptr_ = nullptr; + return __t; + } + _LIBCPP_HIDE_FROM_ABI void reset(_Tp* __p = 0) _NOEXCEPT { + if (__ptr_ != __p) + delete __ptr_; + __ptr_ = __p; + } - _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} - template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT - {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} - template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT - {return auto_ptr<_Up>(release());} + _LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} + template <class _Up> + _LIBCPP_HIDE_FROM_ABI operator auto_ptr_ref<_Up>() _NOEXCEPT { + auto_ptr_ref<_Up> __t; + __t.__ptr_ = release(); + return __t; + } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI operator auto_ptr<_Up>() _NOEXCEPT { + return auto_ptr<_Up>(release()); + } }; template <> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> -{ +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> { public: - typedef void element_type; + typedef void element_type; }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/builtin_new_allocator.h b/lib/libcxx/include/__memory/builtin_new_allocator.h index ab449ad299..c6f7f3c5ff 100644 --- a/lib/libcxx/include/__memory/builtin_new_allocator.h +++ b/lib/libcxx/include/__memory/builtin_new_allocator.h @@ -32,10 +32,10 @@ struct __builtin_new_allocator { : __size_(__size), __align_(__align) {} _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const _NOEXCEPT { - _VSTD::__libcpp_deallocate(__p, __size_, __align_); + std::__libcpp_deallocate(__p, __size_, __align_); } - private: + private: size_t __size_; size_t __align_; }; @@ -43,25 +43,22 @@ struct __builtin_new_allocator { typedef unique_ptr<void, __builtin_new_deleter> __holder_t; _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_bytes(size_t __s, size_t __align) { - return __holder_t(_VSTD::__libcpp_allocate(__s, __align), - __builtin_new_deleter(__s, __align)); + return __holder_t(std::__libcpp_allocate(__s, __align), __builtin_new_deleter(__s, __align)); } - _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, - size_t __align) _NOEXCEPT { - _VSTD::__libcpp_deallocate(__p, __s, __align); + _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, size_t __align) _NOEXCEPT { + std::__libcpp_deallocate(__p, __s, __align); } template <class _Tp> - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE - _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) { - return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) { + return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); } template <class _Tp> - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE - _LIBCPP_HIDE_FROM_ABI static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { - __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static void + __deallocate_type(void* __p, size_t __n) _NOEXCEPT { + __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); } }; diff --git a/lib/libcxx/include/__memory/compressed_pair.h b/lib/libcxx/include/__memory/compressed_pair.h index f24b2bac56..e9faada2f0 100644 --- a/lib/libcxx/include/__memory/compressed_pair.h +++ b/lib/libcxx/include/__memory/compressed_pair.h @@ -42,21 +42,21 @@ struct __value_init_tag {}; template <class _Tp, int _Idx, bool _CanBeEmptyBase = is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> struct __compressed_pair_elem { - using _ParamT = _Tp; - using reference = _Tp&; + using _ParamT = _Tp; + using reference = _Tp&; using const_reference = const _Tp&; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {} template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - explicit __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) + : __value_(std::forward<_Up>(__u)) {} #ifndef _LIBCPP_CXX03_LANG template <class... _Args, size_t... _Indices> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 - explicit __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair_elem( + piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {} #endif @@ -69,18 +69,18 @@ private: template <class _Tp, int _Idx> struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { - using _ParamT = _Tp; - using reference = _Tp&; + using _ParamT = _Tp; + using reference = _Tp&; using const_reference = const _Tp&; - using __value_type = _Tp; + using __value_type = _Tp; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {} template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - explicit __compressed_pair_elem(_Up&& __u) : __value_type(std::forward<_Up>(__u)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) + : __value_type(std::forward<_Up>(__u)) {} #ifndef _LIBCPP_CXX03_LANG template <class... _Args, size_t... _Indices> @@ -94,74 +94,63 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { }; template <class _T1, class _T2> -class __compressed_pair : private __compressed_pair_elem<_T1, 0>, - private __compressed_pair_elem<_T2, 1> { +class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> { public: // NOTE: This static assert should never fire because __compressed_pair // is *almost never* used in a scenario where it's possible for T1 == T2. // (The exception is std::function where it is possible that the function // object and the allocator have the same type). - static_assert((!is_same<_T1, _T2>::value), - "__compressed_pair cannot be instantiated when T1 and T2 are the same type; " - "The current implementation is NOT ABI-compatible with the previous implementation for this configuration"); + static_assert( + (!is_same<_T1, _T2>::value), + "__compressed_pair cannot be instantiated when T1 and T2 are the same type; " + "The current implementation is NOT ABI-compatible with the previous implementation for this configuration"); using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>; using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>; template <bool _Dummy = true, - class = __enable_if_t< - __dependent_type<is_default_constructible<_T1>, _Dummy>::value && - __dependent_type<is_default_constructible<_T2>, _Dummy>::value - > - > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - explicit __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} + class = __enable_if_t< __dependent_type<is_default_constructible<_T1>, _Dummy>::value && + __dependent_type<is_default_constructible<_T2>, _Dummy>::value > > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair() + : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} template <class _U1, class _U2> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - explicit __compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair(_U1&& __t1, _U2&& __t2) + : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} #ifndef _LIBCPP_CXX03_LANG template <class... _Args1, class... _Args2> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 - explicit __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair( + piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices<sizeof...(_Args1)>::type()), _Base2(__pc, std::move(__second_args), typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 - typename _Base1::reference first() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base1::reference first() _NOEXCEPT { return static_cast<_Base1&>(*this).__get(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - typename _Base1::const_reference first() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT { return static_cast<_Base1 const&>(*this).__get(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 - typename _Base2::reference second() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base2::reference second() _NOEXCEPT { return static_cast<_Base2&>(*this).__get(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - typename _Base2::const_reference second() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT { return static_cast<_Base2 const&>(*this).__get(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static - _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { return static_cast<_Base1*>(__pair); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static - _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { return static_cast<_Base2*>(__pair); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 - void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value&& __is_nothrow_swappable<_T2>::value) { using std::swap; swap(first(), __x.first()); swap(second(), __x.second()); @@ -169,9 +158,9 @@ public: }; template <class _T1, class _T2> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 -void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void +swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value&& __is_nothrow_swappable<_T2>::value) { __x.swap(__y); } diff --git a/lib/libcxx/include/__memory/concepts.h b/lib/libcxx/include/__memory/concepts.h index 97cc3583ec..216144aad7 100644 --- a/lib/libcxx/include/__memory/concepts.h +++ b/lib/libcxx/include/__memory/concepts.h @@ -37,8 +37,7 @@ namespace ranges { // at the address pointed-to by the iterator, which requires an lvalue. template <class _Ip> concept __nothrow_input_iterator = - input_iterator<_Ip> && - is_lvalue_reference_v<iter_reference_t<_Ip>> && + input_iterator<_Ip> && is_lvalue_reference_v<iter_reference_t<_Ip>> && same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>; template <class _Sp, class _Ip> @@ -46,20 +45,14 @@ concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>; template <class _Rp> concept __nothrow_input_range = - range<_Rp> && - __nothrow_input_iterator<iterator_t<_Rp>> && - __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>; + range<_Rp> && __nothrow_input_iterator<iterator_t<_Rp>> && __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>; template <class _Ip> concept __nothrow_forward_iterator = - __nothrow_input_iterator<_Ip> && - forward_iterator<_Ip> && - __nothrow_sentinel_for<_Ip, _Ip>; + __nothrow_input_iterator<_Ip> && forward_iterator<_Ip> && __nothrow_sentinel_for<_Ip, _Ip>; template <class _Rp> -concept __nothrow_forward_range = - __nothrow_input_range<_Rp> && - __nothrow_forward_iterator<iterator_t<_Rp>>; +concept __nothrow_forward_range = __nothrow_input_range<_Rp> && __nothrow_forward_iterator<iterator_t<_Rp>>; } // namespace ranges diff --git a/lib/libcxx/include/__memory/construct_at.h b/lib/libcxx/include/__memory/construct_at.h index a032c33b47..91d17134db 100644 --- a/lib/libcxx/include/__memory/construct_at.h +++ b/lib/libcxx/include/__memory/construct_at.h @@ -37,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))> _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) { - _LIBCPP_ASSERT_UNCATEGORIZED(__location != nullptr, "null pointer given to construct_at"); + _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"); return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); } @@ -48,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Ar #if _LIBCPP_STD_VER >= 20 return std::construct_at(__location, std::forward<_Args>(__args)...); #else - return _LIBCPP_ASSERT_UNCATEGORIZED(__location != nullptr, "null pointer given to construct_at"), + return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"), ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); #endif } @@ -59,71 +59,64 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Ar // taking an array). template <class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -_ForwardIterator __destroy(_ForwardIterator, _ForwardIterator); - -template <class _Tp, typename enable_if<!is_array<_Tp>::value, int>::type = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -void __destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT_UNCATEGORIZED(__loc != nullptr, "null pointer given to destroy_at"); - __loc->~_Tp(); +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator __destroy(_ForwardIterator, _ForwardIterator); + +template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at"); + __loc->~_Tp(); } #if _LIBCPP_STD_VER >= 20 -template <class _Tp, typename enable_if<is_array<_Tp>::value, int>::type = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -void __destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT_UNCATEGORIZED(__loc != nullptr, "null pointer given to destroy_at"); - std::__destroy(std::begin(*__loc), std::end(*__loc)); +template <class _Tp, __enable_if_t<is_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at"); + std::__destroy(std::begin(*__loc), std::end(*__loc)); } #endif template <class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -_ForwardIterator __destroy(_ForwardIterator __first, _ForwardIterator __last) { - for (; __first != __last; ++__first) - std::__destroy_at(std::addressof(*__first)); - return __first; +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +__destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + std::__destroy_at(std::addressof(*__first)); + return __first; } template <class _BidirectionalIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -_BidirectionalIterator __reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) { - while (__last != __first) { - --__last; - std::__destroy_at(std::addressof(*__last)); - } - return __last; +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator +__reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) { + while (__last != __first) { + --__last; + std::__destroy_at(std::addressof(*__last)); + } + return __last; } #if _LIBCPP_STD_VER >= 17 template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -void destroy_at(_Tp* __loc) { - std::__destroy_at(__loc); +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc) { + std::__destroy_at(__loc); } -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -void destroy_at(_Tp* __loc) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc) { std::__destroy_at(__loc); } -#endif +# endif template <class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -void destroy(_ForwardIterator __first, _ForwardIterator __last) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy(_ForwardIterator __first, _ForwardIterator __last) { (void)std::__destroy(std::move(__first), std::move(__last)); } template <class _ForwardIterator, class _Size> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { - for (; __n > 0; (void)++__first, --__n) - std::__destroy_at(std::addressof(*__first)); - return __first; +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { + for (; __n > 0; (void)++__first, --__n) + std::__destroy_at(std::addressof(*__first)); + return __first; } #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__memory/destruct_n.h b/lib/libcxx/include/__memory/destruct_n.h index 2cfb2e4c88..78635ad0af 100644 --- a/lib/libcxx/include/__memory/destruct_n.h +++ b/lib/libcxx/include/__memory/destruct_n.h @@ -20,43 +20,42 @@ _LIBCPP_BEGIN_NAMESPACE_STD -struct __destruct_n -{ +struct __destruct_n { private: - size_t __size_; + size_t __size_; - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT - {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void __process(_Tp* __p, false_type) _NOEXCEPT { + for (size_t __i = 0; __i < __size_; ++__i, ++__p) + __p->~_Tp(); + } - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT - {} + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void __process(_Tp*, true_type) _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT - {++__size_;} - _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT - {} + _LIBCPP_HIDE_FROM_ABI void __incr(false_type) _NOEXCEPT { ++__size_; } + _LIBCPP_HIDE_FROM_ABI void __incr(true_type) _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT - {__size_ = __s;} - _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT - {} -public: - _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT - : __size_(__s) {} - - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void __incr() _NOEXCEPT - {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} + _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, false_type) _NOEXCEPT { __size_ = __s; } + _LIBCPP_HIDE_FROM_ABI void __set(size_t, true_type) _NOEXCEPT {} - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT - {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} - - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT - {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} +public: + _LIBCPP_HIDE_FROM_ABI explicit __destruct_n(size_t __s) _NOEXCEPT : __size_(__s) {} + + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void __incr() _NOEXCEPT { + __incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>()); + } + + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, _Tp*) _NOEXCEPT { + __set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>()); + } + + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) _NOEXCEPT { + __process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>()); + } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/pointer_traits.h b/lib/libcxx/include/__memory/pointer_traits.h index c33e7bd43f..643b7391d3 100644 --- a/lib/libcxx/include/__memory/pointer_traits.h +++ b/lib/libcxx/include/__memory/pointer_traits.h @@ -35,24 +35,21 @@ template <class _Tp> struct __has_element_type<_Tp, __void_t<typename _Tp::element_type> > : true_type {}; template <class _Ptr, bool = __has_element_type<_Ptr>::value> -struct __pointer_traits_element_type; +struct __pointer_traits_element_type {}; template <class _Ptr> -struct __pointer_traits_element_type<_Ptr, true> -{ - typedef _LIBCPP_NODEBUG typename _Ptr::element_type type; +struct __pointer_traits_element_type<_Ptr, true> { + typedef _LIBCPP_NODEBUG typename _Ptr::element_type type; }; -template <template <class, class...> class _Sp, class _Tp, class ..._Args> -struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> -{ - typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::element_type type; +template <template <class, class...> class _Sp, class _Tp, class... _Args> +struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> { + typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::element_type type; }; -template <template <class, class...> class _Sp, class _Tp, class ..._Args> -struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> -{ - typedef _LIBCPP_NODEBUG _Tp type; +template <template <class, class...> class _Sp, class _Tp, class... _Args> +struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> { + typedef _LIBCPP_NODEBUG _Tp type; }; template <class _Tp, class = void> @@ -62,96 +59,108 @@ template <class _Tp> struct __has_difference_type<_Tp, __void_t<typename _Tp::difference_type> > : true_type {}; template <class _Ptr, bool = __has_difference_type<_Ptr>::value> -struct __pointer_traits_difference_type -{ - typedef _LIBCPP_NODEBUG ptrdiff_t type; +struct __pointer_traits_difference_type { + typedef _LIBCPP_NODEBUG ptrdiff_t type; }; template <class _Ptr> -struct __pointer_traits_difference_type<_Ptr, true> -{ - typedef _LIBCPP_NODEBUG typename _Ptr::difference_type type; +struct __pointer_traits_difference_type<_Ptr, true> { + typedef _LIBCPP_NODEBUG typename _Ptr::difference_type type; }; template <class _Tp, class _Up> -struct __has_rebind -{ +struct __has_rebind { private: - template <class _Xp> static false_type __test(...); - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - template <class _Xp> static true_type __test(typename _Xp::template rebind<_Up>* = 0); - _LIBCPP_SUPPRESS_DEPRECATED_POP + template <class _Xp> + static false_type __test(...); + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + template <class _Xp> + static true_type __test(typename _Xp::template rebind<_Up>* = 0); + _LIBCPP_SUPPRESS_DEPRECATED_POP + public: - static const bool value = decltype(__test<_Tp>(0))::value; + static const bool value = decltype(__test<_Tp>(0))::value; }; template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> -struct __pointer_traits_rebind -{ +struct __pointer_traits_rebind { #ifndef _LIBCPP_CXX03_LANG - typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type; + typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type; #else - typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up>::other type; #endif }; -template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> -struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> -{ +template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> { #ifndef _LIBCPP_CXX03_LANG - typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type; + typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type; #else - typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; #endif }; -template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> -struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> -{ - typedef _Sp<_Up, _Args...> type; +template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> { + typedef _Sp<_Up, _Args...> type; }; +template <class _Ptr, class = void> +struct __pointer_traits_impl {}; + template <class _Ptr> -struct _LIBCPP_TEMPLATE_VIS pointer_traits -{ - typedef _Ptr pointer; - typedef typename __pointer_traits_element_type<pointer>::type element_type; - typedef typename __pointer_traits_difference_type<pointer>::type difference_type; +struct __pointer_traits_impl<_Ptr, __void_t<typename __pointer_traits_element_type<_Ptr>::type> > { + typedef _Ptr pointer; + typedef typename __pointer_traits_element_type<pointer>::type element_type; + typedef typename __pointer_traits_difference_type<pointer>::type difference_type; #ifndef _LIBCPP_CXX03_LANG - template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; + template <class _Up> + using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; #else - template <class _Up> struct rebind - {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; + template <class _Up> + struct rebind { + typedef typename __pointer_traits_rebind<pointer, _Up>::type other; + }; #endif // _LIBCPP_CXX03_LANG private: - struct __nat {}; + struct __nat {}; + public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static pointer pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) - {return pointer::pointer_to(__r);} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) { + return pointer::pointer_to(__r); + } }; +template <class _Ptr> +struct _LIBCPP_TEMPLATE_VIS pointer_traits : __pointer_traits_impl<_Ptr> {}; + template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> -{ - typedef _Tp* pointer; - typedef _Tp element_type; - typedef ptrdiff_t difference_type; +struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> { + typedef _Tp* pointer; + typedef _Tp element_type; + typedef ptrdiff_t difference_type; #ifndef _LIBCPP_CXX03_LANG - template <class _Up> using rebind = _Up*; + template <class _Up> + using rebind = _Up*; #else - template <class _Up> struct rebind {typedef _Up* other;}; + template <class _Up> + struct rebind { + typedef _Up* other; + }; #endif private: - struct __nat {}; + struct __nat {}; + public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 - static pointer pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) _NOEXCEPT - {return _VSTD::addressof(__r);} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) _NOEXCEPT { + return std::addressof(__r); + } }; #ifndef _LIBCPP_CXX03_LANG @@ -168,27 +177,23 @@ template <class _Pointer, class = void> struct __to_address_helper; template <class _Tp> -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -_Tp* __to_address(_Tp* __p) _NOEXCEPT { - static_assert(!is_function<_Tp>::value, "_Tp is a function type"); - return __p; +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __to_address(_Tp* __p) _NOEXCEPT { + static_assert(!is_function<_Tp>::value, "_Tp is a function type"); + return __p; } template <class _Pointer, class = void> struct _HasToAddress : false_type {}; template <class _Pointer> -struct _HasToAddress<_Pointer, - decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>())) -> : true_type {}; +struct _HasToAddress<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>())) > + : true_type {}; template <class _Pointer, class = void> struct _HasArrow : false_type {}; template <class _Pointer> -struct _HasArrow<_Pointer, - decltype((void)std::declval<const _Pointer&>().operator->()) -> : true_type {}; +struct _HasArrow<_Pointer, decltype((void)std::declval<const _Pointer&>().operator->()) > : true_type {}; template <class _Pointer> struct _IsFancyPointer { @@ -196,44 +201,42 @@ struct _IsFancyPointer { }; // enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers -template <class _Pointer, class = __enable_if_t< - _And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value -> > -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -__decay_t<decltype(__to_address_helper<_Pointer>::__call(std::declval<const _Pointer&>()))> -__to_address(const _Pointer& __p) _NOEXCEPT { - return __to_address_helper<_Pointer>::__call(__p); +template <class _Pointer, class = __enable_if_t< _And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value > > +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR + __decay_t<decltype(__to_address_helper<_Pointer>::__call(std::declval<const _Pointer&>()))> + __to_address(const _Pointer& __p) _NOEXCEPT { + return __to_address_helper<_Pointer>::__call(__p); } template <class _Pointer, class> struct __to_address_helper { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - static decltype(_VSTD::__to_address(std::declval<const _Pointer&>().operator->())) - __call(const _Pointer& __p) _NOEXCEPT { - return _VSTD::__to_address(__p.operator->()); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static decltype(std::__to_address( + std::declval<const _Pointer&>().operator->())) + __call(const _Pointer& __p) _NOEXCEPT { + return std::__to_address(__p.operator->()); + } }; template <class _Pointer> -struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))> { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - static decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>())) - __call(const _Pointer& __p) _NOEXCEPT { - return pointer_traits<_Pointer>::to_address(__p); - } +struct __to_address_helper<_Pointer, + decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))> { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static decltype(pointer_traits<_Pointer>::to_address( + std::declval<const _Pointer&>())) + __call(const _Pointer& __p) _NOEXCEPT { + return pointer_traits<_Pointer>::to_address(__p); + } }; #if _LIBCPP_STD_VER >= 20 template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY constexpr -auto to_address(_Tp *__p) noexcept { - return _VSTD::__to_address(__p); +inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(_Tp* __p) noexcept { + return std::__to_address(__p); } template <class _Pointer> -inline _LIBCPP_INLINE_VISIBILITY constexpr -auto to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) { - return _VSTD::__to_address(__p); +inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(const _Pointer& __p) noexcept + -> decltype(std::__to_address(__p)) { + return std::__to_address(__p); } #endif diff --git a/lib/libcxx/include/__memory/ranges_construct_at.h b/lib/libcxx/include/__memory/ranges_construct_at.h index ed800f4a75..f731e75e7b 100644 --- a/lib/libcxx/include/__memory/ranges_construct_at.h +++ b/lib/libcxx/include/__memory/ranges_construct_at.h @@ -41,19 +41,16 @@ namespace ranges { namespace __construct_at { struct __fn { - template<class _Tp, class... _Args, class = decltype( - ::new (std::declval<void*>()) _Tp(std::declval<_Args>()...) - )> - _LIBCPP_HIDE_FROM_ABI - constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const { - return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...); + template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))> + _LIBCPP_HIDE_FROM_ABI constexpr _Tp* operator()(_Tp* __location, _Args&&... __args) const { + return std::construct_at(__location, std::forward<_Args>(__args)...); } }; } // namespace __construct_at inline namespace __cpo { - inline constexpr auto construct_at = __construct_at::__fn{}; +inline constexpr auto construct_at = __construct_at::__fn{}; } // namespace __cpo // destroy_at @@ -62,16 +59,15 @@ namespace __destroy_at { struct __fn { template <destructible _Tp> - _LIBCPP_HIDE_FROM_ABI - constexpr void operator()(_Tp* __location) const noexcept { - _VSTD::destroy_at(__location); + _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Tp* __location) const noexcept { + std::destroy_at(__location); } }; } // namespace __destroy_at inline namespace __cpo { - inline constexpr auto destroy_at = __destroy_at::__fn{}; +inline constexpr auto destroy_at = __destroy_at::__fn{}; } // namespace __cpo // destroy @@ -81,15 +77,13 @@ namespace __destroy { struct __fn { template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel> requires destructible<iter_value_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI - constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept { - return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last)); + _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept { + return std::__destroy(std::move(__first), std::move(__last)); } template <__nothrow_input_range _InputRange> requires destructible<range_value_t<_InputRange>> - _LIBCPP_HIDE_FROM_ABI - constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept { + _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept { return (*this)(ranges::begin(__range), ranges::end(__range)); } }; @@ -97,7 +91,7 @@ struct __fn { } // namespace __destroy inline namespace __cpo { - inline constexpr auto destroy = __destroy::__fn{}; +inline constexpr auto destroy = __destroy::__fn{}; } // namespace __cpo // destroy_n @@ -107,16 +101,16 @@ namespace __destroy_n { struct __fn { template <__nothrow_input_iterator _InputIterator> requires destructible<iter_value_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI - constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept { - return _VSTD::destroy_n(_VSTD::move(__first), __n); + _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator + operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept { + return std::destroy_n(std::move(__first), __n); } }; } // namespace __destroy_n inline namespace __cpo { - inline constexpr auto destroy_n = __destroy_n::__fn{}; +inline constexpr auto destroy_n = __destroy_n::__fn{}; } // namespace __cpo } // namespace ranges diff --git a/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h b/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h index 01c3e01003..90090055bb 100644 --- a/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h +++ b/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h @@ -31,6 +31,9 @@ # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 @@ -42,13 +45,11 @@ namespace ranges { namespace __uninitialized_default_construct { struct __fn { - template <__nothrow_forward_iterator _ForwardIterator, - __nothrow_sentinel_for<_ForwardIterator> _Sentinel> + template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel> requires default_initializable<iter_value_t<_ForwardIterator>> _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_default_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); + return std::__uninitialized_default_construct<_ValueType>(std::move(__first), std::move(__last)); } template <__nothrow_forward_range _ForwardRange> @@ -61,7 +62,7 @@ struct __fn { } // namespace __uninitialized_default_construct inline namespace __cpo { - inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{}; +inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{}; } // namespace __cpo // uninitialized_default_construct_n @@ -71,17 +72,17 @@ namespace __uninitialized_default_construct_n { struct __fn { template <__nothrow_forward_iterator _ForwardIterator> requires default_initializable<iter_value_t<_ForwardIterator>> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, - iter_difference_t<_ForwardIterator> __n) const { + _LIBCPP_HIDE_FROM_ABI _ForwardIterator + operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n); + return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n); } }; } // namespace __uninitialized_default_construct_n inline namespace __cpo { - inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{}; +inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{}; } // namespace __cpo // uninitialized_value_construct @@ -89,13 +90,11 @@ inline namespace __cpo { namespace __uninitialized_value_construct { struct __fn { - template <__nothrow_forward_iterator _ForwardIterator, - __nothrow_sentinel_for<_ForwardIterator> _Sentinel> + template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel> requires default_initializable<iter_value_t<_ForwardIterator>> _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_value_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); + return std::__uninitialized_value_construct<_ValueType>(std::move(__first), std::move(__last)); } template <__nothrow_forward_range _ForwardRange> @@ -108,7 +107,7 @@ struct __fn { } // namespace __uninitialized_value_construct inline namespace __cpo { - inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{}; +inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{}; } // namespace __cpo // uninitialized_value_construct_n @@ -118,17 +117,17 @@ namespace __uninitialized_value_construct_n { struct __fn { template <__nothrow_forward_iterator _ForwardIterator> requires default_initializable<iter_value_t<_ForwardIterator>> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, - iter_difference_t<_ForwardIterator> __n) const { + _LIBCPP_HIDE_FROM_ABI _ForwardIterator + operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n); + return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n); } }; } // namespace __uninitialized_value_construct_n inline namespace __cpo { - inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{}; +inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{}; } // namespace __cpo // uninitialized_fill @@ -136,13 +135,11 @@ inline namespace __cpo { namespace __uninitialized_fill { struct __fn { - template <__nothrow_forward_iterator _ForwardIterator, - __nothrow_sentinel_for<_ForwardIterator> _Sentinel, - class _Tp> + template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel, class _Tp> requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&> _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_fill<_ValueType>(_VSTD::move(__first), _VSTD::move(__last), __x); + return std::__uninitialized_fill<_ValueType>(std::move(__first), std::move(__last), __x); } template <__nothrow_forward_range _ForwardRange, class _Tp> @@ -155,7 +152,7 @@ struct __fn { } // namespace __uninitialized_fill inline namespace __cpo { - inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{}; +inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{}; } // namespace __cpo // uninitialized_fill_n @@ -165,18 +162,17 @@ namespace __uninitialized_fill_n { struct __fn { template <__nothrow_forward_iterator _ForwardIterator, class _Tp> requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, - iter_difference_t<_ForwardIterator> __n, - const _Tp& __x) const { + _LIBCPP_HIDE_FROM_ABI _ForwardIterator + operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n, const _Tp& __x) const { using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; - return _VSTD::__uninitialized_fill_n<_ValueType>(_VSTD::move(__first), __n, __x); + return std::__uninitialized_fill_n<_ValueType>(std::move(__first), __n, __x); } }; } // namespace __uninitialized_fill_n inline namespace __cpo { - inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{}; +inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{}; } // namespace __cpo // uninitialized_copy @@ -196,24 +192,25 @@ struct __fn { operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const { using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; - auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), _VSTD::move(__olast)); - return {_VSTD::move(__result.first), _VSTD::move(__result.second)}; + auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; + auto __result = std::__uninitialized_copy<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_copying); + return {std::move(__result.first), std::move(__result.second)}; } template <input_range _InputRange, __nothrow_forward_range _OutputRange> requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>> _LIBCPP_HIDE_FROM_ABI uninitialized_copy_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>> - operator()( _InputRange&& __in_range, _OutputRange&& __out_range) const { - return (*this)(ranges::begin(__in_range), ranges::end(__in_range), - ranges::begin(__out_range), ranges::end(__out_range)); + operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { + return (*this)( + ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range)); } }; } // namespace __uninitialized_copy inline namespace __cpo { - inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{}; +inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{}; } // namespace __cpo // uninitialized_copy_n @@ -225,23 +222,26 @@ namespace __uninitialized_copy_n { struct __fn { template <input_iterator _InputIterator, - __nothrow_forward_iterator _OutputIterator, - __nothrow_sentinel_for<_OutputIterator> _Sentinel> + __nothrow_forward_iterator _OutputIterator, + __nothrow_sentinel_for<_OutputIterator> _Sentinel> requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>> _LIBCPP_HIDE_FROM_ABI uninitialized_copy_n_result<_InputIterator, _OutputIterator> - operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n, - _OutputIterator __ofirst, _Sentinel __olast) const { - using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; - auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n, - _VSTD::move(__ofirst), _VSTD::move(__olast)); - return {_VSTD::move(__result.first), _VSTD::move(__result.second)}; + operator()(_InputIterator __ifirst, + iter_difference_t<_InputIterator> __n, + _OutputIterator __ofirst, + _Sentinel __olast) const { + using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; + auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; + auto __result = + std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __stop_copying); + return {std::move(__result.first), std::move(__result.second)}; } }; } // namespace __uninitialized_copy_n inline namespace __cpo { - inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{}; +inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{}; } // namespace __cpo // uninitialized_move @@ -259,26 +259,27 @@ struct __fn { requires constructible_from<iter_value_t<_OutputIterator>, iter_rvalue_reference_t<_InputIterator>> _LIBCPP_HIDE_FROM_ABI uninitialized_move_result<_InputIterator, _OutputIterator> operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const { - using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; - auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move); - return {_VSTD::move(__result.first), _VSTD::move(__result.second)}; + using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; + auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; + auto __result = std::__uninitialized_move<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_moving, __iter_move); + return {std::move(__result.first), std::move(__result.second)}; } template <input_range _InputRange, __nothrow_forward_range _OutputRange> requires constructible_from<range_value_t<_OutputRange>, range_rvalue_reference_t<_InputRange>> _LIBCPP_HIDE_FROM_ABI uninitialized_move_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>> operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { - return (*this)(ranges::begin(__in_range), ranges::end(__in_range), - ranges::begin(__out_range), ranges::end(__out_range)); + return (*this)( + ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range)); } }; } // namespace __uninitialized_move inline namespace __cpo { - inline constexpr auto uninitialized_move = __uninitialized_move::__fn{}; +inline constexpr auto uninitialized_move = __uninitialized_move::__fn{}; } // namespace __cpo // uninitialized_move_n @@ -290,24 +291,27 @@ namespace __uninitialized_move_n { struct __fn { template <input_iterator _InputIterator, - __nothrow_forward_iterator _OutputIterator, - __nothrow_sentinel_for<_OutputIterator> _Sentinel> + __nothrow_forward_iterator _OutputIterator, + __nothrow_sentinel_for<_OutputIterator> _Sentinel> requires constructible_from<iter_value_t<_OutputIterator>, iter_rvalue_reference_t<_InputIterator>> _LIBCPP_HIDE_FROM_ABI uninitialized_move_n_result<_InputIterator, _OutputIterator> - operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n, - _OutputIterator __ofirst, _Sentinel __olast) const { - using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; - auto __result = _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, - _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move); - return {_VSTD::move(__result.first), _VSTD::move(__result.second)}; + operator()(_InputIterator __ifirst, + iter_difference_t<_InputIterator> __n, + _OutputIterator __ofirst, + _Sentinel __olast) const { + using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; + auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; + auto __result = std::__uninitialized_move_n<_ValueType>( + std::move(__ifirst), __n, std::move(__ofirst), __stop_moving, __iter_move); + return {std::move(__result.first), std::move(__result.second)}; } }; } // namespace __uninitialized_move_n inline namespace __cpo { - inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{}; +inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{}; } // namespace __cpo } // namespace ranges @@ -316,4 +320,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H diff --git a/lib/libcxx/include/__memory/raw_storage_iterator.h b/lib/libcxx/include/__memory/raw_storage_iterator.h index df7ef5afe7..774878aa1c 100644 --- a/lib/libcxx/include/__memory/raw_storage_iterator.h +++ b/lib/libcxx/include/__memory/raw_storage_iterator.h @@ -22,6 +22,9 @@ # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) @@ -29,42 +32,56 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_SUPPRESS_DEPRECATED_PUSH template <class _OutputIterator, class _Tp> class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator -#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) +# if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) : public iterator<output_iterator_tag, void, void, void, void> -#endif +# endif { -_LIBCPP_SUPPRESS_DEPRECATED_POP + _LIBCPP_SUPPRESS_DEPRECATED_POP + private: - _OutputIterator __x_; + _OutputIterator __x_; + public: - typedef output_iterator_tag iterator_category; - typedef void value_type; -#if _LIBCPP_STD_VER >= 20 - typedef ptrdiff_t difference_type; -#else - typedef void difference_type; -#endif - typedef void pointer; - typedef void reference; + typedef output_iterator_tag iterator_category; + typedef void value_type; +# if _LIBCPP_STD_VER >= 20 + typedef ptrdiff_t difference_type; +# else + typedef void difference_type; +# endif + typedef void pointer; + typedef void reference; - _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} - _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} - _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) - {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;} -#if _LIBCPP_STD_VER >= 14 - _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) - {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} -#endif - _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} - _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) - {raw_storage_iterator __t(*this); ++__x_; return __t;} -#if _LIBCPP_STD_VER >= 14 - _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } -#endif + _LIBCPP_HIDE_FROM_ABI explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} + _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator*() { return *this; } + _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator=(const _Tp& __element) { + ::new ((void*)std::addressof(*__x_)) _Tp(__element); + return *this; + } +# if _LIBCPP_STD_VER >= 14 + _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator=(_Tp&& __element) { + ::new ((void*)std::addressof(*__x_)) _Tp(std::move(__element)); + return *this; + } +# endif + _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator++() { + ++__x_; + return *this; + } + _LIBCPP_HIDE_FROM_ABI raw_storage_iterator operator++(int) { + raw_storage_iterator __t(*this); + ++__x_; + return __t; + } +# if _LIBCPP_STD_VER >= 14 + _LIBCPP_HIDE_FROM_ABI _OutputIterator base() const { return __x_; } +# endif }; #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H diff --git a/lib/libcxx/include/__memory/shared_ptr.h b/lib/libcxx/include/__memory/shared_ptr.h index dce44a7b37..e6de615d76 100644 --- a/lib/libcxx/include/__memory/shared_ptr.h +++ b/lib/libcxx/include/__memory/shared_ptr.h @@ -14,9 +14,11 @@ #include <__compare/compare_three_way.h> #include <__compare/ordering.h> #include <__config> +#include <__exception/exception.h> #include <__functional/binary_function.h> #include <__functional/operations.h> #include <__functional/reference_wrapper.h> +#include <__fwd/ostream.h> #include <__iterator/access.h> #include <__memory/addressof.h> #include <__memory/allocation_guard.h> @@ -49,9 +51,7 @@ #include <__utility/swap.h> #include <__verbose_abort> #include <cstddef> -#include <iosfwd> #include <new> -#include <stdexcept> #include <typeinfo> #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) # include <__atomic/memory_order.h> @@ -61,218 +61,183 @@ # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) // should be sufficient for thread safety. // See https://llvm.org/PR22803 -#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ - && defined(__ATOMIC_RELAXED) \ - && defined(__ATOMIC_ACQ_REL) -# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +#if defined(__clang__) && __has_builtin(__atomic_add_fetch) && defined(__ATOMIC_RELAXED) && defined(__ATOMIC_ACQ_REL) +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT #elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT #endif template <class _ValueType> -inline _LIBCPP_INLINE_VISIBILITY -_ValueType __libcpp_relaxed_load(_ValueType const* __value) { -#if !defined(_LIBCPP_HAS_NO_THREADS) && \ - defined(__ATOMIC_RELAXED) && \ +inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_relaxed_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && defined(__ATOMIC_RELAXED) && \ (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) - return __atomic_load_n(__value, __ATOMIC_RELAXED); + return __atomic_load_n(__value, __ATOMIC_RELAXED); #else - return *__value; + return *__value; #endif } template <class _ValueType> -inline _LIBCPP_INLINE_VISIBILITY -_ValueType __libcpp_acquire_load(_ValueType const* __value) { -#if !defined(_LIBCPP_HAS_NO_THREADS) && \ - defined(__ATOMIC_ACQUIRE) && \ +inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && defined(__ATOMIC_ACQUIRE) && \ (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) - return __atomic_load_n(__value, __ATOMIC_ACQUIRE); + return __atomic_load_n(__value, __ATOMIC_ACQUIRE); #else - return *__value; + return *__value; #endif } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _Tp -__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT { #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) - return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); + return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); #else - return __t += 1; + return __t += 1; #endif } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _Tp -__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT -{ +inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT { #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) - return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); + return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); #else - return __t -= 1; + return __t -= 1; #endif } -class _LIBCPP_EXPORTED_FROM_ABI bad_weak_ptr - : public std::exception -{ +class _LIBCPP_EXPORTED_FROM_ABI bad_weak_ptr : public std::exception { public: - _LIBCPP_HIDE_FROM_ABI bad_weak_ptr() _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; - ~bad_weak_ptr() _NOEXCEPT override; - const char* what() const _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI bad_weak_ptr() _NOEXCEPT = default; + _LIBCPP_HIDE_FROM_ABI bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; + _LIBCPP_HIDE_FROM_ABI bad_weak_ptr& operator=(const bad_weak_ptr&) _NOEXCEPT = default; + ~bad_weak_ptr() _NOEXCEPT override; + const char* what() const _NOEXCEPT override; }; -_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY -void __throw_bad_weak_ptr() -{ +_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_weak_ptr() { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - throw bad_weak_ptr(); + throw bad_weak_ptr(); #else - _LIBCPP_VERBOSE_ABORT("bad_weak_ptr was thrown in -fno-exceptions mode"); + _LIBCPP_VERBOSE_ABORT("bad_weak_ptr was thrown in -fno-exceptions mode"); #endif } -template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS weak_ptr; -class _LIBCPP_EXPORTED_FROM_ABI __shared_count -{ - __shared_count(const __shared_count&); - __shared_count& operator=(const __shared_count&); +class _LIBCPP_EXPORTED_FROM_ABI __shared_count { + __shared_count(const __shared_count&); + __shared_count& operator=(const __shared_count&); protected: - long __shared_owners_; - virtual ~__shared_count(); + long __shared_owners_; + virtual ~__shared_count(); + private: - virtual void __on_zero_shared() _NOEXCEPT = 0; + virtual void __on_zero_shared() _NOEXCEPT = 0; public: - _LIBCPP_INLINE_VISIBILITY - explicit __shared_count(long __refs = 0) _NOEXCEPT - : __shared_owners_(__refs) {} + _LIBCPP_HIDE_FROM_ABI explicit __shared_count(long __refs = 0) _NOEXCEPT : __shared_owners_(__refs) {} #if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS) - void __add_shared() noexcept; - bool __release_shared() noexcept; + void __add_shared() noexcept; + bool __release_shared() noexcept; #else - _LIBCPP_INLINE_VISIBILITY - void __add_shared() _NOEXCEPT { - __libcpp_atomic_refcount_increment(__shared_owners_); - } - _LIBCPP_INLINE_VISIBILITY - bool __release_shared() _NOEXCEPT { - if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { - __on_zero_shared(); - return true; - } - return false; + _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_owners_); } + _LIBCPP_HIDE_FROM_ABI bool __release_shared() _NOEXCEPT { + if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { + __on_zero_shared(); + return true; } + return false; + } #endif - _LIBCPP_INLINE_VISIBILITY - long use_count() const _NOEXCEPT { - return __libcpp_relaxed_load(&__shared_owners_) + 1; - } + _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __libcpp_relaxed_load(&__shared_owners_) + 1; } }; -class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count - : private __shared_count -{ - long __shared_weak_owners_; +class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count { + long __shared_weak_owners_; public: - _LIBCPP_INLINE_VISIBILITY - explicit __shared_weak_count(long __refs = 0) _NOEXCEPT - : __shared_count(__refs), - __shared_weak_owners_(__refs) {} + _LIBCPP_HIDE_FROM_ABI explicit __shared_weak_count(long __refs = 0) _NOEXCEPT + : __shared_count(__refs), + __shared_weak_owners_(__refs) {} + protected: - ~__shared_weak_count() override; + ~__shared_weak_count() override; public: #if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS) - void __add_shared() noexcept; - void __add_weak() noexcept; - void __release_shared() noexcept; + void __add_shared() noexcept; + void __add_weak() noexcept; + void __release_shared() noexcept; #else - _LIBCPP_INLINE_VISIBILITY - void __add_shared() _NOEXCEPT { - __shared_count::__add_shared(); - } - _LIBCPP_INLINE_VISIBILITY - void __add_weak() _NOEXCEPT { - __libcpp_atomic_refcount_increment(__shared_weak_owners_); - } - _LIBCPP_INLINE_VISIBILITY - void __release_shared() _NOEXCEPT { - if (__shared_count::__release_shared()) - __release_weak(); - } + _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __shared_count::__add_shared(); } + _LIBCPP_HIDE_FROM_ABI void __add_weak() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_weak_owners_); } + _LIBCPP_HIDE_FROM_ABI void __release_shared() _NOEXCEPT { + if (__shared_count::__release_shared()) + __release_weak(); + } #endif - void __release_weak() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - long use_count() const _NOEXCEPT {return __shared_count::use_count();} - __shared_weak_count* lock() _NOEXCEPT; + void __release_weak() _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __shared_count::use_count(); } + __shared_weak_count* lock() _NOEXCEPT; + + virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; - virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; private: - virtual void __on_zero_shared_weak() _NOEXCEPT = 0; + virtual void __on_zero_shared_weak() _NOEXCEPT = 0; }; template <class _Tp, class _Dp, class _Alloc> -class __shared_ptr_pointer - : public __shared_weak_count -{ - __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; +class __shared_ptr_pointer : public __shared_weak_count { + __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; + public: - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) - : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} + _LIBCPP_HIDE_FROM_ABI __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) + : __data_(__compressed_pair<_Tp, _Dp>(__p, std::move(__d)), std::move(__a)) {} #ifndef _LIBCPP_HAS_NO_RTTI - _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info&) const _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info&) const _NOEXCEPT override; #endif private: - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override; - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override; }; #ifndef _LIBCPP_HAS_NO_RTTI template <class _Tp, class _Dp, class _Alloc> -const void* -__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT -{ - return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; +const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { + return __t == typeid(_Dp) ? std::addressof(__data_.first().second()) : nullptr; } #endif // _LIBCPP_HAS_NO_RTTI template <class _Tp, class _Dp, class _Alloc> -void -__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT -{ - __data_.first().second()(__data_.first().first()); - __data_.first().second().~_Dp(); +void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT { + __data_.first().second()(__data_.first().first()); + __data_.first().second().~_Dp(); } template <class _Tp, class _Dp, class _Alloc> -void -__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT -{ - typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; - typedef allocator_traits<_Al> _ATraits; - typedef pointer_traits<typename _ATraits::pointer> _PTraits; +void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; - _Al __a(__data_.second()); - __data_.second().~_Alloc(); - __a.deallocate(_PTraits::pointer_to(*this), 1); + _Al __a(__data_.second()); + __data_.second().~_Alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); } // This tag is used to instantiate an allocator type. The various shared_ptr control blocks @@ -281,108 +246,99 @@ __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT struct __for_overwrite_tag {}; template <class _Tp, class _Alloc> -struct __shared_ptr_emplace - : __shared_weak_count -{ - template<class ..._Args> - _LIBCPP_HIDE_FROM_ABI - explicit __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) - : __storage_(_VSTD::move(__a)) - { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - static_assert(sizeof...(_Args) == 0, "No argument should be provided to the control block when using _for_overwrite"); - ::new ((void*)__get_elem()) _Tp; - } else { - using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type; - _TpAlloc __tmp(*__get_alloc()); - allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), _VSTD::forward<_Args>(__args)...); - } -#else - ::new ((void*)__get_elem()) _Tp(_VSTD::forward<_Args>(__args)...); -#endif - } - - _LIBCPP_HIDE_FROM_ABI - _Alloc* __get_alloc() _NOEXCEPT { return __storage_.__get_alloc(); } - - _LIBCPP_HIDE_FROM_ABI - _Tp* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); } +struct __shared_ptr_emplace : __shared_weak_count { + template <class... _Args, + class _Allocator = _Alloc, + __enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&...) : __storage_(std::move(__a)) { + static_assert( + sizeof...(_Args) == 0, "No argument should be provided to the control block when using _for_overwrite"); + ::new ((void*)__get_elem()) _Tp; + } + + template <class... _Args, + class _Allocator = _Alloc, + __enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __storage_(std::move(__a)) { + using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type; + _TpAlloc __tmp(*__get_alloc()); + allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), std::forward<_Args>(__args)...); + } + + _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { return __storage_.__get_alloc(); } + + _LIBCPP_HIDE_FROM_ABI _Tp* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); } private: - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - __get_elem()->~_Tp(); - } else { - using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type; - _TpAlloc __tmp(*__get_alloc()); - allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem()); - } -#else - __get_elem()->~_Tp(); -#endif + template <class _Allocator = _Alloc, + __enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT { + __get_elem()->~_Tp(); + } + + template <class _Allocator = _Alloc, + __enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT { + using _TpAlloc = typename __allocator_traits_rebind<_Allocator, _Tp>::type; + _TpAlloc __tmp(*__get_alloc()); + allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem()); + } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { __on_zero_shared_impl(); } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { + using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type; + using _ControlBlockPointer = typename allocator_traits<_ControlBlockAlloc>::pointer; + _ControlBlockAlloc __tmp(*__get_alloc()); + __storage_.~_Storage(); + allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, pointer_traits<_ControlBlockPointer>::pointer_to(*this), 1); + } + + // This class implements the control block for non-array shared pointers created + // through `std::allocate_shared` and `std::make_shared`. + // + // In previous versions of the library, we used a compressed pair to store + // both the _Alloc and the _Tp. This implies using EBO, which is incompatible + // with Allocator construction for _Tp. To allow implementing P0674 in C++20, + // we now use a properly aligned char buffer while making sure that we maintain + // the same layout that we had when we used a compressed pair. + using _CompressedPair = __compressed_pair<_Alloc, _Tp>; + struct _ALIGNAS_TYPE(_CompressedPair) _Storage { + char __blob_[sizeof(_CompressedPair)]; + + _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) { ::new ((void*)__get_alloc()) _Alloc(std::move(__a)); } + _LIBCPP_HIDE_FROM_ABI ~_Storage() { __get_alloc()->~_Alloc(); } + _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { + _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_); + typename _CompressedPair::_Base1* __first = _CompressedPair::__get_first_base(__as_pair); + _Alloc* __alloc = reinterpret_cast<_Alloc*>(__first); + return __alloc; } - - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { - using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type; - using _ControlBlockPointer = typename allocator_traits<_ControlBlockAlloc>::pointer; - _ControlBlockAlloc __tmp(*__get_alloc()); - __storage_.~_Storage(); - allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, - pointer_traits<_ControlBlockPointer>::pointer_to(*this), 1); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT { + _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_); + typename _CompressedPair::_Base2* __second = _CompressedPair::__get_second_base(__as_pair); + _Tp* __elem = reinterpret_cast<_Tp*>(__second); + return __elem; } + }; - // This class implements the control block for non-array shared pointers created - // through `std::allocate_shared` and `std::make_shared`. - // - // In previous versions of the library, we used a compressed pair to store - // both the _Alloc and the _Tp. This implies using EBO, which is incompatible - // with Allocator construction for _Tp. To allow implementing P0674 in C++20, - // we now use a properly aligned char buffer while making sure that we maintain - // the same layout that we had when we used a compressed pair. - using _CompressedPair = __compressed_pair<_Alloc, _Tp>; - struct _ALIGNAS_TYPE(_CompressedPair) _Storage { - char __blob_[sizeof(_CompressedPair)]; - - _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) { - ::new ((void*)__get_alloc()) _Alloc(_VSTD::move(__a)); - } - _LIBCPP_HIDE_FROM_ABI ~_Storage() { - __get_alloc()->~_Alloc(); - } - _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { - _CompressedPair *__as_pair = reinterpret_cast<_CompressedPair*>(__blob_); - typename _CompressedPair::_Base1* __first = _CompressedPair::__get_first_base(__as_pair); - _Alloc *__alloc = reinterpret_cast<_Alloc*>(__first); - return __alloc; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT { - _CompressedPair *__as_pair = reinterpret_cast<_CompressedPair*>(__blob_); - typename _CompressedPair::_Base2* __second = _CompressedPair::__get_second_base(__as_pair); - _Tp *__elem = reinterpret_cast<_Tp*>(__second); - return __elem; - } - }; - - static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), ""); - static_assert(sizeof(_Storage) == sizeof(_CompressedPair), ""); - _Storage __storage_; + static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), ""); + static_assert(sizeof(_Storage) == sizeof(_CompressedPair), ""); + _Storage __storage_; }; struct __shared_ptr_dummy_rebind_allocator_type; template <> -class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> -{ +class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> { public: - template <class _Other> - struct rebind - { - typedef allocator<_Other> other; - }; + template <class _Other> + struct rebind { + typedef allocator<_Other> other; + }; }; -template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; // http://eel.is/c++draft/util.sharedptr#util.smartptr.shared.general-6 // A pointer type Y* is said to be compatible with a pointer type T* @@ -392,19 +348,13 @@ template <class _Yp, class _Tp> struct __bounded_convertible_to_unbounded : false_type {}; template <class _Up, std::size_t _Np, class _Tp> -struct __bounded_convertible_to_unbounded<_Up[_Np], _Tp> - : is_same<__remove_cv_t<_Tp>, _Up[]> {}; +struct __bounded_convertible_to_unbounded<_Up[_Np], _Tp> : is_same<__remove_cv_t<_Tp>, _Up[]> {}; template <class _Yp, class _Tp> -struct __compatible_with - : _Or< - is_convertible<_Yp*, _Tp*>, - __bounded_convertible_to_unbounded<_Yp, _Tp> - > {}; +struct __compatible_with : _Or< is_convertible<_Yp*, _Tp*>, __bounded_convertible_to_unbounded<_Yp, _Tp> > {}; #else template <class _Yp, class _Tp> -struct __compatible_with - : is_convertible<_Yp*, _Tp*> {}; +struct __compatible_with : is_convertible<_Yp*, _Tp*> {}; #endif // _LIBCPP_STD_VER >= 17 // Constructors that take raw pointers have a different set of "compatible" constraints @@ -414,40 +364,32 @@ struct __compatible_with // - If T is not an array type, then Y* is convertible to T*. #if _LIBCPP_STD_VER >= 17 template <class _Yp, class _Tp, class = void> -struct __raw_pointer_compatible_with : _And< - _Not<is_array<_Tp>>, - is_convertible<_Yp*, _Tp*> - > {}; +struct __raw_pointer_compatible_with : _And< _Not<is_array<_Tp>>, is_convertible<_Yp*, _Tp*> > {}; template <class _Yp, class _Up, std::size_t _Np> -struct __raw_pointer_compatible_with<_Yp, _Up[_Np], __enable_if_t< - is_convertible<_Yp(*)[_Np], _Up(*)[_Np]>::value> > - : true_type {}; +struct __raw_pointer_compatible_with<_Yp, _Up[_Np], __enable_if_t< is_convertible<_Yp (*)[_Np], _Up (*)[_Np]>::value> > + : true_type {}; template <class _Yp, class _Up> -struct __raw_pointer_compatible_with<_Yp, _Up[], __enable_if_t< - is_convertible<_Yp(*)[], _Up(*)[]>::value> > - : true_type {}; +struct __raw_pointer_compatible_with<_Yp, _Up[], __enable_if_t< is_convertible<_Yp (*)[], _Up (*)[]>::value> > + : true_type {}; #else template <class _Yp, class _Tp> -struct __raw_pointer_compatible_with - : is_convertible<_Yp*, _Tp*> {}; +struct __raw_pointer_compatible_with : is_convertible<_Yp*, _Tp*> {}; #endif // _LIBCPP_STD_VER >= 17 - template <class _Ptr, class = void> -struct __is_deletable : false_type { }; +struct __is_deletable : false_type {}; template <class _Ptr> -struct __is_deletable<_Ptr, decltype(delete std::declval<_Ptr>())> : true_type { }; +struct __is_deletable<_Ptr, decltype(delete std::declval<_Ptr>())> : true_type {}; template <class _Ptr, class = void> -struct __is_array_deletable : false_type { }; +struct __is_array_deletable : false_type {}; template <class _Ptr> -struct __is_array_deletable<_Ptr, decltype(delete[] std::declval<_Ptr>())> : true_type { }; +struct __is_array_deletable<_Ptr, decltype(delete[] std::declval<_Ptr>())> : true_type {}; -template <class _Dp, class _Pt, - class = decltype(std::declval<_Dp>()(std::declval<_Pt>()))> +template <class _Dp, class _Pt, class = decltype(std::declval<_Dp>()(std::declval<_Pt>()))> true_type __well_formed_deleter_test(int); template <class, class> @@ -456,12 +398,10 @@ false_type __well_formed_deleter_test(...); template <class _Dp, class _Pt> struct __well_formed_deleter : decltype(std::__well_formed_deleter_test<_Dp, _Pt>(0)) {}; -template<class _Dp, class _Yp, class _Tp> -struct __shared_ptr_deleter_ctor_reqs -{ - static const bool value = __raw_pointer_compatible_with<_Yp, _Tp>::value && - is_move_constructible<_Dp>::value && - __well_formed_deleter<_Dp, _Yp*>::value; +template <class _Dp, class _Yp, class _Tp> +struct __shared_ptr_deleter_ctor_reqs { + static const bool value = __raw_pointer_compatible_with<_Yp, _Tp>::value && is_move_constructible<_Dp>::value && + __well_formed_deleter<_Dp, _Yp*>::value; }; #if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI) @@ -470,583 +410,439 @@ struct __shared_ptr_deleter_ctor_reqs # define _LIBCPP_SHARED_PTR_TRIVIAL_ABI #endif -template<class _Tp> -class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr -{ +template <class _Tp> +class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr { public: #if _LIBCPP_STD_VER >= 17 - typedef weak_ptr<_Tp> weak_type; - typedef remove_extent_t<_Tp> element_type; + typedef weak_ptr<_Tp> weak_type; + typedef remove_extent_t<_Tp> element_type; #else - typedef _Tp element_type; + typedef _Tp element_type; #endif private: - element_type* __ptr_; - __shared_weak_count* __cntrl_; + element_type* __ptr_; + __shared_weak_count* __cntrl_; public: - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT - : __ptr_(nullptr), - __cntrl_(nullptr) - { } - - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT - : __ptr_(nullptr), - __cntrl_(nullptr) - { } - - template<class _Yp, class = __enable_if_t< - _And< - __raw_pointer_compatible_with<_Yp, _Tp> - // In C++03 we get errors when trying to do SFINAE with the - // delete operator, so we always pretend that it's deletable. - // The same happens on GCC. + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} + + template <class _Yp, + class = __enable_if_t< _And< __raw_pointer_compatible_with<_Yp, _Tp> + // In C++03 we get errors when trying to do SFINAE with the + // delete operator, so we always pretend that it's deletable. + // The same happens on GCC. #if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_COMPILER_GCC) - , _If<is_array<_Tp>::value, __is_array_deletable<_Yp*>, __is_deletable<_Yp*> > + , + _If<is_array<_Tp>::value, __is_array_deletable<_Yp*>, __is_deletable<_Yp*> > #endif - >::value - > > - _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(_Yp* __p) : __ptr_(__p) { - unique_ptr<_Yp> __hold(__p); - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT> _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT()); - __hold.release(); - __enable_weak_this(__p, __p); - } - - template<class _Yp, class _Dp, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(_Yp* __p, _Dp __d) - : __ptr_(__p) - { + >::value > > + _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(_Yp* __p) : __ptr_(__p) { + unique_ptr<_Yp> __hold(__p); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT> _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT()); + __hold.release(); + __enable_weak_this(__p, __p); + } + + template <class _Yp, class _Dp, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif // _LIBCPP_HAS_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk; + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk; #ifndef _LIBCPP_CXX03_LANG - __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT()); + __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); #else - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); #endif // not _LIBCPP_CXX03_LANG - __enable_weak_this(__p, __p); + __enable_weak_this(__p, __p); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + __d(__p); + throw; } +#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } - template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) - : __ptr_(__p) - { + template <class _Yp, + class _Dp, + class _Alloc, + class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif // _LIBCPP_HAS_NO_EXCEPTIONS - typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new ((void*)_VSTD::addressof(*__hold2.get())) + typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new ((void*)std::addressof(*__hold2.get())) #ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, _VSTD::move(__d), __a); + _CntrlBlk(__p, std::move(__d), __a); #else - _CntrlBlk(__p, __d, __a); + _CntrlBlk(__p, __d, __a); #endif // not _LIBCPP_CXX03_LANG - __cntrl_ = _VSTD::addressof(*__hold2.release()); - __enable_weak_this(__p, __p); + __cntrl_ = std::addressof(*__hold2.release()); + __enable_weak_this(__p, __p); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + __d(__p); + throw; } +#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } - template<class _Dp> - _LIBCPP_HIDE_FROM_ABI - shared_ptr(nullptr_t __p, _Dp __d) - : __ptr_(nullptr) - { + template <class _Dp> + _LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d) : __ptr_(nullptr) { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif // _LIBCPP_HAS_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; - typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk; + typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; + typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk; #ifndef _LIBCPP_CXX03_LANG - __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT()); + __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); #else - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); #endif // not _LIBCPP_CXX03_LANG #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + __d(__p); + throw; } +#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } - template<class _Dp, class _Alloc> - _LIBCPP_HIDE_FROM_ABI - shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) - : __ptr_(nullptr) - { + template <class _Dp, class _Alloc> + _LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) : __ptr_(nullptr) { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif // _LIBCPP_HAS_NO_EXCEPTIONS - typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new ((void*)_VSTD::addressof(*__hold2.get())) + typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new ((void*)std::addressof(*__hold2.get())) #ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, _VSTD::move(__d), __a); + _CntrlBlk(__p, std::move(__d), __a); #else - _CntrlBlk(__p, __d, __a); + _CntrlBlk(__p, __d, __a); #endif // not _LIBCPP_CXX03_LANG - __cntrl_ = _VSTD::addressof(*__hold2.release()); + __cntrl_ = std::addressof(*__hold2.release()); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + __d(__p); + throw; } +#endif // _LIBCPP_HAS_NO_EXCEPTIONS + } - template<class _Yp> - _LIBCPP_HIDE_FROM_ABI - shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT - : __ptr_(__p), - __cntrl_(__r.__cntrl_) - { - if (__cntrl_) - __cntrl_->__add_shared(); - } + template <class _Yp> + _LIBCPP_HIDE_FROM_ABI shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT + : __ptr_(__p), + __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_shared(); + } // LWG-2996 // We don't backport because it is an evolutionary change. #if _LIBCPP_STD_VER >= 20 - template <class _Yp> - _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr<_Yp>&& __r, element_type* __p) noexcept - : __ptr_(__p), - __cntrl_(__r.__cntrl_) { - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; - } + template <class _Yp> + _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr<_Yp>&& __r, element_type* __p) noexcept + : __ptr_(__p), __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; + } #endif - _LIBCPP_HIDE_FROM_ABI - shared_ptr(const shared_ptr& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) - { - if (__cntrl_) - __cntrl_->__add_shared(); - } + _LIBCPP_HIDE_FROM_ABI shared_ptr(const shared_ptr& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_shared(); + } - template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(const shared_ptr<_Yp>& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) - { - if (__cntrl_) - __cntrl_->__add_shared(); - } + template <class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr(const shared_ptr<_Yp>& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_shared(); + } - _LIBCPP_HIDE_FROM_ABI - shared_ptr(shared_ptr&& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) - { - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; - } + _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; + } - template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(shared_ptr<_Yp>&& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) - { - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; - } + template <class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr<_Yp>&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; + } - template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - explicit shared_ptr(const weak_ptr<_Yp>& __r) - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) - { - if (__cntrl_ == nullptr) - __throw_bad_weak_ptr(); - } + template <class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(const weak_ptr<_Yp>& __r) + : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) { + if (__cntrl_ == nullptr) + __throw_bad_weak_ptr(); + } #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template<class _Yp, class = __enable_if_t<is_convertible<_Yp*, element_type*>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(auto_ptr<_Yp>&& __r) - : __ptr_(__r.get()) - { - typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); - __enable_weak_this(__r.get(), __r.get()); - __r.release(); - } + template <class _Yp, class = __enable_if_t<is_convertible<_Yp*, element_type*>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr(auto_ptr<_Yp>&& __r) : __ptr_(__r.get()) { + typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); + __enable_weak_this(__r.get(), __r.get()); + __r.release(); + } #endif - template <class _Yp, class _Dp, class = __enable_if_t< - !is_lvalue_reference<_Dp>::value && - __compatible_with<_Yp, _Tp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - > > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(unique_ptr<_Yp, _Dp>&& __r) - : __ptr_(__r.get()) - { + template <class _Yp, + class _Dp, + class = __enable_if_t< !is_lvalue_reference<_Dp>::value && __compatible_with<_Yp, _Tp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value > > + _LIBCPP_HIDE_FROM_ABI shared_ptr(unique_ptr<_Yp, _Dp>&& __r) : __ptr_(__r.get()) { #if _LIBCPP_STD_VER >= 14 - if (__ptr_ == nullptr) - __cntrl_ = nullptr; - else + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else #endif - { - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT> _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), std::move(__r.get_deleter()), _AllocT()); - __enable_weak_this(__r.get(), __r.get()); - } - __r.release(); - } - - template <class _Yp, class _Dp, class = void, class = __enable_if_t< - is_lvalue_reference<_Dp>::value && - __compatible_with<_Yp, _Tp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - > > - _LIBCPP_HIDE_FROM_ABI - shared_ptr(unique_ptr<_Yp, _Dp>&& __r) - : __ptr_(__r.get()) { + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT> _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), std::move(__r.get_deleter()), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); + } + __r.release(); + } + + template <class _Yp, + class _Dp, + class = void, + class = __enable_if_t< is_lvalue_reference<_Dp>::value && __compatible_with<_Yp, _Tp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value > > + _LIBCPP_HIDE_FROM_ABI shared_ptr(unique_ptr<_Yp, _Dp>&& __r) : __ptr_(__r.get()) { #if _LIBCPP_STD_VER >= 14 - if (__ptr_ == nullptr) - __cntrl_ = nullptr; - else + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else #endif - { - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, - reference_wrapper<__libcpp_remove_reference_t<_Dp> >, - _AllocT> _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); - __enable_weak_this(__r.get(), __r.get()); - } - __r.release(); - } - - _LIBCPP_HIDE_FROM_ABI - ~shared_ptr() { - if (__cntrl_) - __cntrl_->__release_shared(); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, + reference_wrapper<__libcpp_remove_reference_t<_Dp> >, + _AllocT> + _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), std::ref(__r.get_deleter()), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); } + __r.release(); + } - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(const shared_ptr& __r) _NOEXCEPT - { - shared_ptr(__r).swap(*this); - return *this; - } + _LIBCPP_HIDE_FROM_ABI ~shared_ptr() { + if (__cntrl_) + __cntrl_->__release_shared(); + } - template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT - { - shared_ptr(__r).swap(*this); - return *this; - } + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(const shared_ptr& __r) _NOEXCEPT { + shared_ptr(__r).swap(*this); + return *this; + } - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(shared_ptr&& __r) _NOEXCEPT - { - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; - } + template <class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT { + shared_ptr(__r).swap(*this); + return *this; + } - template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(shared_ptr<_Yp>&& __r) - { - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; - } + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(shared_ptr&& __r) _NOEXCEPT { + shared_ptr(std::move(__r)).swap(*this); + return *this; + } + + template <class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(shared_ptr<_Yp>&& __r) { + shared_ptr(std::move(__r)).swap(*this); + return *this; + } #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template<class _Yp, class = __enable_if_t< - !is_array<_Yp>::value && - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value - > > - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(auto_ptr<_Yp>&& __r) - { - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; - } + template <class _Yp, + class = __enable_if_t< !is_array<_Yp>::value && + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value > > + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(auto_ptr<_Yp>&& __r) { + shared_ptr(std::move(__r)).swap(*this); + return *this; + } #endif - template <class _Yp, class _Dp, class = __enable_if_t<_And< - __compatible_with<_Yp, _Tp>, - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*> - >::value> > - _LIBCPP_HIDE_FROM_ABI - shared_ptr<_Tp>& operator=(unique_ptr<_Yp, _Dp>&& __r) - { - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; - } + template < + class _Yp, + class _Dp, + class = __enable_if_t<_And< __compatible_with<_Yp, _Tp>, + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*> >::value> > + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(unique_ptr<_Yp, _Dp>&& __r) { + shared_ptr(std::move(__r)).swap(*this); + return *this; + } - _LIBCPP_HIDE_FROM_ABI - void swap(shared_ptr& __r) _NOEXCEPT - { - _VSTD::swap(__ptr_, __r.__ptr_); - _VSTD::swap(__cntrl_, __r.__cntrl_); - } + _LIBCPP_HIDE_FROM_ABI void swap(shared_ptr& __r) _NOEXCEPT { + std::swap(__ptr_, __r.__ptr_); + std::swap(__cntrl_, __r.__cntrl_); + } - _LIBCPP_HIDE_FROM_ABI - void reset() _NOEXCEPT - { - shared_ptr().swap(*this); - } + _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT { shared_ptr().swap(*this); } - template<class _Yp, class = __enable_if_t< - __raw_pointer_compatible_with<_Yp, _Tp>::value - > > - _LIBCPP_HIDE_FROM_ABI - void reset(_Yp* __p) - { - shared_ptr(__p).swap(*this); - } + template <class _Yp, class = __enable_if_t< __raw_pointer_compatible_with<_Yp, _Tp>::value > > + _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p) { + shared_ptr(__p).swap(*this); + } - template<class _Yp, class _Dp, class = __enable_if_t< - __shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - void reset(_Yp* __p, _Dp __d) - { - shared_ptr(__p, __d).swap(*this); - } + template <class _Yp, class _Dp, class = __enable_if_t< __shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p, _Dp __d) { + shared_ptr(__p, __d).swap(*this); + } - template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t< - __shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > - _LIBCPP_HIDE_FROM_ABI - void reset(_Yp* __p, _Dp __d, _Alloc __a) - { - shared_ptr(__p, __d, __a).swap(*this); - } + template <class _Yp, + class _Dp, + class _Alloc, + class = __enable_if_t< __shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value> > + _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p, _Dp __d, _Alloc __a) { + shared_ptr(__p, __d, __a).swap(*this); + } - _LIBCPP_HIDE_FROM_ABI - element_type* get() const _NOEXCEPT - { - return __ptr_; - } + _LIBCPP_HIDE_FROM_ABI element_type* get() const _NOEXCEPT { return __ptr_; } - _LIBCPP_HIDE_FROM_ABI - __add_lvalue_reference_t<element_type> operator*() const _NOEXCEPT - { - return *__ptr_; - } + _LIBCPP_HIDE_FROM_ABI __add_lvalue_reference_t<element_type> operator*() const _NOEXCEPT { return *__ptr_; } - _LIBCPP_HIDE_FROM_ABI - element_type* operator->() const _NOEXCEPT - { - static_assert(!is_array<_Tp>::value, - "std::shared_ptr<T>::operator-> is only valid when T is not an array type."); - return __ptr_; - } + _LIBCPP_HIDE_FROM_ABI element_type* operator->() const _NOEXCEPT { + static_assert(!is_array<_Tp>::value, "std::shared_ptr<T>::operator-> is only valid when T is not an array type."); + return __ptr_; + } - _LIBCPP_HIDE_FROM_ABI - long use_count() const _NOEXCEPT - { - return __cntrl_ ? __cntrl_->use_count() : 0; - } + _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __cntrl_ ? __cntrl_->use_count() : 0; } - _LIBCPP_HIDE_FROM_ABI - bool unique() const _NOEXCEPT - { - return use_count() == 1; - } +#if _LIBCPP_STD_VER < 20 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE) + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; } +#endif - _LIBCPP_HIDE_FROM_ABI - explicit operator bool() const _NOEXCEPT - { - return get() != nullptr; - } + _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return get() != nullptr; } - template <class _Up> - _LIBCPP_HIDE_FROM_ABI - bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT - { - return __cntrl_ < __p.__cntrl_; - } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT { + return __cntrl_ < __p.__cntrl_; + } - template <class _Up> - _LIBCPP_HIDE_FROM_ABI - bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT - { - return __cntrl_ < __p.__cntrl_; - } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT { + return __cntrl_ < __p.__cntrl_; + } - _LIBCPP_HIDE_FROM_ABI - bool __owner_equivalent(const shared_ptr& __p) const - { - return __cntrl_ == __p.__cntrl_; - } + _LIBCPP_HIDE_FROM_ABI bool __owner_equivalent(const shared_ptr& __p) const { return __cntrl_ == __p.__cntrl_; } #if _LIBCPP_STD_VER >= 17 - _LIBCPP_HIDE_FROM_ABI - __add_lvalue_reference_t<element_type> operator[](ptrdiff_t __i) const - { - static_assert(is_array<_Tp>::value, - "std::shared_ptr<T>::operator[] is only valid when T is an array type."); - return __ptr_[__i]; - } + _LIBCPP_HIDE_FROM_ABI __add_lvalue_reference_t<element_type> operator[](ptrdiff_t __i) const { + static_assert(is_array<_Tp>::value, "std::shared_ptr<T>::operator[] is only valid when T is an array type."); + return __ptr_[__i]; + } #endif #ifndef _LIBCPP_HAS_NO_RTTI - template <class _Dp> - _LIBCPP_HIDE_FROM_ABI - _Dp* __get_deleter() const _NOEXCEPT - { - return static_cast<_Dp*>(__cntrl_ - ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) - : nullptr); - } + template <class _Dp> + _LIBCPP_HIDE_FROM_ABI _Dp* __get_deleter() const _NOEXCEPT { + return static_cast<_Dp*>(__cntrl_ ? const_cast<void*>(__cntrl_->__get_deleter(typeid(_Dp))) : nullptr); + } #endif // _LIBCPP_HAS_NO_RTTI - template<class _Yp, class _CntrlBlk> - _LIBCPP_HIDE_FROM_ABI - static shared_ptr<_Tp> __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT - { - shared_ptr<_Tp> __r; - __r.__ptr_ = __p; - __r.__cntrl_ = __cntrl; - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; - } + template <class _Yp, class _CntrlBlk> + _LIBCPP_HIDE_FROM_ABI static shared_ptr<_Tp> __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT { + shared_ptr<_Tp> __r; + __r.__ptr_ = __p; + __r.__cntrl_ = __cntrl; + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; + } private: - template <class _Yp, bool = is_function<_Yp>::value> - struct __shared_ptr_default_allocator - { - typedef allocator<_Yp> type; - }; - - template <class _Yp> - struct __shared_ptr_default_allocator<_Yp, true> - { - typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; - }; - - template <class _Yp, class _OrigPtr, class = __enable_if_t< - is_convertible<_OrigPtr*, const enable_shared_from_this<_Yp>*>::value - > > - _LIBCPP_HIDE_FROM_ABI - void __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT - { - typedef __remove_cv_t<_Yp> _RawYp; - if (__e && __e->__weak_this_.expired()) - { - __e->__weak_this_ = shared_ptr<_RawYp>(*this, - const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); - } + template <class _Yp, bool = is_function<_Yp>::value> + struct __shared_ptr_default_allocator { + typedef allocator<_Yp> type; + }; + + template <class _Yp> + struct __shared_ptr_default_allocator<_Yp, true> { + typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; + }; + + template <class _Yp, + class _OrigPtr, + class = __enable_if_t< is_convertible<_OrigPtr*, const enable_shared_from_this<_Yp>*>::value > > + _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT { + typedef __remove_cv_t<_Yp> _RawYp; + if (__e && __e->__weak_this_.expired()) { + __e->__weak_this_ = shared_ptr<_RawYp>(*this, const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); } + } - _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(...) _NOEXCEPT { } + _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(...) _NOEXCEPT {} - template <class, class _Yp> - struct __shared_ptr_default_delete - : default_delete<_Yp> - { }; + template <class, class _Yp> + struct __shared_ptr_default_delete : default_delete<_Yp> {}; - template <class _Yp, class _Un, size_t _Sz> - struct __shared_ptr_default_delete<_Yp[_Sz], _Un> - : default_delete<_Yp[]> - { }; + template <class _Yp, class _Un, size_t _Sz> + struct __shared_ptr_default_delete<_Yp[_Sz], _Un> : default_delete<_Yp[]> {}; - template <class _Yp, class _Un> - struct __shared_ptr_default_delete<_Yp[], _Un> - : default_delete<_Yp[]> - { }; + template <class _Yp, class _Un> + struct __shared_ptr_default_delete<_Yp[], _Un> : default_delete<_Yp[]> {}; - template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; - template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + template <class _Up> + friend class _LIBCPP_TEMPLATE_VIS shared_ptr; + template <class _Up> + friend class _LIBCPP_TEMPLATE_VIS weak_ptr; }; #if _LIBCPP_STD_VER >= 17 -template<class _Tp> +template <class _Tp> shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; -template<class _Tp, class _Dp> +template <class _Tp, class _Dp> shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; #endif // // std::allocate_shared and std::make_shared // -template<class _Tp, class _Alloc, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> > -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args) -{ - using _ControlBlock = __shared_ptr_emplace<_Tp, _Alloc>; - using _ControlBlockAllocator = typename __allocator_traits_rebind<_Alloc, _ControlBlock>::type; - __allocation_guard<_ControlBlockAllocator> __guard(__a, 1); - ::new ((void*)_VSTD::addressof(*__guard.__get())) _ControlBlock(__a, _VSTD::forward<_Args>(__args)...); - auto __control_block = __guard.__release_ptr(); - return shared_ptr<_Tp>::__create_with_control_block((*__control_block).__get_elem(), _VSTD::addressof(*__control_block)); +template <class _Tp, class _Alloc, class... _Args, class = __enable_if_t<!is_array<_Tp>::value> > +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&... __args) { + using _ControlBlock = __shared_ptr_emplace<_Tp, _Alloc>; + using _ControlBlockAllocator = typename __allocator_traits_rebind<_Alloc, _ControlBlock>::type; + __allocation_guard<_ControlBlockAllocator> __guard(__a, 1); + ::new ((void*)std::addressof(*__guard.__get())) _ControlBlock(__a, std::forward<_Args>(__args)...); + auto __control_block = __guard.__release_ptr(); + return shared_ptr<_Tp>::__create_with_control_block( + (*__control_block).__get_elem(), std::addressof(*__control_block)); } -template<class _Tp, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> > -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared(_Args&& ...__args) -{ - return _VSTD::allocate_shared<_Tp>(allocator<_Tp>(), _VSTD::forward<_Args>(__args)...); +template <class _Tp, class... _Args, class = __enable_if_t<!is_array<_Tp>::value> > +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared(_Args&&... __args) { + return std::allocate_shared<_Tp>(allocator<_Tp>(), std::forward<_Args>(__args)...); } #if _LIBCPP_STD_VER >= 20 -template<class _Tp, class _Alloc, __enable_if_t<!is_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a) -{ - using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; - _ForOverwriteAllocator __alloc(__a); - return std::allocate_shared<_Tp>(__alloc); +template <class _Tp, class _Alloc, __enable_if_t<!is_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a) { + using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; + _ForOverwriteAllocator __alloc(__a); + return std::allocate_shared<_Tp>(__alloc); } -template<class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared_for_overwrite() -{ - return std::allocate_shared_for_overwrite<_Tp>(allocator<_Tp>()); +template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared_for_overwrite() { + return std::allocate_shared_for_overwrite<_Tp>(allocator<_Tp>()); } #endif // _LIBCPP_STD_VER >= 20 @@ -1055,190 +851,180 @@ shared_ptr<_Tp> make_shared_for_overwrite() template <size_t _Alignment> struct __sp_aligned_storage { - alignas(_Alignment) char __storage[_Alignment]; + alignas(_Alignment) char __storage[_Alignment]; }; template <class _Tp, class _Alloc> struct __unbounded_array_control_block; template <class _Tp, class _Alloc> -struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count -{ - _LIBCPP_HIDE_FROM_ABI constexpr - _Tp* __get_data() noexcept { return __data_; } - - _LIBCPP_HIDE_FROM_ABI - explicit __unbounded_array_control_block(_Alloc const& __alloc, size_t __count, _Tp const& __arg) - : __alloc_(__alloc), __count_(__count) - { - std::__uninitialized_allocator_fill_n_multidimensional(__alloc_, std::begin(__data_), __count_, __arg); - } - - _LIBCPP_HIDE_FROM_ABI - explicit __unbounded_array_control_block(_Alloc const& __alloc, size_t __count) - : __alloc_(__alloc), __count_(__count) - { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - // We are purposefully not using an allocator-aware default construction because the spec says so. - // There's currently no way of expressing default initialization in an allocator-aware manner anyway. - std::uninitialized_default_construct_n(std::begin(__data_), __count_); - } else { - std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::begin(__data_), __count_); - } -#else - std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::begin(__data_), __count_); -#endif - } - - // Returns the number of bytes required to store a control block followed by the given number - // of elements of _Tp, with the whole storage being aligned to a multiple of _Tp's alignment. - _LIBCPP_HIDE_FROM_ABI - static constexpr size_t __bytes_for(size_t __elements) { - // When there's 0 elements, the control block alone is enough since it holds one element. - // Otherwise, we allocate one fewer element than requested because the control block already - // holds one. Also, we use the bitwise formula below to ensure that we allocate enough bytes - // for the whole allocation to be a multiple of _Tp's alignment. That formula is taken from [1]. - // - // [1]: https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding - size_t __bytes = __elements == 0 ? sizeof(__unbounded_array_control_block) - : (__elements - 1) * sizeof(_Tp) + sizeof(__unbounded_array_control_block); - constexpr size_t __align = alignof(_Tp); - return (__bytes + __align - 1) & ~(__align - 1); +struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count { + _LIBCPP_HIDE_FROM_ABI constexpr _Tp* __get_data() noexcept { return __data_; } + + _LIBCPP_HIDE_FROM_ABI explicit __unbounded_array_control_block( + _Alloc const& __alloc, size_t __count, _Tp const& __arg) + : __alloc_(__alloc), __count_(__count) { + std::__uninitialized_allocator_fill_n_multidimensional(__alloc_, std::begin(__data_), __count_, __arg); + } + + _LIBCPP_HIDE_FROM_ABI explicit __unbounded_array_control_block(_Alloc const& __alloc, size_t __count) + : __alloc_(__alloc), __count_(__count) { +# if _LIBCPP_STD_VER >= 20 + if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { + // We are purposefully not using an allocator-aware default construction because the spec says so. + // There's currently no way of expressing default initialization in an allocator-aware manner anyway. + std::uninitialized_default_construct_n(std::begin(__data_), __count_); + } else { + std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::begin(__data_), __count_); } +# else + std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::begin(__data_), __count_); +# endif + } + + // Returns the number of bytes required to store a control block followed by the given number + // of elements of _Tp, with the whole storage being aligned to a multiple of _Tp's alignment. + _LIBCPP_HIDE_FROM_ABI static constexpr size_t __bytes_for(size_t __elements) { + // When there's 0 elements, the control block alone is enough since it holds one element. + // Otherwise, we allocate one fewer element than requested because the control block already + // holds one. Also, we use the bitwise formula below to ensure that we allocate enough bytes + // for the whole allocation to be a multiple of _Tp's alignment. That formula is taken from [1]. + // + // [1]: https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding + size_t __bytes = __elements == 0 ? sizeof(__unbounded_array_control_block) + : (__elements - 1) * sizeof(_Tp) + sizeof(__unbounded_array_control_block); + constexpr size_t __align = alignof(_Tp); + return (__bytes + __align - 1) & ~(__align - 1); + } - _LIBCPP_HIDE_FROM_ABI_VIRTUAL - ~__unbounded_array_control_block() override { } // can't be `= default` because of the sometimes-non-trivial union member __data_ + _LIBCPP_HIDE_FROM_ABI_VIRTUAL + ~__unbounded_array_control_block() override { + } // can't be `= default` because of the sometimes-non-trivial union member __data_ private: - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - std::__reverse_destroy(__data_, __data_ + __count_); - } else { - __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); - std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + __count_); - } -#else - __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); - std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + __count_); -#endif - } - - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { - using _AlignedStorage = __sp_aligned_storage<alignof(__unbounded_array_control_block)>; - using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>; - using _PointerTraits = pointer_traits<typename allocator_traits<_StorageAlloc>::pointer>; - - _StorageAlloc __tmp(__alloc_); - __alloc_.~_Alloc(); - size_t __size = __unbounded_array_control_block::__bytes_for(__count_); - _AlignedStorage* __storage = reinterpret_cast<_AlignedStorage*>(this); - allocator_traits<_StorageAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*__storage), __size); + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { +# if _LIBCPP_STD_VER >= 20 + if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { + std::__reverse_destroy(__data_, __data_ + __count_); + } else { + __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); + std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + __count_); } - - _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; - size_t __count_; - union { - _Tp __data_[1]; - }; +# else + __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); + std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + __count_); +# endif + } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { + using _AlignedStorage = __sp_aligned_storage<alignof(__unbounded_array_control_block)>; + using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>; + using _PointerTraits = pointer_traits<typename allocator_traits<_StorageAlloc>::pointer>; + + _StorageAlloc __tmp(__alloc_); + __alloc_.~_Alloc(); + size_t __size = __unbounded_array_control_block::__bytes_for(__count_); + _AlignedStorage* __storage = reinterpret_cast<_AlignedStorage*>(this); + allocator_traits<_StorageAlloc>::deallocate( + __tmp, _PointerTraits::pointer_to(*__storage), __size / sizeof(_AlignedStorage)); + } + + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + size_t __count_; + union { + _Tp __data_[1]; + }; }; -template<class _Array, class _Alloc, class... _Arg> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Array> __allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&& ...__arg) -{ - static_assert(__libcpp_is_unbounded_array<_Array>::value); - // We compute the number of bytes necessary to hold the control block and the - // array elements. Then, we allocate an array of properly-aligned dummy structs - // large enough to hold the control block and array. This allows shifting the - // burden of aligning memory properly from us to the allocator. - using _ControlBlock = __unbounded_array_control_block<_Array, _Alloc>; - using _AlignedStorage = __sp_aligned_storage<alignof(_ControlBlock)>; - using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>; - __allocation_guard<_StorageAlloc> __guard(__a, _ControlBlock::__bytes_for(__n) / sizeof(_AlignedStorage)); - _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get())); - std::__construct_at(__control_block, __a, __n, std::forward<_Arg>(__arg)...); - __guard.__release_ptr(); - return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block); +template <class _Array, class _Alloc, class... _Arg> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array> +__allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&&... __arg) { + static_assert(__libcpp_is_unbounded_array<_Array>::value); + // We compute the number of bytes necessary to hold the control block and the + // array elements. Then, we allocate an array of properly-aligned dummy structs + // large enough to hold the control block and array. This allows shifting the + // burden of aligning memory properly from us to the allocator. + using _ControlBlock = __unbounded_array_control_block<_Array, _Alloc>; + using _AlignedStorage = __sp_aligned_storage<alignof(_ControlBlock)>; + using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>; + __allocation_guard<_StorageAlloc> __guard(__a, _ControlBlock::__bytes_for(__n) / sizeof(_AlignedStorage)); + _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get())); + std::__construct_at(__control_block, __a, __n, std::forward<_Arg>(__arg)...); + __guard.__release_ptr(); + return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block); } template <class _Tp, class _Alloc> struct __bounded_array_control_block; template <class _Tp, size_t _Count, class _Alloc> -struct __bounded_array_control_block<_Tp[_Count], _Alloc> - : __shared_weak_count -{ - _LIBCPP_HIDE_FROM_ABI constexpr - _Tp* __get_data() noexcept { return __data_; } - - _LIBCPP_HIDE_FROM_ABI - explicit __bounded_array_control_block(_Alloc const& __alloc, _Tp const& __arg) : __alloc_(__alloc) { - std::__uninitialized_allocator_fill_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count, __arg); - } - - _LIBCPP_HIDE_FROM_ABI - explicit __bounded_array_control_block(_Alloc const& __alloc) : __alloc_(__alloc) { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - // We are purposefully not using an allocator-aware default construction because the spec says so. - // There's currently no way of expressing default initialization in an allocator-aware manner anyway. - std::uninitialized_default_construct_n(std::addressof(__data_[0]), _Count); - } else { - std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count); - } -#else - std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count); -#endif +struct __bounded_array_control_block<_Tp[_Count], _Alloc> : __shared_weak_count { + _LIBCPP_HIDE_FROM_ABI constexpr _Tp* __get_data() noexcept { return __data_; } + + _LIBCPP_HIDE_FROM_ABI explicit __bounded_array_control_block(_Alloc const& __alloc, _Tp const& __arg) + : __alloc_(__alloc) { + std::__uninitialized_allocator_fill_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count, __arg); + } + + _LIBCPP_HIDE_FROM_ABI explicit __bounded_array_control_block(_Alloc const& __alloc) : __alloc_(__alloc) { +# if _LIBCPP_STD_VER >= 20 + if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { + // We are purposefully not using an allocator-aware default construction because the spec says so. + // There's currently no way of expressing default initialization in an allocator-aware manner anyway. + std::uninitialized_default_construct_n(std::addressof(__data_[0]), _Count); + } else { + std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count); } +# else + std::__uninitialized_allocator_value_construct_n_multidimensional(__alloc_, std::addressof(__data_[0]), _Count); +# endif + } - _LIBCPP_HIDE_FROM_ABI_VIRTUAL - ~__bounded_array_control_block() override { } // can't be `= default` because of the sometimes-non-trivial union member __data_ + _LIBCPP_HIDE_FROM_ABI_VIRTUAL + ~__bounded_array_control_block() override { + } // can't be `= default` because of the sometimes-non-trivial union member __data_ private: - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { -#if _LIBCPP_STD_VER >= 20 - if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { - std::__reverse_destroy(__data_, __data_ + _Count); - } else { - __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); - std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + _Count); - } -#else - __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); - std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + _Count); -#endif - } - - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { - using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, __bounded_array_control_block>; - using _PointerTraits = pointer_traits<typename allocator_traits<_ControlBlockAlloc>::pointer>; - - _ControlBlockAlloc __tmp(__alloc_); - __alloc_.~_Alloc(); - allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*this), sizeof(*this)); + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { +# if _LIBCPP_STD_VER >= 20 + if constexpr (is_same_v<typename _Alloc::value_type, __for_overwrite_tag>) { + std::__reverse_destroy(__data_, __data_ + _Count); + } else { + __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); + std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + _Count); } - - _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; - union { - _Tp __data_[_Count]; - }; +# else + __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_); + std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + _Count); +# endif + } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { + using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, __bounded_array_control_block>; + using _PointerTraits = pointer_traits<typename allocator_traits<_ControlBlockAlloc>::pointer>; + + _ControlBlockAlloc __tmp(__alloc_); + __alloc_.~_Alloc(); + allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*this), 1); + } + + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + union { + _Tp __data_[_Count]; + }; }; -template<class _Array, class _Alloc, class... _Arg> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&& ...__arg) -{ - static_assert(__libcpp_is_bounded_array<_Array>::value); - using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>; - using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>; +template <class _Array, class _Alloc, class... _Arg> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&&... __arg) { + static_assert(__libcpp_is_bounded_array<_Array>::value); + using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>; + using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>; - __allocation_guard<_ControlBlockAlloc> __guard(__a, 1); - _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get())); - std::__construct_at(__control_block, __a, std::forward<_Arg>(__arg)...); - __guard.__release_ptr(); - return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block); + __allocation_guard<_ControlBlockAlloc> __guard(__a, 1); + _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get())); + std::__construct_at(__control_block, __a, std::forward<_Arg>(__arg)...); + __guard.__release_ptr(); + return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block); } #endif // _LIBCPP_STD_VER >= 17 @@ -1246,289 +1032,198 @@ shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&& ... #if _LIBCPP_STD_VER >= 20 // bounded array variants -template<class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared(const _Alloc& __a) -{ - return std::__allocate_shared_bounded_array<_Tp>(__a); +template <class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a) { + return std::__allocate_shared_bounded_array<_Tp>(__a); } -template<class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared(const _Alloc& __a, const remove_extent_t<_Tp>& __u) -{ - return std::__allocate_shared_bounded_array<_Tp>(__a, __u); +template <class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, const remove_extent_t<_Tp>& __u) { + return std::__allocate_shared_bounded_array<_Tp>(__a, __u); } -template<class _Tp, class _Alloc, __enable_if_t<is_bounded_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a) -{ - using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; - _ForOverwriteAllocator __alloc(__a); - return std::__allocate_shared_bounded_array<_Tp>(__alloc); +template <class _Tp, class _Alloc, __enable_if_t<is_bounded_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a) { + using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; + _ForOverwriteAllocator __alloc(__a); + return std::__allocate_shared_bounded_array<_Tp>(__alloc); } -template<class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared() -{ - return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>()); +template <class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared() { + return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>()); } -template<class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared(const remove_extent_t<_Tp>& __u) -{ - return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>(), __u); +template <class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared(const remove_extent_t<_Tp>& __u) { + return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>(), __u); } -template<class _Tp, __enable_if_t<is_bounded_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared_for_overwrite() -{ - return std::__allocate_shared_bounded_array<_Tp>(allocator<__for_overwrite_tag>()); +template <class _Tp, __enable_if_t<is_bounded_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared_for_overwrite() { + return std::__allocate_shared_bounded_array<_Tp>(allocator<__for_overwrite_tag>()); } // unbounded array variants -template<class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n) -{ - return std::__allocate_shared_unbounded_array<_Tp>(__a, __n); +template <class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n) { + return std::__allocate_shared_unbounded_array<_Tp>(__a, __n); } -template<class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n, const remove_extent_t<_Tp>& __u) -{ - return std::__allocate_shared_unbounded_array<_Tp>(__a, __n, __u); +template <class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n, const remove_extent_t<_Tp>& __u) { + return std::__allocate_shared_unbounded_array<_Tp>(__a, __n, __u); } -template<class _Tp, class _Alloc, __enable_if_t<is_unbounded_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a, size_t __n) -{ - using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; - _ForOverwriteAllocator __alloc(__a); - return std::__allocate_shared_unbounded_array<_Tp>(__alloc, __n); +template <class _Tp, class _Alloc, __enable_if_t<is_unbounded_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a, size_t __n) { + using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; + _ForOverwriteAllocator __alloc(__a); + return std::__allocate_shared_unbounded_array<_Tp>(__alloc, __n); } -template<class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared(size_t __n) -{ - return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n); +template <class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared(size_t __n) { + return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n); } -template<class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared(size_t __n, const remove_extent_t<_Tp>& __u) -{ - return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n, __u); +template <class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared(size_t __n, const remove_extent_t<_Tp>& __u) { + return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n, __u); } -template<class _Tp, __enable_if_t<is_unbounded_array<_Tp>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -shared_ptr<_Tp> make_shared_for_overwrite(size_t __n) -{ - return std::__allocate_shared_unbounded_array<_Tp>(allocator<__for_overwrite_tag>(), __n); +template <class _Tp, __enable_if_t<is_unbounded_array<_Tp>::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared_for_overwrite(size_t __n) { + return std::__allocate_shared_unbounded_array<_Tp>(allocator<__for_overwrite_tag>(), __n); } #endif // _LIBCPP_STD_VER >= 20 -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return __x.get() == __y.get(); +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { + return __x.get() == __y.get(); } #if _LIBCPP_STD_VER <= 17 -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return !(__x == __y); -} - -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ -#if _LIBCPP_STD_VER <= 11 - typedef typename common_type<_Tp*, _Up*>::type _Vp; - return less<_Vp>()(__x.get(), __y.get()); -#else - return less<>()(__x.get(), __y.get()); -#endif +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { + return !(__x == __y); +} +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { +# if _LIBCPP_STD_VER <= 11 + typedef typename common_type<_Tp*, _Up*>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); +# else + return less<>()(__x.get(), __y.get()); +# endif } -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return __y < __x; +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { + return __y < __x; } -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return !(__y < __x); +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { + return !(__y < __x); } -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return !(__x < __y); +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { + return !(__x < __y); } #endif // _LIBCPP_STD_VER <= 17 #if _LIBCPP_STD_VER >= 20 -template<class _Tp, class _Up> -_LIBCPP_HIDE_FROM_ABI strong_ordering -operator<=>(shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) noexcept -{ - return compare_three_way()(__x.get(), __y.get()); +template <class _Tp, class _Up> +_LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) noexcept { + return compare_three_way()(__x.get(), __y.get()); } #endif -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return !__x; +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return !__x; } #if _LIBCPP_STD_VER <= 17 -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return !__x; +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return !__x; } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return static_cast<bool>(__x); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return static_cast<bool>(__x); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return static_cast<bool>(__x); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return static_cast<bool>(__x); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return less<_Tp*>()(__x.get(), nullptr); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return less<typename shared_ptr<_Tp>::element_type*>()(__x.get(), nullptr); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return less<_Tp*>()(nullptr, __x.get()); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return less<typename shared_ptr<_Tp>::element_type*>()(nullptr, __x.get()); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return nullptr < __x; +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return nullptr < __x; } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return __x < nullptr; +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return __x < nullptr; } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return !(nullptr < __x); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return !(nullptr < __x); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return !(__x < nullptr); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return !(__x < nullptr); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return !(__x < nullptr); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT { + return !(__x < nullptr); } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return !(nullptr < __x); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT { + return !(nullptr < __x); } #endif // _LIBCPP_STD_VER <= 17 #if _LIBCPP_STD_VER >= 20 -template<class _Tp> -_LIBCPP_HIDE_FROM_ABI strong_ordering -operator<=>(shared_ptr<_Tp> const& __x, nullptr_t) noexcept -{ - return compare_three_way()(__x.get(), static_cast<typename shared_ptr<_Tp>::element_type*>(nullptr)); +template <class _Tp> +_LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(shared_ptr<_Tp> const& __x, nullptr_t) noexcept { + return compare_three_way()(__x.get(), static_cast<typename shared_ptr<_Tp>::element_type*>(nullptr)); } #endif -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -void -swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT -{ - __x.swap(__y); +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI void swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT { + __x.swap(__y); } -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -shared_ptr<_Tp> -static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT -{ - return shared_ptr<_Tp>(__r, - static_cast< - typename shared_ptr<_Tp>::element_type*>(__r.get())); +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { + return shared_ptr<_Tp>(__r, static_cast< typename shared_ptr<_Tp>::element_type*>(__r.get())); } // LWG-2996 @@ -1540,14 +1235,11 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> static_pointer_cast(shared_ptr<_Up>&& __r) } #endif -template<class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -shared_ptr<_Tp> -dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT -{ - typedef typename shared_ptr<_Tp>::element_type _ET; - _ET* __p = dynamic_cast<_ET*>(__r.get()); - return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { + typedef typename shared_ptr<_Tp>::element_type _ET; + _ET* __p = dynamic_cast<_ET*>(__r.get()); + return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); } // LWG-2996 @@ -1560,12 +1252,10 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> dynamic_pointer_cast(shared_ptr<_Up>&& __r } #endif -template<class _Tp, class _Up> -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> -const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT -{ - typedef typename shared_ptr<_Tp>::element_type _RTp; - return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); +template <class _Tp, class _Up> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { + typedef typename shared_ptr<_Tp>::element_type _RTp; + return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); } // LWG-2996 @@ -1577,13 +1267,9 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(shared_ptr<_Up>&& __r) } #endif -template<class _Tp, class _Up> -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> -reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT -{ - return shared_ptr<_Tp>(__r, - reinterpret_cast< - typename shared_ptr<_Tp>::element_type*>(__r.get())); +template <class _Tp, class _Up> +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { + return shared_ptr<_Tp>(__r, reinterpret_cast< typename shared_ptr<_Tp>::element_type*>(__r.get())); } // LWG-2996 @@ -1597,542 +1283,388 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(shared_ptr<_Up>&& #ifndef _LIBCPP_HAS_NO_RTTI -template<class _Dp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Dp* -get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT -{ - return __p.template __get_deleter<_Dp>(); +template <class _Dp, class _Tp> +inline _LIBCPP_HIDE_FROM_ABI _Dp* get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT { + return __p.template __get_deleter<_Dp>(); } #endif // _LIBCPP_HAS_NO_RTTI -template<class _Tp> -class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr -{ +template <class _Tp> +class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr { public: #if _LIBCPP_STD_VER >= 17 - typedef remove_extent_t<_Tp> element_type; + typedef remove_extent_t<_Tp> element_type; #else - typedef _Tp element_type; + typedef _Tp element_type; #endif private: - element_type* __ptr_; - __shared_weak_count* __cntrl_; + element_type* __ptr_; + __shared_weak_count* __cntrl_; public: - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; - template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0) - _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - weak_ptr(weak_ptr const& __r) _NOEXCEPT; - template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0) - _NOEXCEPT; - - _LIBCPP_INLINE_VISIBILITY - weak_ptr(weak_ptr&& __r) _NOEXCEPT; - template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0) - _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI ~weak_ptr(); - - _LIBCPP_INLINE_VISIBILITY - weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, _Tp>::value, - weak_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; - - _LIBCPP_INLINE_VISIBILITY - weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, _Tp>::value, - weak_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; - - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, _Tp>::value, - weak_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; - - _LIBCPP_INLINE_VISIBILITY - void swap(weak_ptr& __r) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - void reset() _NOEXCEPT; - - _LIBCPP_INLINE_VISIBILITY - long use_count() const _NOEXCEPT - {return __cntrl_ ? __cntrl_->use_count() : 0;} - _LIBCPP_INLINE_VISIBILITY - bool expired() const _NOEXCEPT - {return __cntrl_ == nullptr || __cntrl_->use_count() == 0;} - _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> lock() const _NOEXCEPT; - template<class _Up> - _LIBCPP_INLINE_VISIBILITY - bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT - {return __cntrl_ < __r.__cntrl_;} - template<class _Up> - _LIBCPP_INLINE_VISIBILITY - bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT - {return __cntrl_ < __r.__cntrl_;} - - template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; - template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; + + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr const& __r) _NOEXCEPT; + + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr&& __r) _NOEXCEPT; + + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI ~weak_ptr(); + + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; + + template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI void swap(weak_ptr& __r) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT; + + _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __cntrl_ ? __cntrl_->use_count() : 0; } + _LIBCPP_HIDE_FROM_ABI bool expired() const _NOEXCEPT { return __cntrl_ == nullptr || __cntrl_->use_count() == 0; } + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> lock() const _NOEXCEPT; + template <class _Up> + _LIBCPP_HIDE_FROM_ABI bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT { + return __cntrl_ < __r.__cntrl_; + } + template <class _Up> + _LIBCPP_HIDE_FROM_ABI bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT { + return __cntrl_ < __r.__cntrl_; + } + + template <class _Up> + friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + template <class _Up> + friend class _LIBCPP_TEMPLATE_VIS shared_ptr; }; #if _LIBCPP_STD_VER >= 17 -template<class _Tp> +template <class _Tp> weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; #endif -template<class _Tp> -inline -_LIBCPP_CONSTEXPR -weak_ptr<_Tp>::weak_ptr() _NOEXCEPT - : __ptr_(nullptr), - __cntrl_(nullptr) -{ -} - -template<class _Tp> -inline -weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_weak(); -} - -template<class _Tp> -template<class _Yp> -inline -weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_weak(); -} - -template<class _Tp> -template<class _Yp> -inline -weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_weak(); +template <class _Tp> +inline _LIBCPP_CONSTEXPR weak_ptr<_Tp>::weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} + +template <class _Tp> +inline weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_weak(); } -template<class _Tp> -inline -weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_weak(); } -template<class _Tp> -template<class _Yp> -inline -weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, - typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { + shared_ptr<_Yp> __s = __r.lock(); + *this = weak_ptr<_Tp>(__s); } -template<class _Tp> -weak_ptr<_Tp>::~weak_ptr() -{ - if (__cntrl_) - __cntrl_->__release_weak(); +template <class _Tp> +inline weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; } -template<class _Tp> -inline -weak_ptr<_Tp>& -weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT -{ - weak_ptr(__r).swap(*this); - return *this; +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { + shared_ptr<_Yp> __s = __r.lock(); + *this = weak_ptr<_Tp>(__s); + __r.reset(); } -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, _Tp>::value, - weak_ptr<_Tp>& ->::type -weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT -{ - weak_ptr(__r).swap(*this); - return *this; +template <class _Tp> +weak_ptr<_Tp>::~weak_ptr() { + if (__cntrl_) + __cntrl_->__release_weak(); } -template<class _Tp> -inline -weak_ptr<_Tp>& -weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT -{ - weak_ptr(_VSTD::move(__r)).swap(*this); - return *this; +template <class _Tp> +inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; } -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, _Tp>::value, - weak_ptr<_Tp>& ->::type -weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT -{ - weak_ptr(_VSTD::move(__r)).swap(*this); - return *this; +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; } -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, _Tp>::value, - weak_ptr<_Tp>& ->::type -weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT -{ - weak_ptr(__r).swap(*this); - return *this; +template <class _Tp> +inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT { + weak_ptr(std::move(__r)).swap(*this); + return *this; } -template<class _Tp> -inline -void -weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT -{ - _VSTD::swap(__ptr_, __r.__ptr_); - _VSTD::swap(__cntrl_, __r.__cntrl_); +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT { + weak_ptr(std::move(__r)).swap(*this); + return *this; } -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -void -swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT -{ - __x.swap(__y); +template <class _Tp> +template <class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> > +inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; } -template<class _Tp> -inline -void -weak_ptr<_Tp>::reset() _NOEXCEPT -{ - weak_ptr().swap(*this); +template <class _Tp> +inline void weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT { + std::swap(__ptr_, __r.__ptr_); + std::swap(__cntrl_, __r.__cntrl_); } -template<class _Tp> -shared_ptr<_Tp> -weak_ptr<_Tp>::lock() const _NOEXCEPT -{ - shared_ptr<_Tp> __r; - __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; - if (__r.__cntrl_) - __r.__ptr_ = __ptr_; - return __r; +template <class _Tp> +inline _LIBCPP_HIDE_FROM_ABI void swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT { + __x.swap(__y); +} + +template <class _Tp> +inline void weak_ptr<_Tp>::reset() _NOEXCEPT { + weak_ptr().swap(*this); +} + +template <class _Tp> +shared_ptr<_Tp> weak_ptr<_Tp>::lock() const _NOEXCEPT { + shared_ptr<_Tp> __r; + __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; + if (__r.__cntrl_) + __r.__ptr_ = __ptr_; + return __r; } #if _LIBCPP_STD_VER >= 17 -template <class _Tp = void> struct owner_less; +template <class _Tp = void> +struct owner_less; #else -template <class _Tp> struct owner_less; +template <class _Tp> +struct owner_less; #endif - template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > - : __binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> -{ - _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} +struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > : __binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> { + _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } }; template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > - : __binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> -{ - _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} +struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > : __binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> { + _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } }; #if _LIBCPP_STD_VER >= 17 template <> -struct _LIBCPP_TEMPLATE_VIS owner_less<void> -{ - template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY - bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY - bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT - {return __x.owner_before(__y);} - typedef void is_transparent; +struct _LIBCPP_TEMPLATE_VIS owner_less<void> { + template <class _Tp, class _Up> + _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + template <class _Tp, class _Up> + _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + template <class _Tp, class _Up> + _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + template <class _Tp, class _Up> + _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT { + return __x.owner_before(__y); + } + typedef void is_transparent; }; #endif -template<class _Tp> -class _LIBCPP_TEMPLATE_VIS enable_shared_from_this -{ - mutable weak_ptr<_Tp> __weak_this_; +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS enable_shared_from_this { + mutable weak_ptr<_Tp> __weak_this_; + protected: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - enable_shared_from_this() _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY - enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY - enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT - {return *this;} - _LIBCPP_INLINE_VISIBILITY - ~enable_shared_from_this() {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR enable_shared_from_this() _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT { return *this; } + _LIBCPP_HIDE_FROM_ABI ~enable_shared_from_this() {} + public: - _LIBCPP_INLINE_VISIBILITY - shared_ptr<_Tp> shared_from_this() - {return shared_ptr<_Tp>(__weak_this_);} - _LIBCPP_INLINE_VISIBILITY - shared_ptr<_Tp const> shared_from_this() const - {return shared_ptr<const _Tp>(__weak_this_);} + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> shared_from_this() { return shared_ptr<_Tp>(__weak_this_); } + _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp const> shared_from_this() const { return shared_ptr<const _Tp>(__weak_this_); } #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY - weak_ptr<_Tp> weak_from_this() _NOEXCEPT - { return __weak_this_; } + _LIBCPP_HIDE_FROM_ABI weak_ptr<_Tp> weak_from_this() _NOEXCEPT { return __weak_this_; } - _LIBCPP_INLINE_VISIBILITY - weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT - { return __weak_this_; } + _LIBCPP_HIDE_FROM_ABI weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT { return __weak_this_; } #endif // _LIBCPP_STD_VER >= 17 - template <class _Up> friend class shared_ptr; + template <class _Up> + friend class shared_ptr; }; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash; template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > -{ +struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > { #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> argument_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> argument_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type; #endif - _LIBCPP_INLINE_VISIBILITY - size_t operator()(const shared_ptr<_Tp>& __ptr) const _NOEXCEPT - { - return hash<typename shared_ptr<_Tp>::element_type*>()(__ptr.get()); - } + _LIBCPP_HIDE_FROM_ABI size_t operator()(const shared_ptr<_Tp>& __ptr) const _NOEXCEPT { + return hash<typename shared_ptr<_Tp>::element_type*>()(__ptr.get()); + } }; -template<class _CharT, class _Traits, class _Yp> -inline _LIBCPP_INLINE_VISIBILITY -basic_ostream<_CharT, _Traits>& +template <class _CharT, class _Traits, class _Yp> +inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); - #if !defined(_LIBCPP_HAS_NO_THREADS) -class _LIBCPP_EXPORTED_FROM_ABI __sp_mut -{ - void* __lx_; +class _LIBCPP_EXPORTED_FROM_ABI __sp_mut { + void* __lx_; + public: - void lock() _NOEXCEPT; - void unlock() _NOEXCEPT; + void lock() _NOEXCEPT; + void unlock() _NOEXCEPT; private: - _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; - __sp_mut(const __sp_mut&); - __sp_mut& operator=(const __sp_mut&); + _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; + __sp_mut(const __sp_mut&); + __sp_mut& operator=(const __sp_mut&); - friend _LIBCPP_EXPORTED_FROM_ABI __sp_mut& __get_sp_mut(const void*); + friend _LIBCPP_EXPORTED_FROM_ABI __sp_mut& __get_sp_mut(const void*); }; -_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -__sp_mut& __get_sp_mut(const void*); +_LIBCPP_EXPORTED_FROM_ABI __sp_mut& __get_sp_mut(const void*); template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -atomic_is_lock_free(const shared_ptr<_Tp>*) -{ - return false; +inline _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const shared_ptr<_Tp>*) { + return false; } template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> -atomic_load(const shared_ptr<_Tp>* __p) -{ - __sp_mut& __m = std::__get_sp_mut(__p); - __m.lock(); - shared_ptr<_Tp> __q = *__p; - __m.unlock(); - return __q; +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> atomic_load(const shared_ptr<_Tp>* __p) { + __sp_mut& __m = std::__get_sp_mut(__p); + __m.lock(); + shared_ptr<_Tp> __q = *__p; + __m.unlock(); + return __q; } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -shared_ptr<_Tp> -atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) -{ - return std::atomic_load(__p); +inline _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) { + return std::atomic_load(__p); } template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -_LIBCPP_HIDE_FROM_ABI void -atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) -{ - __sp_mut& __m = std::__get_sp_mut(__p); - __m.lock(); - __p->swap(__r); - __m.unlock(); +_LIBCPP_HIDE_FROM_ABI void atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { + __sp_mut& __m = std::__get_sp_mut(__p); + __m.lock(); + __p->swap(__r); + __m.unlock(); } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -void -atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) -{ - std::atomic_store(__p, __r); +inline _LIBCPP_HIDE_FROM_ABI void atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) { + std::atomic_store(__p, __r); } template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> -atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) -{ - __sp_mut& __m = std::__get_sp_mut(__p); - __m.lock(); - __p->swap(__r); - __m.unlock(); - return __r; +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { + __sp_mut& __m = std::__get_sp_mut(__p); + __m.lock(); + __p->swap(__r); + __m.unlock(); + return __r; } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -shared_ptr<_Tp> -atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) -{ - return std::atomic_exchange(__p, __r); +inline _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> +atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) { + return std::atomic_exchange(__p, __r); } template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR _LIBCPP_HIDE_FROM_ABI bool -atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) -{ - shared_ptr<_Tp> __temp; - __sp_mut& __m = std::__get_sp_mut(__p); - __m.lock(); - if (__p->__owner_equivalent(*__v)) - { - _VSTD::swap(__temp, *__p); - *__p = __w; - __m.unlock(); - return true; - } - _VSTD::swap(__temp, *__v); - *__v = *__p; +atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) { + shared_ptr<_Tp> __temp; + __sp_mut& __m = std::__get_sp_mut(__p); + __m.lock(); + if (__p->__owner_equivalent(*__v)) { + std::swap(__temp, *__p); + *__p = __w; __m.unlock(); - return false; + return true; + } + std::swap(__temp, *__v); + *__v = *__p; + __m.unlock(); + return false; } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -bool -atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) -{ - return std::atomic_compare_exchange_strong(__p, __v, __w); +inline _LIBCPP_HIDE_FROM_ABI bool +atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) { + return std::atomic_compare_exchange_strong(__p, __v, __w); } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -bool -atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, - shared_ptr<_Tp> __w, memory_order, memory_order) -{ - return std::atomic_compare_exchange_strong(__p, __v, __w); +inline _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( + shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w, memory_order, memory_order) { + return std::atomic_compare_exchange_strong(__p, __v, __w); } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -bool -atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, - shared_ptr<_Tp> __w, memory_order, memory_order) -{ - return std::atomic_compare_exchange_weak(__p, __v, __w); +inline _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( + shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w, memory_order, memory_order) { + return std::atomic_compare_exchange_weak(__p, __v, __w); } #endif // !defined(_LIBCPP_HAS_NO_THREADS) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___MEMORY_SHARED_PTR_H diff --git a/lib/libcxx/include/__memory/swap_allocator.h b/lib/libcxx/include/__memory/swap_allocator.h index 90851cb79c..f2c5090563 100644 --- a/lib/libcxx/include/__memory/swap_allocator.h +++ b/lib/libcxx/include/__memory/swap_allocator.h @@ -29,7 +29,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swap_allocator(_Alloc _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) #endif { - using _VSTD::swap; + using std::swap; swap(__a1, __a2); } @@ -45,7 +45,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swap_allocator _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) #endif { - _VSTD::__swap_allocator( + std::__swap_allocator( __a1, __a2, integral_constant<bool, allocator_traits<_Alloc>::propagate_on_container_swap::value>()); } diff --git a/lib/libcxx/include/__memory/temp_value.h b/lib/libcxx/include/__memory/temp_value.h index 3ce8b4bcbb..4a133b3fbc 100644 --- a/lib/libcxx/include/__memory/temp_value.h +++ b/lib/libcxx/include/__memory/temp_value.h @@ -23,32 +23,34 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _Alloc> struct __temp_value { - typedef allocator_traits<_Alloc> _Traits; + typedef allocator_traits<_Alloc> _Traits; #ifdef _LIBCPP_CXX03_LANG - typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; + typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; #else - union { _Tp __v; }; + union { + _Tp __v; + }; #endif - _Alloc &__a; + _Alloc& __a; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp *__addr() { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __addr() { #ifdef _LIBCPP_CXX03_LANG - return reinterpret_cast<_Tp*>(std::addressof(__v)); + return reinterpret_cast<_Tp*>(std::addressof(__v)); #else - return std::addressof(__v); + return std::addressof(__v); #endif - } + } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp & get() { return *__addr(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& get() { return *__addr(); } - template<class... _Args> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI - _LIBCPP_CONSTEXPR_SINCE_CXX20 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { - _Traits::construct(__a, __addr(), std::forward<_Args>(__args)...); - } + template <class... _Args> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_CONSTEXPR_SINCE_CXX20 __temp_value(_Alloc& __alloc, _Args&&... __args) + : __a(__alloc) { + _Traits::construct(__a, __addr(), std::forward<_Args>(__args)...); + } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__temp_value() { _Traits::destroy(__a, __addr()); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__temp_value() { _Traits::destroy(__a, __addr()); } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/temporary_buffer.h b/lib/libcxx/include/__memory/temporary_buffer.h index c917f041a0..d46bda3821 100644 --- a/lib/libcxx/include/__memory/temporary_buffer.h +++ b/lib/libcxx/include/__memory/temporary_buffer.h @@ -23,63 +23,52 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 -pair<_Tp*, ptrdiff_t> -get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT -{ - pair<_Tp*, ptrdiff_t> __r(0, 0); - const ptrdiff_t __m = (~ptrdiff_t(0) ^ - ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) - / sizeof(_Tp); - if (__n > __m) - __n = __m; - while (__n > 0) - { +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t> +get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT { + pair<_Tp*, ptrdiff_t> __r(0, 0); + const ptrdiff_t __m = + (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp); + if (__n > __m) + __n = __m; + while (__n > 0) { #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) - if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) - { - align_val_t __al = - align_val_t(alignment_of<_Tp>::value); - __r.first = static_cast<_Tp*>(::operator new( - __n * sizeof(_Tp), __al, nothrow)); - } else { - __r.first = static_cast<_Tp*>(::operator new( - __n * sizeof(_Tp), nothrow)); - } + if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) { + align_val_t __al = align_val_t(_LIBCPP_ALIGNOF(_Tp)); + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al, nothrow)); + } else { + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); + } #else - if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) - { - // Since aligned operator new is unavailable, return an empty - // buffer rather than one with invalid alignment. - return __r; - } + if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) { + // Since aligned operator new is unavailable, return an empty + // buffer rather than one with invalid alignment. + return __r; + } - __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); #endif - if (__r.first) - { - __r.second = __n; - break; - } - __n /= 2; + if (__r.first) { + __r.second = __n; + break; } - return __r; + __n /= 2; + } + return __r; } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 -void return_temporary_buffer(_Tp* __p) _NOEXCEPT -{ - _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 void return_temporary_buffer(_Tp* __p) _NOEXCEPT { + std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); } -struct __return_temporary_buffer -{ -_LIBCPP_SUPPRESS_DEPRECATED_PUSH - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} -_LIBCPP_SUPPRESS_DEPRECATED_POP +struct __return_temporary_buffer { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) const { + std::return_temporary_buffer(__p); + } + _LIBCPP_SUPPRESS_DEPRECATED_POP }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/uninitialized_algorithms.h b/lib/libcxx/include/__memory/uninitialized_algorithms.h index 2b68df8e6d..9aff93a896 100644 --- a/lib/libcxx/include/__memory/uninitialized_algorithms.h +++ b/lib/libcxx/include/__memory/uninitialized_algorithms.h @@ -42,144 +42,132 @@ # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD -// This is a simplified version of C++20 `unreachable_sentinel` that doesn't use concepts and thus can be used in any -// language mode. -struct __unreachable_sentinel { - template <class _Iter> - _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool operator!=(const _Iter&, __unreachable_sentinel) _NOEXCEPT { - return true; +struct __always_false { + template <class... _Args> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(_Args&&...) const _NOEXCEPT { + return false; } }; // uninitialized_copy -template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_copy(_InputIterator __ifirst, _Sentinel1 __ilast, - _ForwardIterator __ofirst, _Sentinel2 __olast) { +template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _EndPredicate> +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy( + _InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __ifirst != __ilast && __idx != __olast; ++__ifirst, (void)++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst); + for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx) + ::new (std::__voidify(*__idx)) _ValueType(*__ifirst); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx)); + return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } template <class _InputIterator, class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI -_ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast, - _ForwardIterator __ofirst) { +_LIBCPP_HIDE_FROM_ABI _ForwardIterator +uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), __unreachable_sentinel()); - return _VSTD::move(__result.second); + auto __result = std::__uninitialized_copy<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false()); + return std::move(__result.second); } // uninitialized_copy_n -template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel> +template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _EndPredicate> inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_copy_n(_InputIterator __ifirst, _Size __n, - _ForwardIterator __ofirst, _Sentinel __olast) { +__uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __n > 0 && __idx != __olast; ++__ifirst, (void)++__idx, (void)--__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst); + for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n) + ::new (std::__voidify(*__idx)) _ValueType(*__ifirst); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx)); + return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } template <class _InputIterator, class _Size, class _ForwardIterator> -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy_n(_InputIterator __ifirst, _Size __n, - _ForwardIterator __ofirst) { +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst), - __unreachable_sentinel()); - return _VSTD::move(__result.second); + auto __result = + std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __always_false()); + return std::move(__result.second); } // uninitialized_fill template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) -{ - _ForwardIterator __idx = __first; +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +__uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) { + _ForwardIterator __idx = __first; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif - for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); + for (; __idx != __last; ++__idx) + ::new (std::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - _VSTD::__destroy(__first, __idx); - throw; - } + } catch (...) { + std::__destroy(__first, __idx); + throw; + } #endif - return __idx; + return __idx; } template <class _ForwardIterator, class _Tp> -inline _LIBCPP_HIDE_FROM_ABI -void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - (void)_VSTD::__uninitialized_fill<_ValueType>(__first, __last, __x); +inline _LIBCPP_HIDE_FROM_ABI void +uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x) { + typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + (void)std::__uninitialized_fill<_ValueType>(__first, __last, __x); } // uninitialized_fill_n template <class _ValueType, class _ForwardIterator, class _Size, class _Tp> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) -{ - _ForwardIterator __idx = __first; +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +__uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { + _ForwardIterator __idx = __first; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { + try { #endif - for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); + for (; __n > 0; ++__idx, (void)--__n) + ::new (std::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - _VSTD::__destroy(__first, __idx); - throw; - } + } catch (...) { + std::__destroy(__first, __idx); + throw; + } #endif - return __idx; + return __idx; } template <class _ForwardIterator, class _Size, class _Tp> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - return _VSTD::__uninitialized_fill_n<_ValueType>(__first, __n, __x); +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { + typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + return std::__uninitialized_fill_n<_ValueType>(__first, __n, __x); } #if _LIBCPP_STD_VER >= 17 @@ -187,182 +175,185 @@ _ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const // uninitialized_default_construct template <class _ValueType, class _ForwardIterator, class _Sentinel> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { - auto __idx = __first; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +__uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { + auto __idx = __first; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + try { +# endif for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - _VSTD::__destroy(__first, __idx); - throw; - } -#endif + ::new (std::__voidify(*__idx)) _ValueType; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + std::__destroy(__first, __idx); + throw; + } +# endif - return __idx; + return __idx; } template <class _ForwardIterator> -inline _LIBCPP_HIDE_FROM_ABI -void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - (void)_VSTD::__uninitialized_default_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); +inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + (void)std::__uninitialized_default_construct<_ValueType>(std::move(__first), std::move(__last)); } // uninitialized_default_construct_n template <class _ValueType, class _ForwardIterator, class _Size> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { - auto __idx = __first; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - _VSTD::__destroy(__first, __idx); - throw; - } -#endif +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + auto __idx = __first; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + try { +# endif + for (; __n > 0; ++__idx, (void)--__n) + ::new (std::__voidify(*__idx)) _ValueType; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + std::__destroy(__first, __idx); + throw; + } +# endif - return __idx; + return __idx; } template <class _ForwardIterator, class _Size> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { - using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n); +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n); } // uninitialized_value_construct template <class _ValueType, class _ForwardIterator, class _Sentinel> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { - auto __idx = __first; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +__uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { + auto __idx = __first; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + try { +# endif for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - _VSTD::__destroy(__first, __idx); - throw; - } -#endif + ::new (std::__voidify(*__idx)) _ValueType(); +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + std::__destroy(__first, __idx); + throw; + } +# endif - return __idx; + return __idx; } template <class _ForwardIterator> -inline _LIBCPP_HIDE_FROM_ABI -void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - (void)_VSTD::__uninitialized_value_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); +inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + (void)std::__uninitialized_value_construct<_ValueType>(std::move(__first), std::move(__last)); } // uninitialized_value_construct_n template <class _ValueType, class _ForwardIterator, class _Size> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { - auto __idx = __first; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - _VSTD::__destroy(__first, __idx); - throw; - } -#endif +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + auto __idx = __first; +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + try { +# endif + for (; __n > 0; ++__idx, (void)--__n) + ::new (std::__voidify(*__idx)) _ValueType(); +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + } catch (...) { + std::__destroy(__first, __idx); + throw; + } +# endif - return __idx; + return __idx; } template <class _ForwardIterator, class _Size> -inline _LIBCPP_HIDE_FROM_ABI -_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { - using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - return std::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n); +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n); } // uninitialized_move -template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2, +template <class _ValueType, + class _InputIterator, + class _Sentinel1, + class _ForwardIterator, + class _EndPredicate, class _IterMove> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_move(_InputIterator __ifirst, _Sentinel1 __ilast, - _ForwardIterator __ofirst, _Sentinel2 __olast, _IterMove __iter_move) { +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move( + _InputIterator __ifirst, + _Sentinel1 __ilast, + _ForwardIterator __ofirst, + _EndPredicate __stop_moving, + _IterMove __iter_move) { auto __idx = __ofirst; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { -#endif - for (; __ifirst != __ilast && __idx != __olast; ++__idx, (void)++__ifirst) { - ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); +# endif + for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) { + ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } -#endif +# endif - return {_VSTD::move(__ifirst), _VSTD::move(__idx)}; + return {std::move(__ifirst), std::move(__idx)}; } template <class _InputIterator, class _ForwardIterator> -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast, - _ForwardIterator __ofirst) { +inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; - auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), __unreachable_sentinel(), __iter_move); - return _VSTD::move(__result.second); + auto __result = std::__uninitialized_move<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false(), __iter_move); + return std::move(__result.second); } // uninitialized_move_n -template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel, class _IterMove> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_move_n(_InputIterator __ifirst, _Size __n, - _ForwardIterator __ofirst, _Sentinel __olast, _IterMove __iter_move) { +template <class _ValueType, + class _InputIterator, + class _Size, + class _ForwardIterator, + class _EndPredicate, + class _IterMove> +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n( + _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) { auto __idx = __ofirst; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { -#endif - for (; __n > 0 && __idx != __olast; ++__idx, (void)++__ifirst, --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# endif + for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n) + ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } -#endif +# endif - return {_VSTD::move(__ifirst), _VSTD::move(__idx)}; + return {std::move(__ifirst), std::move(__idx)}; } template <class _InputIterator, class _Size, class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; - return _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst), - __unreachable_sentinel(), __iter_move); + return std::__uninitialized_move_n<_ValueType>( + std::move(__ifirst), __n, std::move(__ofirst), __always_false(), __iter_move); } // TODO: Rewrite this to iterate left to right and use reverse_iterators when calling @@ -372,35 +363,35 @@ uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofir // // This function assumes that destructors do not throw, and that the allocator is bound to // the correct type. -template<class _Alloc, class _BidirIter, class = __enable_if_t< - __has_bidirectional_iterator_category<_BidirIter>::value ->> -_LIBCPP_HIDE_FROM_ABI -constexpr void __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _BidirIter __last) noexcept { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _ValueType>, - "The allocator should already be rebound to the correct type"); - - if (__first == __last) - return; - - if constexpr (is_array_v<_ValueType>) { - static_assert(!__libcpp_is_unbounded_array<_ValueType>::value, - "arrays of unbounded arrays don't exist, but if they did we would mess up here"); - - using _Element = remove_extent_t<_ValueType>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - do { - --__last; - decltype(auto) __array = *__last; - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + extent_v<_ValueType>); - } while (__last != __first); - } else { - do { - --__last; - allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__last)); - } while (__last != __first); - } +template <class _Alloc, + class _BidirIter, + class = __enable_if_t< __has_bidirectional_iterator_category<_BidirIter>::value >> +_LIBCPP_HIDE_FROM_ABI constexpr void +__allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _BidirIter __last) noexcept { + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _ValueType>, + "The allocator should already be rebound to the correct type"); + + if (__first == __last) + return; + + if constexpr (is_array_v<_ValueType>) { + static_assert(!__libcpp_is_unbounded_array<_ValueType>::value, + "arrays of unbounded arrays don't exist, but if they did we would mess up here"); + + using _Element = remove_extent_t<_ValueType>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + do { + --__last; + decltype(auto) __array = *__last; + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + extent_v<_ValueType>); + } while (__last != __first); + } else { + do { + --__last; + allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__last)); + } while (__last != __first); + } } // Constructs the object at the given location using the allocator's construct method. @@ -410,30 +401,29 @@ constexpr void __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter // elements are destroyed in reverse order of initialization using allocator destruction. // // This function assumes that the allocator is bound to the correct type. -template<class _Alloc, class _Tp> -_LIBCPP_HIDE_FROM_ABI -constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc) { - static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>, - "The allocator should already be rebound to the correct type"); - - if constexpr (is_array_v<_Tp>) { - using _Element = remove_extent_t<_Tp>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - size_t __i = 0; - _Tp& __array = *__loc; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); - }); - - for (; __i != extent_v<_Tp>; ++__i) { - std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i])); - } - __guard.__complete(); - } else { - allocator_traits<_Alloc>::construct(__alloc, __loc); +template <class _Alloc, class _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc) { + static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>, + "The allocator should already be rebound to the correct type"); + + if constexpr (is_array_v<_Tp>) { + using _Element = remove_extent_t<_Tp>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + size_t __i = 0; + _Tp& __array = *__loc; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = std::__make_exception_guard([&]() { + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); + }); + + for (; __i != extent_v<_Tp>; ++__i) { + std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i])); } + __guard.__complete(); + } else { + allocator_traits<_Alloc>::construct(__alloc, __loc); + } } // Constructs the object at the given location using the allocator's construct method, passing along @@ -446,33 +436,33 @@ constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* _ // destruction. // // This function assumes that the allocator is bound to the correct type. -template<class _Alloc, class _Tp, class _Arg> -_LIBCPP_HIDE_FROM_ABI -constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc, _Arg const& __arg) { - static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>, - "The allocator should already be rebound to the correct type"); - - if constexpr (is_array_v<_Tp>) { - static_assert(is_array_v<_Arg>, - "Provided non-array initialization argument to __allocator_construct_at_multidimensional when " - "trying to construct an array."); - - using _Element = remove_extent_t<_Tp>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - size_t __i = 0; - _Tp& __array = *__loc; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); - }); - for (; __i != extent_v<_Tp>; ++__i) { - std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i]), __arg[__i]); - } - __guard.__complete(); - } else { - allocator_traits<_Alloc>::construct(__alloc, __loc, __arg); +template <class _Alloc, class _Tp, class _Arg> +_LIBCPP_HIDE_FROM_ABI constexpr void +__allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc, _Arg const& __arg) { + static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>, + "The allocator should already be rebound to the correct type"); + + if constexpr (is_array_v<_Tp>) { + static_assert(is_array_v<_Arg>, + "Provided non-array initialization argument to __allocator_construct_at_multidimensional when " + "trying to construct an array."); + + using _Element = remove_extent_t<_Tp>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + size_t __i = 0; + _Tp& __array = *__loc; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = std::__make_exception_guard([&]() { + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); + }); + for (; __i != extent_v<_Tp>; ++__i) { + std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i]), __arg[__i]); } + __guard.__complete(); + } else { + allocator_traits<_Alloc>::construct(__alloc, __loc, __arg); + } } // Given a range starting at it and containing n elements, initializes each element in the @@ -482,19 +472,23 @@ constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* _ // If an exception is thrown, the initialized elements are destroyed in reverse order of // initialization using allocator_traits destruction. If the elements in the range are C-style // arrays, they are initialized element-wise using allocator construction, and recursively so. -template<class _Alloc, class _BidirIter, class _Tp, class _Size = typename iterator_traits<_BidirIter>::difference_type> +template <class _Alloc, + class _BidirIter, + class _Tp, + class _Size = typename iterator_traits<_BidirIter>::difference_type> _LIBCPP_HIDE_FROM_ABI constexpr void __uninitialized_allocator_fill_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n, _Tp const& __value) { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); - _BidirIter __begin = __it; + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); + _BidirIter __begin = __it; - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); - for (; __n != 0; --__n, ++__it) { - std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it), __value); - } - __guard.__complete(); + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = + std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); + for (; __n != 0; --__n, ++__it) { + std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it), __value); + } + __guard.__complete(); } // Same as __uninitialized_allocator_fill_n_multidimensional, but doesn't pass any initialization argument @@ -502,16 +496,17 @@ __uninitialized_allocator_fill_n_multidimensional(_Alloc& __alloc, _BidirIter __ template <class _Alloc, class _BidirIter, class _Size = typename iterator_traits<_BidirIter>::difference_type> _LIBCPP_HIDE_FROM_ABI constexpr void __uninitialized_allocator_value_construct_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n) { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); - _BidirIter __begin = __it; + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); + _BidirIter __begin = __it; - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); - for (; __n != 0; --__n, ++__it) { - std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it)); - } - __guard.__complete(); + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = + std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); + for (; __n != 0; --__n, ++__it) { + std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it)); + } + __guard.__complete(); } #endif // _LIBCPP_STD_VER >= 17 @@ -521,7 +516,7 @@ template <class _Alloc, class _Iter, class _Sent> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __allocator_destroy(_Alloc& __alloc, _Iter __first, _Sent __last) { for (; __first != __last; ++__first) - allocator_traits<_Alloc>::destroy(__alloc, std::__to_address(__first)); + allocator_traits<_Alloc>::destroy(__alloc, std::__to_address(__first)); } template <class _Alloc, class _Iter> @@ -591,10 +586,12 @@ __uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out* } template <class _Alloc, class _Iter1, class _Sent1, class _Iter2> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2 __uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { - auto __unwrapped_range = std::__unwrap_range(__first1, __last1); - auto __result = std::__uninitialized_allocator_copy_impl(__alloc, __unwrapped_range.first, __unwrapped_range.second, std::__unwrap_iter(__first2)); - return std::__rewrap_iter(__first2, __result); +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2 +__uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { + auto __unwrapped_range = std::__unwrap_range(__first1, __last1); + auto __result = std::__uninitialized_allocator_copy_impl( + __alloc, __unwrapped_range.first, __unwrapped_range.second, std::__unwrap_iter(__first2)); + return std::__rewrap_iter(__first2, __result); } // Move-construct the elements [__first1, __last1) into [__first2, __first2 + N) @@ -603,8 +600,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2 __uninitialized_alloc // Otherwise try to copy all elements. If an exception is thrown the already copied // elements are destroyed in reverse order of their construction. template <class _Alloc, class _Iter1, class _Sent1, class _Iter2> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2 __uninitialized_allocator_move_if_noexcept( - _Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2 +__uninitialized_allocator_move_if_noexcept(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { static_assert(__is_cpp17_move_insertable<_Alloc>::value, "The specified type does not meet the requirements of Cpp17MoveInsertable"); auto __destruct_first = __first2; @@ -654,4 +651,6 @@ __uninitialized_allocator_move_if_noexcept(_Alloc&, _Iter1 __first1, _Iter1 __la _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H diff --git a/lib/libcxx/include/__memory/unique_ptr.h b/lib/libcxx/include/__memory/unique_ptr.h index 5a96878971..db473eaa50 100644 --- a/lib/libcxx/include/__memory/unique_ptr.h +++ b/lib/libcxx/include/__memory/unique_ptr.h @@ -51,18 +51,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> struct _LIBCPP_TEMPLATE_VIS default_delete { - static_assert(!is_function<_Tp>::value, - "default_delete cannot be instantiated for function types"); + static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types"); #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; + _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default; #else - _LIBCPP_INLINE_VISIBILITY default_delete() {} + _LIBCPP_HIDE_FROM_ABI default_delete() {} #endif - template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete( - const default_delete<_Up>&, typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} + template <class _Up, __enable_if_t<is_convertible<_Up*, _Tp*>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(const default_delete<_Up>&) _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) const _NOEXCEPT { static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type"); static_assert(!is_void<_Tp>::value, "cannot delete an incomplete type"); delete __ptr; @@ -73,22 +71,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { private: template <class _Up> - struct _EnableIfConvertible - : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; + struct _EnableIfConvertible : enable_if<is_convertible<_Up (*)[], _Tp (*)[]>::value> {}; public: #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; + _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default; #else - _LIBCPP_INLINE_VISIBILITY default_delete() {} + _LIBCPP_HIDE_FROM_ABI default_delete() {} #endif template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(const default_delete<_Up[]>&, typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename _EnableIfConvertible<_Up>::type + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename _EnableIfConvertible<_Up>::type operator()(_Up* __ptr) const _NOEXCEPT { static_assert(sizeof(_Up) >= 0, "cannot delete an incomplete type"); delete[] __ptr; @@ -130,109 +127,85 @@ public: typedef _Dp deleter_type; typedef _LIBCPP_NODEBUG typename __pointer<_Tp, deleter_type>::type pointer; - static_assert(!is_rvalue_reference<deleter_type>::value, - "the specified deleter type cannot be an rvalue reference"); + static_assert(!is_rvalue_reference<deleter_type>::value, "the specified deleter type cannot be an rvalue reference"); private: __compressed_pair<pointer, deleter_type> __ptr_; - struct __nat { int __for_bool_; }; - typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; template <bool _Dummy> - using _LValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; + using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; template <bool _Dummy> - using _GoodRValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; + using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; template <bool _Dummy> - using _BadRValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; - template <bool _Dummy, class _Deleter = typename __dependent_type< - __type_identity<deleter_type>, _Dummy>::type> + template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type> using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - typename enable_if<is_default_constructible<_Deleter>::value && - !is_pointer<_Deleter>::value>::type; + __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>; template <class _ArgType> - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = - typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>; template <class _UPtr, class _Up> - using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if< - is_convertible<typename _UPtr::pointer, pointer>::value && - !is_array<_Up>::value - >::type; + using _EnableIfMoveConvertible _LIBCPP_NODEBUG = + __enable_if_t< is_convertible<typename _UPtr::pointer, pointer>::value && !is_array<_Up>::value >; template <class _UDel> - using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if< - (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || - (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) - >::type; + using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = + __enable_if_t< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >; template <class _UDel> - using _EnableIfDeleterAssignable = typename enable_if< - is_assignable<_Dp&, _UDel&&>::value - >::type; + using _EnableIfDeleterAssignable = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >; public: - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT + : __ptr_(__value_init_tag(), __value_init_tag()) {} template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {} template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, __d) {} template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 - unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, _VSTD::move(__d)) { - static_assert(!is_reference<deleter_type>::value, - "rvalue deleter bound to reference"); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT + : __ptr_(__p, std::move(__d)) { + static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; + template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > + _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT + : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {} template <class _Up, class _Ep, class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, class = _EnableIfDeleterConvertible<_Ep> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {} #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - unique_ptr(auto_ptr<_Up>&& __p, - typename enable_if<is_convertible<_Up*, _Tp*>::value && - is_same<_Dp, default_delete<_Tp> >::value, - __nat>::type = __nat()) _NOEXCEPT - : __ptr_(__p.release(), __value_init_tag()) {} + template <class _Up, + __enable_if_t<is_convertible<_Up*, _Tp*>::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release(), __value_init_tag()) {} #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + __ptr_.second() = std::forward<deleter_type>(__u.get_deleter()); return *this; } @@ -240,72 +213,62 @@ public: class _Ep, class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, class = _EnableIfDeleterAssignable<_Ep> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + __ptr_.second() = std::forward<_Ep>(__u.get_deleter()); return *this; } #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - typename enable_if<is_convertible<_Up*, _Tp*>::value && - is_same<_Dp, default_delete<_Tp> >::value, - unique_ptr&>::type - operator=(auto_ptr<_Up> __p) { + template <class _Up, + __enable_if_t<is_convertible<_Up*, _Tp*>::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI unique_ptr& operator=(auto_ptr<_Up> __p) { reset(__p.release()); return *this; } #endif #ifdef _LIBCPP_CXX03_LANG - unique_ptr(unique_ptr const&) = delete; + unique_ptr(unique_ptr const&) = delete; unique_ptr& operator=(unique_ptr const&) = delete; #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT { reset(); return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const { return *__ptr_.first(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { - return __ptr_.first(); - } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_.first(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { return __ptr_.second(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { - return __ptr_.second(); - } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { return __ptr_.first() != nullptr; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); __ptr_.first() = pointer(); return __t; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(pointer __p = pointer()) _NOEXCEPT { - pointer __tmp = __ptr_.first(); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(pointer __p = pointer()) _NOEXCEPT { + pointer __tmp = __ptr_.first(); __ptr_.first() = __p; if (__tmp) __ptr_.second()(__tmp); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { - __ptr_.swap(__u.__ptr_); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); } }; - template <class _Tp, class _Dp> class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { public: @@ -322,119 +285,98 @@ private: template <class _FromElem> struct _CheckArrayPointerConversion<_FromElem*> : integral_constant<bool, - is_same<_FromElem*, pointer>::value || - (is_same<pointer, element_type*>::value && - is_convertible<_FromElem(*)[], element_type(*)[]>::value) - > - {}; + is_same<_FromElem*, pointer>::value || + (is_same<pointer, element_type*>::value && + is_convertible<_FromElem (*)[], element_type (*)[]>::value) > {}; typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; template <bool _Dummy> - using _LValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; + using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; template <bool _Dummy> - using _GoodRValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; + using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; template <bool _Dummy> - using _BadRValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; - template <bool _Dummy, class _Deleter = typename __dependent_type< - __type_identity<deleter_type>, _Dummy>::type> + template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type> using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - typename enable_if<is_default_constructible<_Deleter>::value && - !is_pointer<_Deleter>::value>::type; + __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>; template <class _ArgType> - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = - typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>; template <class _Pp> - using _EnableIfPointerConvertible _LIBCPP_NODEBUG = typename enable_if< - _CheckArrayPointerConversion<_Pp>::value - >::type; - - template <class _UPtr, class _Up, - class _ElemT = typename _UPtr::element_type> - using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if< - is_array<_Up>::value && - is_same<pointer, element_type*>::value && - is_same<typename _UPtr::pointer, _ElemT*>::value && - is_convertible<_ElemT(*)[], element_type(*)[]>::value - >::type; + using _EnableIfPointerConvertible _LIBCPP_NODEBUG = __enable_if_t< _CheckArrayPointerConversion<_Pp>::value >; + + template <class _UPtr, class _Up, class _ElemT = typename _UPtr::element_type> + using _EnableIfMoveConvertible _LIBCPP_NODEBUG = + __enable_if_t< is_array<_Up>::value && is_same<pointer, element_type*>::value && + is_same<typename _UPtr::pointer, _ElemT*>::value && + is_convertible<_ElemT (*)[], element_type (*)[]>::value >; template <class _UDel> - using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if< - (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || - (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) - >::type; + using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = + __enable_if_t< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >; template <class _UDel> - using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = typename enable_if< - is_assignable<_Dp&, _UDel&&>::value - >::type; + using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >; public: - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT + : __ptr_(__value_init_tag(), __value_init_tag()) {} template <class _Pp, bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy>, class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __p) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {} template <class _Pp, bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, __d) {} template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(nullptr, __d) {} template <class _Pp, bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >, class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, _VSTD::move(__d)) { - static_assert(!is_reference<deleter_type>::value, - "rvalue deleter bound to reference"); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT + : __ptr_(__p, std::move(__d)) { + static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(nullptr, _VSTD::move(__d)) { - static_assert(!is_reference<deleter_type>::value, - "rvalue deleter bound to reference"); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT + : __ptr_(nullptr, std::move(__d)) { + static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } - template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; + template <class _Pp, + bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > + _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT + : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + __ptr_.second() = std::forward<deleter_type>(__u.get_deleter()); return *this; } @@ -442,263 +384,228 @@ public: class _Ep, class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, class = _EnableIfDeleterConvertible<_Ep> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {} template <class _Up, class _Ep, class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, class = _EnableIfDeleterAssignable<_Ep> > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + __ptr_.second() = std::forward<_Ep>(__u.get_deleter()); return *this; } #ifdef _LIBCPP_CXX03_LANG - unique_ptr(unique_ptr const&) = delete; + unique_ptr(unique_ptr const&) = delete; unique_ptr& operator=(unique_ptr const&) = delete; #endif + public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT { reset(); return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> - operator[](size_t __i) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator[](size_t __i) const { return __ptr_.first()[__i]; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { - return __ptr_.second(); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { return __ptr_.second(); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { return __ptr_.first() != nullptr; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); __ptr_.first() = pointer(); return __t; } - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 - typename enable_if< _CheckArrayPointerConversion<_Pp>::value >::type - reset(_Pp __p) _NOEXCEPT { - pointer __tmp = __ptr_.first(); + template <class _Pp, __enable_if_t<_CheckArrayPointerConversion<_Pp>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __p) _NOEXCEPT { + pointer __tmp = __ptr_.first(); __ptr_.first() = __p; if (__tmp) __ptr_.second()(__tmp); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT { - pointer __tmp = __ptr_.first(); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT { + pointer __tmp = __ptr_.first(); __ptr_.first() = nullptr; if (__tmp) __ptr_.second()(__tmp); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { - __ptr_.swap(__u.__ptr_); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); } }; -template <class _Tp, class _Dp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 - typename enable_if< __is_swappable<_Dp>::value, void >::type - swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT { +template <class _Tp, class _Dp, __enable_if_t<__is_swappable<_Dp>::value, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void +swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT { __x.swap(__y); } template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { return __x.get() == __y.get(); } #if _LIBCPP_STD_VER <= 17 template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + return !(__x == __y); +} #endif template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) -{ - typedef typename unique_ptr<_T1, _D1>::pointer _P1; - typedef typename unique_ptr<_T2, _D2>::pointer _P2; - typedef typename common_type<_P1, _P2>::type _Vp; - return less<_Vp>()(__x.get(), __y.get()); +inline _LIBCPP_HIDE_FROM_ABI bool operator<(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + typedef typename unique_ptr<_T1, _D1>::pointer _P1; + typedef typename unique_ptr<_T2, _D2>::pointer _P2; + typedef typename common_type<_P1, _P2>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); } template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} +inline _LIBCPP_HIDE_FROM_ABI bool operator>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + return __y < __x; +} template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + return !(__y < __x); +} template <class _T1, class _D1, class _T2, class _D2> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} - +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + return !(__x < __y); +} #if _LIBCPP_STD_VER >= 20 template <class _T1, class _D1, class _T2, class _D2> -requires three_way_comparable_with<typename unique_ptr<_T1, _D1>::pointer, - typename unique_ptr<_T2, _D2>::pointer> + requires three_way_comparable_with<typename unique_ptr<_T1, _D1>::pointer, typename unique_ptr<_T2, _D2>::pointer> _LIBCPP_HIDE_FROM_ABI -compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer, - typename unique_ptr<_T2, _D2>::pointer> -operator<=>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { - return compare_three_way()(__x.get(), __y.get()); + compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer, typename unique_ptr<_T2, _D2>::pointer> + operator<=>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) { + return compare_three_way()(__x.get(), __y.get()); } #endif template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT { return !__x; } #if _LIBCPP_STD_VER <= 17 template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT -{ - return !__x; +inline _LIBCPP_HIDE_FROM_ABI bool operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT { + return !__x; } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT -{ - return static_cast<bool>(__x); +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT { + return static_cast<bool>(__x); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT -{ - return static_cast<bool>(__x); +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT { + return static_cast<bool>(__x); } #endif // _LIBCPP_STD_VER <= 17 template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) { typedef typename unique_ptr<_T1, _D1>::pointer _P1; return less<_P1>()(__x.get(), nullptr); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) { typedef typename unique_ptr<_T1, _D1>::pointer _P1; return less<_P1>()(nullptr, __x.get()); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return nullptr < __x; } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return __x < nullptr; } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return !(nullptr < __x); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return !(__x < nullptr); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return !(__x < nullptr); } template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool -operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return !(nullptr < __x); } #if _LIBCPP_STD_VER >= 20 template <class _T1, class _D1> - requires three_way_comparable< - typename unique_ptr<_T1, _D1>::pointer> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 - compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer> + requires three_way_comparable< typename unique_ptr<_T1, _D1>::pointer> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer> operator<=>(const unique_ptr<_T1, _D1>& __x, nullptr_t) { - return compare_three_way()(__x.get(), static_cast<typename unique_ptr<_T1, _D1>::pointer>(nullptr)); + return compare_three_way()(__x.get(), static_cast<typename unique_ptr<_T1, _D1>::pointer>(nullptr)); } #endif #if _LIBCPP_STD_VER >= 14 -template<class _Tp> -struct __unique_if -{ - typedef unique_ptr<_Tp> __unique_single; +template <class _Tp> +struct __unique_if { + typedef unique_ptr<_Tp> __unique_single; }; -template<class _Tp> -struct __unique_if<_Tp[]> -{ - typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; +template <class _Tp> +struct __unique_if<_Tp[]> { + typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; }; -template<class _Tp, size_t _Np> -struct __unique_if<_Tp[_Np]> -{ - typedef void __unique_array_known_bound; +template <class _Tp, size_t _Np> +struct __unique_if<_Tp[_Np]> { + typedef void __unique_array_known_bound; }; template <class _Tp, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single make_unique(_Args&&... __args) { - return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); + return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound make_unique(size_t __n) { typedef __remove_extent_t<_Tp> _Up; return unique_ptr<_Tp>(new _Up[__n]()); } -template<class _Tp, class... _Args> - typename __unique_if<_Tp>::__unique_array_known_bound - make_unique(_Args&&...) = delete; +template <class _Tp, class... _Args> +typename __unique_if<_Tp>::__unique_array_known_bound make_unique(_Args&&...) = delete; #endif // _LIBCPP_STD_VER >= 14 @@ -716,32 +623,30 @@ make_unique_for_overwrite(size_t __n) { return unique_ptr<_Tp>(new __remove_extent_t<_Tp>[__n]); } -template<class _Tp, class... _Args> +template <class _Tp, class... _Args> typename __unique_if<_Tp>::__unique_array_known_bound make_unique_for_overwrite(_Args&&...) = delete; #endif // _LIBCPP_STD_VER >= 20 -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash; template <class _Tp, class _Dp> #ifdef _LIBCPP_CXX03_LANG struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > #else -struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< - unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > +struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > #endif { #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef unique_ptr<_Tp, _Dp> argument_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef unique_ptr<_Tp, _Dp> argument_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type; #endif - _LIBCPP_INLINE_VISIBILITY - size_t operator()(const unique_ptr<_Tp, _Dp>& __ptr) const - { - typedef typename unique_ptr<_Tp, _Dp>::pointer pointer; - return hash<pointer>()(__ptr.get()); - } + _LIBCPP_HIDE_FROM_ABI size_t operator()(const unique_ptr<_Tp, _Dp>& __ptr) const { + typedef typename unique_ptr<_Tp, _Dp>::pointer pointer; + return hash<pointer>()(__ptr.get()); + } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__memory/uses_allocator.h b/lib/libcxx/include/__memory/uses_allocator.h index f82ac17963..84310c3fa5 100644 --- a/lib/libcxx/include/__memory/uses_allocator.h +++ b/lib/libcxx/include/__memory/uses_allocator.h @@ -21,33 +21,26 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -struct __has_allocator_type -{ +struct __has_allocator_type { private: - template <class _Up> static false_type __test(...); - template <class _Up> static true_type __test(typename _Up::allocator_type* = 0); + template <class _Up> + static false_type __test(...); + template <class _Up> + static true_type __test(typename _Up::allocator_type* = 0); + public: - static const bool value = decltype(__test<_Tp>(0))::value; + static const bool value = decltype(__test<_Tp>(0))::value; }; template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> -struct __uses_allocator - : public integral_constant<bool, - is_convertible<_Alloc, typename _Tp::allocator_type>::value> -{ +struct __uses_allocator : public integral_constant<bool, is_convertible<_Alloc, typename _Tp::allocator_type>::value> { }; template <class _Tp, class _Alloc> -struct __uses_allocator<_Tp, _Alloc, false> - : public false_type -{ -}; +struct __uses_allocator<_Tp, _Alloc, false> : public false_type {}; template <class _Tp, class _Alloc> -struct _LIBCPP_TEMPLATE_VIS uses_allocator - : public __uses_allocator<_Tp, _Alloc> -{ -}; +struct _LIBCPP_TEMPLATE_VIS uses_allocator : public __uses_allocator<_Tp, _Alloc> {}; #if _LIBCPP_STD_VER >= 17 template <class _Tp, class _Alloc> diff --git a/lib/libcxx/include/__memory/uses_allocator_construction.h b/lib/libcxx/include/__memory/uses_allocator_construction.h index a2e4f6e26f..71ae5bcd32 100644 --- a/lib/libcxx/include/__memory/uses_allocator_construction.h +++ b/lib/libcxx/include/__memory/uses_allocator_construction.h @@ -12,6 +12,7 @@ #include <__config> #include <__memory/construct_at.h> #include <__memory/uses_allocator.h> +#include <__tuple/pair_like.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_same.h> #include <__type_traits/remove_cv.h> @@ -36,15 +37,19 @@ inline constexpr bool __is_std_pair = false; template <class _Type1, class _Type2> inline constexpr bool __is_std_pair<pair<_Type1, _Type2>> = true; -template <class _Type, class _Alloc, class... _Args, __enable_if_t<!__is_std_pair<_Type>, int> = 0> +template <class _Tp> +inline constexpr bool __is_cv_std_pair = __is_std_pair<remove_cv_t<_Tp>>; + +template <class _Type, class _Alloc, class... _Args, __enable_if_t<!__is_cv_std_pair<_Type>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept { - if constexpr (!uses_allocator_v<_Type, _Alloc> && is_constructible_v<_Type, _Args...>) { + if constexpr (!uses_allocator_v<remove_cv_t<_Type>, _Alloc> && is_constructible_v<_Type, _Args...>) { return std::forward_as_tuple(std::forward<_Args>(__args)...); - } else if constexpr (uses_allocator_v<_Type, _Alloc> && + } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> && is_constructible_v<_Type, allocator_arg_t, const _Alloc&, _Args...>) { return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(allocator_arg, __alloc, std::forward<_Args>(__args)...); - } else if constexpr (uses_allocator_v<_Type, _Alloc> && is_constructible_v<_Type, _Args..., const _Alloc&>) { + } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> && + is_constructible_v<_Type, _Args..., const _Alloc&>) { return std::forward_as_tuple(std::forward<_Args>(__args)..., __alloc); } else { static_assert( @@ -52,7 +57,7 @@ __uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noe } } -template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args( const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept { return std::make_tuple( @@ -71,12 +76,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args( std::forward<_Tuple2>(__y))); } -template <class _Pair, class _Alloc, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc) noexcept { return std::__uses_allocator_construction_args<_Pair>(__alloc, piecewise_construct, tuple<>{}, tuple<>{}); } -template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept { return std::__uses_allocator_construction_args<_Pair>( @@ -87,7 +92,7 @@ __uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) } # if _LIBCPP_STD_VER >= 23 -template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept { return std::__uses_allocator_construction_args<_Pair>( @@ -95,14 +100,14 @@ __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair } # endif -template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept { return std::__uses_allocator_construction_args<_Pair>( __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second)); } -template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept { return std::__uses_allocator_construction_args<_Pair>( @@ -113,7 +118,7 @@ __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pai } # if _LIBCPP_STD_VER >= 23 -template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0> +template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept { return std::__uses_allocator_construction_args<_Pair>( @@ -122,6 +127,20 @@ __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& std::forward_as_tuple(std::get<0>(std::move(__pair))), std::forward_as_tuple(std::get<1>(std::move(__pair)))); } + +template < class _Pair, + class _Alloc, + __pair_like _PairLike, + __enable_if_t<__is_cv_std_pair<_Pair> && !__is_specialization_of_subrange<remove_cvref_t<_PairLike>>::value, + int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr auto +__uses_allocator_construction_args(const _Alloc& __alloc, _PairLike&& __p) noexcept { + return std::__uses_allocator_construction_args<_Pair>( + __alloc, + piecewise_construct, + std::forward_as_tuple(std::get<0>(std::forward<_PairLike>(__p))), + std::forward_as_tuple(std::get<1>(std::forward<_PairLike>(__p)))); +} # endif namespace __uses_allocator_detail { @@ -139,23 +158,33 @@ template <class _Tp> inline constexpr bool __convertible_to_const_pair_ref = decltype(__uses_allocator_detail::__convertible_to_const_pair_ref_impl<_Tp>(0))::value; +# if _LIBCPP_STD_VER >= 23 +template <class _Tp, class _Up> +inline constexpr bool __uses_allocator_constraints = + __is_cv_std_pair<_Tp> && + (__is_specialization_of_subrange<remove_cvref_t<_Up>>::value || + (!__pair_like<_Up> && !__convertible_to_const_pair_ref<_Up>)); +# else +template <class _Tp, class _Up> +inline constexpr bool __uses_allocator_constraints = __is_cv_std_pair<_Tp> && !__convertible_to_const_pair_ref<_Up>; +# endif + } // namespace __uses_allocator_detail -template < - class _Pair, - class _Alloc, - class _Type, - __enable_if_t<__is_std_pair<_Pair> && !__uses_allocator_detail::__convertible_to_const_pair_ref<_Type>, int> = 0> +template < class _Pair, + class _Alloc, + class _Type, + __enable_if_t<__uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept; template <class _Type, class _Alloc, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr _Type __make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args); -template <class _Pair, - class _Alloc, - class _Type, - __enable_if_t<__is_std_pair<_Pair> && !__uses_allocator_detail::__convertible_to_const_pair_ref<_Type>, int>> +template < class _Pair, + class _Alloc, + class _Type, + __enable_if_t< __uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int>> _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept { struct __pair_constructor { diff --git a/lib/libcxx/include/__memory/voidify.h b/lib/libcxx/include/__memory/voidify.h index 39e10343f4..dbd083bd8c 100644 --- a/lib/libcxx/include/__memory/voidify.h +++ b/lib/libcxx/include/__memory/voidify.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <typename _Tp> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void* __voidify(_Tp& __from) { // Cast away cv-qualifiers to allow modifying elements of a range through const iterators. - return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__from))); + return const_cast<void*>(static_cast<const volatile void*>(std::addressof(__from))); } _LIBCPP_END_NAMESPACE_STD |
