diff options
author | Andrey Khalyavin <halyavin@gmail.com> | 2022-02-10 16:46:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:29 +0300 |
commit | f773626848a7c7456803654292e716b83d69cc12 (patch) | |
tree | db052dfcf9134f492bdbb962cb6c16cea58e1ed3 /contrib/libs/cxxsupp/libcxx/include/__memory | |
parent | f43ab775d197d300eb67bd4497632b909cd7c2a5 (diff) | |
download | ydb-f773626848a7c7456803654292e716b83d69cc12.tar.gz |
Restoring authorship annotation for Andrey Khalyavin <halyavin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__memory')
16 files changed, 4653 insertions, 4653 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/addressof.h b/contrib/libs/cxxsupp/libcxx/include/__memory/addressof.h index c45dedfaec..0bcbf9e0cc 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/addressof.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/addressof.h @@ -1,76 +1,76 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_ADDRESSOF_H -#define _LIBCPP___MEMORY_ADDRESSOF_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp> -inline _LIBCPP_CONSTEXPR_AFTER_CXX14 -_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY -_Tp* -addressof(_Tp& __x) _NOEXCEPT -{ - return __builtin_addressof(__x); -} - -#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) -// Objective-C++ Automatic Reference Counting uses qualified pointers -// that require special addressof() signatures. When -// _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 -{ - return &__x; -} - -#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__weak _Tp* -addressof(__weak _Tp& __x) _NOEXCEPT -{ - return &__x; -} -#endif - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__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 -{ - return &__x; -} -#endif - -#if !defined(_LIBCPP_CXX03_LANG) -template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_ADDRESSOF_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_ADDRESSOF_H +#define _LIBCPP___MEMORY_ADDRESSOF_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return __builtin_addressof(__x); +} + +#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _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 +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__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 +{ + return &__x; +} +#endif + +#if !defined(_LIBCPP_CXX03_LANG) +template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_ADDRESSOF_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/allocation_guard.h b/contrib/libs/cxxsupp/libcxx/include/__memory/allocation_guard.h index 6412677aaf..1198625bfd 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/allocation_guard.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/allocation_guard.h @@ -1,83 +1,83 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_ALLOCATION_GUARD_H -#define _LIBCPP___MEMORY_ALLOCATION_GUARD_H - -#include <__config> -#include <__memory/allocator_traits.h> -#include <cstddef> -#include <utility> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Helper class to allocate memory using an Allocator in an exception safe -// manner. -// -// The intended usage of this class is as follows: -// -// 0 -// 1 __allocation_guard<SomeAllocator> guard(alloc, 10); -// 2 do_some_initialization_that_may_throw(guard.__get()); -// 3 save_allocated_pointer_in_a_noexcept_operation(guard.__release_ptr()); -// 4 -// -// If line (2) throws an exception during initialization of the memory, the -// guard's destructor will be called, and the memory will be released using -// Allocator deallocation. Otherwise, we release the memory from the guard on -// line (3) in an operation that can't throw -- after that, the guard is not -// responsible for the memory anymore. -// -// This is similar to a unique_ptr, except it's easier to use with a -// custom allocator. -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 { - if (__ptr_ != nullptr) { - allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_); - } - } - - _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_; - } - -private: - _Alloc __alloc_; - _Size __n_; - _Pointer __ptr_; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_ALLOCATION_GUARD_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_ALLOCATION_GUARD_H +#define _LIBCPP___MEMORY_ALLOCATION_GUARD_H + +#include <__config> +#include <__memory/allocator_traits.h> +#include <cstddef> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Helper class to allocate memory using an Allocator in an exception safe +// manner. +// +// The intended usage of this class is as follows: +// +// 0 +// 1 __allocation_guard<SomeAllocator> guard(alloc, 10); +// 2 do_some_initialization_that_may_throw(guard.__get()); +// 3 save_allocated_pointer_in_a_noexcept_operation(guard.__release_ptr()); +// 4 +// +// If line (2) throws an exception during initialization of the memory, the +// guard's destructor will be called, and the memory will be released using +// Allocator deallocation. Otherwise, we release the memory from the guard on +// line (3) in an operation that can't throw -- after that, the guard is not +// responsible for the memory anymore. +// +// This is similar to a unique_ptr, except it's easier to use with a +// custom allocator. +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 { + if (__ptr_ != nullptr) { + allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_); + } + } + + _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_; + } + +private: + _Alloc __alloc_; + _Size __n_; + _Pointer __ptr_; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_ALLOCATION_GUARD_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator.h b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator.h index 7913a19c10..8a4f9b5300 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator.h @@ -1,251 +1,251 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_ALLOCATOR_H -#define _LIBCPP___MEMORY_ALLOCATOR_H - -#include <__config> -#include <__memory/allocator_traits.h> -#include <__utility/forward.h> -#include <cstddef> -#include <new> -#include <stdexcept> -#include <type_traits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp> class allocator; - -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) -template <> -class _LIBCPP_TEMPLATE_VIS allocator<void> -{ -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;}; -}; - -template <> -class _LIBCPP_TEMPLATE_VIS allocator<const void> -{ -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 - -// This class provides a non-trivial default constructor to the class that derives from it -// if the condition is satisfied. -// -// The second template parameter exists to allow giving a unique type to __non_trivial_if, -// which makes it possible to avoid breaking the ABI when making this a base class of an -// existing class. Without that, imagine we have classes D1 and D2, both of which used to -// have no base classes, but which now derive from __non_trivial_if. The layout of a class -// that inherits from both D1 and D2 will change because the two __non_trivial_if base -// classes are not allowed to share the same address. -// -// 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 { }; - -template <class _Unique> -struct __non_trivial_if<true, _Unique> { - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR __non_trivial_if() _NOEXCEPT { } -}; - -// allocator -// -// Note: For ABI compatibility between C++20 and previous standards, we make -// 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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - allocator() _NOEXCEPT _LIBCPP_DEFAULT - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - allocator(const allocator<_Up>&) _NOEXCEPT { } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - _Tp* allocate(size_t __n) { - if (__n > allocator_traits<allocator>::max_size(*this)) - __throw_length_error("allocator<T>::allocate(size_t n)" - " 'n' exceeds maximum supported size"); - 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))); - } - } - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { - if (__libcpp_is_constant_evaluated()) { - ::operator delete((void*)__p); - } else { - _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_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_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); - } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 - _Tp* allocate(size_t __n, const void*) { - return allocate(__n); - } - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return size_type(~0) / sizeof(_Tp); - } - - 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_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - 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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - allocator() _NOEXCEPT _LIBCPP_DEFAULT - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - allocator(const allocator<_Up>&) _NOEXCEPT { } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - const _Tp* allocate(size_t __n) { - if (__n > allocator_traits<allocator>::max_size(*this)) - __throw_length_error("allocator<const T>::allocate(size_t n)" - " 'n' exceeds maximum supported size"); - 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))); - } - } - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - 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)); - } - } - - // 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); - } - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 - const _Tp* allocate(size_t __n, const void*) { - return allocate(__n); - } - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return size_type(~0) / sizeof(_Tp); - } - - 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_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY - void destroy(pointer __p) { - __p->~_Tp(); - } -#endif -}; - -template <class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} - -template <class _Tp, class _Up> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_ALLOCATOR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_ALLOCATOR_H +#define _LIBCPP___MEMORY_ALLOCATOR_H + +#include <__config> +#include <__memory/allocator_traits.h> +#include <__utility/forward.h> +#include <cstddef> +#include <new> +#include <stdexcept> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> class allocator; + +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) +template <> +class _LIBCPP_TEMPLATE_VIS allocator<void> +{ +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;}; +}; + +template <> +class _LIBCPP_TEMPLATE_VIS allocator<const void> +{ +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 + +// This class provides a non-trivial default constructor to the class that derives from it +// if the condition is satisfied. +// +// The second template parameter exists to allow giving a unique type to __non_trivial_if, +// which makes it possible to avoid breaking the ABI when making this a base class of an +// existing class. Without that, imagine we have classes D1 and D2, both of which used to +// have no base classes, but which now derive from __non_trivial_if. The layout of a class +// that inherits from both D1 and D2 will change because the two __non_trivial_if base +// classes are not allowed to share the same address. +// +// 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 { }; + +template <class _Unique> +struct __non_trivial_if<true, _Unique> { + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __non_trivial_if() _NOEXCEPT { } +}; + +// allocator +// +// Note: For ABI compatibility between C++20 and previous standards, we make +// 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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT _LIBCPP_DEFAULT + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT { } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _Tp* allocate(size_t __n) { + if (__n > allocator_traits<allocator>::max_size(*this)) + __throw_length_error("allocator<T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + 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))); + } + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { + if (__libcpp_is_constant_evaluated()) { + ::operator delete((void*)__p); + } else { + _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_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_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); + } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 + _Tp* allocate(size_t __n, const void*) { + return allocate(__n); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { + return size_type(~0) / sizeof(_Tp); + } + + 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_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY + 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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT _LIBCPP_DEFAULT + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT { } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + const _Tp* allocate(size_t __n) { + if (__n > allocator_traits<allocator>::max_size(*this)) + __throw_length_error("allocator<const T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + 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))); + } + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + 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)); + } + } + + // 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); + } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 + const _Tp* allocate(size_t __n, const void*) { + return allocate(__n); + } + + _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { + return size_type(~0) / sizeof(_Tp); + } + + 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_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY + void destroy(pointer __p) { + __p->~_Tp(); + } +#endif +}; + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_ALLOCATOR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_arg_t.h b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_arg_t.h index f5a116dbbd..bbf62d76a1 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_arg_t.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_arg_t.h @@ -1,78 +1,78 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H -#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H - -#include <__config> -#include <__memory/uses_allocator.h> -#include <__utility/forward.h> -#include <type_traits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; - -#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) -extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; -#else -/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); -#endif - -#ifndef _LIBCPP_CXX03_LANG - -// allocator construction - -template <class _Tp, class _Alloc, class ..._Args> -struct __uses_alloc_ctor_imp -{ - typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _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 _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)...); -} - -// 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)...); -} - -// 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); -} - -#endif // _LIBCPP_CXX03_LANG - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H +#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H + +#include <__config> +#include <__memory/uses_allocator.h> +#include <__utility/forward.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; + +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) +extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; +#else +/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +#endif + +#ifndef _LIBCPP_CXX03_LANG + +// allocator construction + +template <class _Tp, class _Alloc, class ..._Args> +struct __uses_alloc_ctor_imp +{ + typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _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 _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)...); +} + +// 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)...); +} + +// 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); +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_traits.h b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_traits.h index f4c8fa02d6..8c5ababba5 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_traits.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/allocator_traits.h @@ -1,405 +1,405 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H -#define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H - -#include <__config> -#include <__memory/construct_at.h> -#include <__memory/pointer_traits.h> -#include <__utility/forward.h> -#include <limits> -#include <type_traits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_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, typename __void_t<typename _Tp:: PROPERTY >::type> : true_type { } - -// __pointer -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer); -template <class _Tp, class _Alloc, - class _RawAlloc = typename remove_reference<_Alloc>::type, - bool = __has_pointer<_RawAlloc>::value> -struct __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*; -}; - -// __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> -struct __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; -#else - 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> -struct __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; -#else - 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> -struct __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; -#else - 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> { }; -template <class _Alloc, class _DiffType> -struct __size_type<_Alloc, _DiffType, true> { - 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; -}; -template <class _Alloc, class _Ptr> -struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { - 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 { }; -template <class _Alloc> -struct __propagate_on_container_copy_assignment<_Alloc, true> { - 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 { }; -template <class _Alloc> -struct __propagate_on_container_move_assignment<_Alloc, true> { - 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 { }; -template <class _Alloc> -struct __propagate_on_container_swap<_Alloc, true> { - 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> { }; -template <class _Alloc> -struct __is_always_equal<_Alloc, true> { - 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 { }; -template <class _Tp, class _Up> -struct __has_rebind_other<_Tp, _Up, typename __void_t< - typename _Tp::template rebind<_Up>::other ->::type> : true_type { }; - -template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> -struct __allocator_traits_rebind { - using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other; -}; -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; -}; -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...>; -}; -_LIBCPP_SUPPRESS_DEPRECATED_POP - -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 { }; - -template <class _Alloc, class _SizeType, class _ConstVoidPtr> -struct __has_allocate_hint<_Alloc, _SizeType, _ConstVoidPtr, decltype( - (void)declval<_Alloc>().allocate(declval<_SizeType>(), declval<_ConstVoidPtr>()) -)> : true_type { }; - -// __has_construct -template <class, class _Alloc, class ..._Args> -struct __has_construct_impl : false_type { }; - -template <class _Alloc, class ..._Args> -struct __has_construct_impl<decltype( - (void)declval<_Alloc>().construct(declval<_Args>()...) -), _Alloc, _Args...> : true_type { }; - -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 { }; - -template <class _Alloc, class _Pointer> -struct __has_destroy<_Alloc, _Pointer, decltype( - (void)declval<_Alloc>().destroy(declval<_Pointer>()) -)> : true_type { }; - -// __has_max_size -template <class _Alloc, class = void> -struct __has_max_size : false_type { }; - -template <class _Alloc> -struct __has_max_size<_Alloc, decltype( - (void)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 { }; - -template <class _Alloc> -struct __has_select_on_container_copy_construction<_Alloc, decltype( - (void)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; - -#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> >; -#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>; - }; -#endif // _LIBCPP_CXX03_LANG - - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - 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_AFTER_CXX17 - 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_AFTER_CXX17 - static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) { - return __a.allocate(__n); - } - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - 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_AFTER_CXX17 - 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_AFTER_CXX17 - static void construct(allocator_type&, _Tp* __p, _Args&&... __args) { -#if _LIBCPP_STD_VER > 17 - _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_AFTER_CXX17 - 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_AFTER_CXX17 - static void destroy(allocator_type&, _Tp* __p) { -#if _LIBCPP_STD_VER > 17 - _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_AFTER_CXX17 - 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_AFTER_CXX17 - 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_AFTER_CXX17 - 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_AFTER_CXX17 - static allocator_type select_on_container_copy_construction(const allocator_type& __a) { - return __a; - } -}; - -template <class _Traits, class _Tp> -struct __rebind_alloc_helper { -#ifndef _LIBCPP_CXX03_LANG - using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; -#else - using type = typename _Traits::template rebind_alloc<_Tp>::other; -#endif -}; - -// __is_default_allocator -template <class _Tp> -struct __is_default_allocator : false_type { }; - -template <class> class allocator; - -template <class _Tp> -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> -{ }; - -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 { }; - -// __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 - > -{ }; - -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> -{ }; - -#undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H +#define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H + +#include <__config> +#include <__memory/construct_at.h> +#include <__memory/pointer_traits.h> +#include <__utility/forward.h> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_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, typename __void_t<typename _Tp:: PROPERTY >::type> : true_type { } + +// __pointer +_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer); +template <class _Tp, class _Alloc, + class _RawAlloc = typename remove_reference<_Alloc>::type, + bool = __has_pointer<_RawAlloc>::value> +struct __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*; +}; + +// __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> +struct __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; +#else + 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> +struct __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; +#else + 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> +struct __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; +#else + 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> { }; +template <class _Alloc, class _DiffType> +struct __size_type<_Alloc, _DiffType, true> { + 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; +}; +template <class _Alloc, class _Ptr> +struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { + 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 { }; +template <class _Alloc> +struct __propagate_on_container_copy_assignment<_Alloc, true> { + 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 { }; +template <class _Alloc> +struct __propagate_on_container_move_assignment<_Alloc, true> { + 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 { }; +template <class _Alloc> +struct __propagate_on_container_swap<_Alloc, true> { + 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> { }; +template <class _Alloc> +struct __is_always_equal<_Alloc, true> { + 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 { }; +template <class _Tp, class _Up> +struct __has_rebind_other<_Tp, _Up, typename __void_t< + typename _Tp::template rebind<_Up>::other +>::type> : true_type { }; + +template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> +struct __allocator_traits_rebind { + using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other; +}; +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; +}; +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...>; +}; +_LIBCPP_SUPPRESS_DEPRECATED_POP + +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 { }; + +template <class _Alloc, class _SizeType, class _ConstVoidPtr> +struct __has_allocate_hint<_Alloc, _SizeType, _ConstVoidPtr, decltype( + (void)declval<_Alloc>().allocate(declval<_SizeType>(), declval<_ConstVoidPtr>()) +)> : true_type { }; + +// __has_construct +template <class, class _Alloc, class ..._Args> +struct __has_construct_impl : false_type { }; + +template <class _Alloc, class ..._Args> +struct __has_construct_impl<decltype( + (void)declval<_Alloc>().construct(declval<_Args>()...) +), _Alloc, _Args...> : true_type { }; + +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 { }; + +template <class _Alloc, class _Pointer> +struct __has_destroy<_Alloc, _Pointer, decltype( + (void)declval<_Alloc>().destroy(declval<_Pointer>()) +)> : true_type { }; + +// __has_max_size +template <class _Alloc, class = void> +struct __has_max_size : false_type { }; + +template <class _Alloc> +struct __has_max_size<_Alloc, decltype( + (void)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 { }; + +template <class _Alloc> +struct __has_select_on_container_copy_construction<_Alloc, decltype( + (void)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; + +#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> >; +#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>; + }; +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + 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_AFTER_CXX17 + 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_AFTER_CXX17 + static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) { + return __a.allocate(__n); + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + 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_AFTER_CXX17 + 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_AFTER_CXX17 + static void construct(allocator_type&, _Tp* __p, _Args&&... __args) { +#if _LIBCPP_STD_VER > 17 + _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_AFTER_CXX17 + 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_AFTER_CXX17 + static void destroy(allocator_type&, _Tp* __p) { +#if _LIBCPP_STD_VER > 17 + _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_AFTER_CXX17 + 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_AFTER_CXX17 + 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_AFTER_CXX17 + 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_AFTER_CXX17 + static allocator_type select_on_container_copy_construction(const allocator_type& __a) { + return __a; + } +}; + +template <class _Traits, class _Tp> +struct __rebind_alloc_helper { +#ifndef _LIBCPP_CXX03_LANG + using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; +#else + using type = typename _Traits::template rebind_alloc<_Tp>::other; +#endif +}; + +// __is_default_allocator +template <class _Tp> +struct __is_default_allocator : false_type { }; + +template <class> class allocator; + +template <class _Tp> +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> +{ }; + +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 { }; + +// __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 + > +{ }; + +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> +{ }; + +#undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/auto_ptr.h b/contrib/libs/cxxsupp/libcxx/include/__memory/auto_ptr.h index 492cbabab8..8f82c35764 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/auto_ptr.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/auto_ptr.h @@ -1,81 +1,81 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_AUTO_PTR_H -#define _LIBCPP___MEMORY_AUTO_PTR_H - -#include <__config> -#include <__nullptr> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp> -struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref -{ - _Tp* __ptr_; -}; - -template<class _Tp> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr -{ -private: - _Tp* __ptr_; -public: - 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_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_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());} -}; - -template <> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> -{ -public: - typedef void element_type; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_AUTO_PTR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_AUTO_PTR_H +#define _LIBCPP___MEMORY_AUTO_PTR_H + +#include <__config> +#include <__nullptr> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref +{ + _Tp* __ptr_; +}; + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr +{ +private: + _Tp* __ptr_; +public: + 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_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_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());} +}; + +template <> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> +{ +public: + typedef void element_type; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_AUTO_PTR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h b/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h index fd1fcbe5bf..b28e983947 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h @@ -1,196 +1,196 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_COMPRESSED_PAIR_H -#define _LIBCPP___MEMORY_COMPRESSED_PAIR_H - -#include <__config> -#include <__utility/forward.h> -#include <tuple> // needed in c++03 for some constructors -#include <type_traits> -#include <utility> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Tag used to default initialize one or both of the pair's elements. -struct __default_init_tag {}; -struct __value_init_tag {}; - -template <class _Tp, int _Idx, - bool _CanBeEmptyBase = - is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> -struct __compressed_pair_elem { - typedef _Tp _ParamT; - typedef _Tp& reference; - typedef const _Tp& const_reference; - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __compressed_pair_elem(__value_init_tag) : __value_() {} - - template <class _Up, class = typename enable_if< - !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value - >::type> - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR explicit - __compressed_pair_elem(_Up&& __u) - : __value_(_VSTD::forward<_Up>(__u)) - { - } - - -#ifndef _LIBCPP_CXX03_LANG - template <class... _Args, size_t... _Indexes> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, - __tuple_indices<_Indexes...>) - : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} -#endif - - - _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } - _LIBCPP_INLINE_VISIBILITY - const_reference __get() const _NOEXCEPT { return __value_; } - -private: - _Tp __value_; -}; - -template <class _Tp, int _Idx> -struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { - typedef _Tp _ParamT; - typedef _Tp& reference; - typedef const _Tp& const_reference; - typedef _Tp __value_type; - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __compressed_pair_elem(__value_init_tag) : __value_type() {} - - template <class _Up, class = typename enable_if< - !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value - >::type> - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR explicit - __compressed_pair_elem(_Up&& __u) - : __value_type(_VSTD::forward<_Up>(__u)) - {} - -#ifndef _LIBCPP_CXX03_LANG - template <class... _Args, size_t... _Indexes> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, - __tuple_indices<_Indexes...>) - : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} -#endif - - _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } - _LIBCPP_INLINE_VISIBILITY - const_reference __get() const _NOEXCEPT { return *this; } -}; - -template <class _T1, class _T2> -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"); - - typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T1, 0> _Base1; - typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T2, 1> _Base2; - - template <bool _Dummy = true, - class = typename enable_if< - __dependent_type<is_default_constructible<_T1>, _Dummy>::value && - __dependent_type<is_default_constructible<_T2>, _Dummy>::value - >::type - > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} - - template <class _U1, class _U2> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __compressed_pair(_U1&& __t1, _U2&& __t2) - : _Base1(_VSTD::forward<_U1>(__t1)), _Base2(_VSTD::forward<_U2>(__t2)) {} - -#ifndef _LIBCPP_CXX03_LANG - template <class... _Args1, class... _Args2> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) - : _Base1(__pc, _VSTD::move(__first_args), - typename __make_tuple_indices<sizeof...(_Args1)>::type()), - _Base2(__pc, _VSTD::move(__second_args), - typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} -#endif - - _LIBCPP_INLINE_VISIBILITY - typename _Base1::reference first() _NOEXCEPT { - return static_cast<_Base1&>(*this).__get(); - } - - _LIBCPP_INLINE_VISIBILITY - typename _Base1::const_reference first() const _NOEXCEPT { - return static_cast<_Base1 const&>(*this).__get(); - } - - _LIBCPP_INLINE_VISIBILITY - typename _Base2::reference second() _NOEXCEPT { - return static_cast<_Base2&>(*this).__get(); - } - - _LIBCPP_INLINE_VISIBILITY - typename _Base2::const_reference second() const _NOEXCEPT { - return static_cast<_Base2 const&>(*this).__get(); - } - - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base1*>(__pair); - } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base2*>(__pair); - } - - _LIBCPP_INLINE_VISIBILITY - void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { - using _VSTD::swap; - swap(first(), __x.first()); - swap(second(), __x.second()); - } -}; - -template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY -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); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_COMPRESSED_PAIR_H +#define _LIBCPP___MEMORY_COMPRESSED_PAIR_H + +#include <__config> +#include <__utility/forward.h> +#include <tuple> // needed in c++03 for some constructors +#include <type_traits> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Tag used to default initialize one or both of the pair's elements. +struct __default_init_tag {}; +struct __value_init_tag {}; + +template <class _Tp, int _Idx, + bool _CanBeEmptyBase = + is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> +struct __compressed_pair_elem { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __compressed_pair_elem(__value_init_tag) : __value_() {} + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR explicit + __compressed_pair_elem(_Up&& __u) + : __value_(_VSTD::forward<_Up>(__u)) + { + } + + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#endif + + + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return __value_; } + +private: + _Tp __value_; +}; + +template <class _Tp, int _Idx> +struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp __value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __compressed_pair_elem(__value_init_tag) : __value_type() {} + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR explicit + __compressed_pair_elem(_Up&& __u) + : __value_type(_VSTD::forward<_Up>(__u)) + {} + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#endif + + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return *this; } +}; + +template <class _T1, class _T2> +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"); + + typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T1, 0> _Base1; + typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T2, 1> _Base2; + + template <bool _Dummy = true, + class = typename enable_if< + __dependent_type<is_default_constructible<_T1>, _Dummy>::value && + __dependent_type<is_default_constructible<_T2>, _Dummy>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} + + template <class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __compressed_pair(_U1&& __t1, _U2&& __t2) + : _Base1(_VSTD::forward<_U1>(__t1)), _Base2(_VSTD::forward<_U2>(__t2)) {} + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args1, class... _Args2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, + tuple<_Args2...> __second_args) + : _Base1(__pc, _VSTD::move(__first_args), + typename __make_tuple_indices<sizeof...(_Args1)>::type()), + _Base2(__pc, _VSTD::move(__second_args), + typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + typename _Base1::reference first() _NOEXCEPT { + return static_cast<_Base1&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base1::const_reference first() const _NOEXCEPT { + return static_cast<_Base1 const&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base2::reference second() _NOEXCEPT { + return static_cast<_Base2&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base2::const_reference second() const _NOEXCEPT { + return static_cast<_Base2 const&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { + return static_cast<_Base1*>(__pair); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { + return static_cast<_Base2*>(__pair); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value) + { + using _VSTD::swap; + swap(first(), __x.first()); + swap(second(), __x.second()); + } +}; + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +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); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h b/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h index 789677d7a6..720fce96b9 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h @@ -1,85 +1,85 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H -#define _LIBCPP___MEMORY_CONSTRUCT_AT_H - -#include <__config> -#include <__debug> -#include <__iterator/access.h> -#include <__memory/addressof.h> -#include <__utility/forward.h> -#include <type_traits> -#include <utility> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// construct_at - -#if _LIBCPP_STD_VER > 17 - -template<class _Tp, class ..._Args, class = decltype( - ::new (declval<void*>()) _Tp(declval<_Args>()...) -)> -_LIBCPP_INLINE_VISIBILITY -constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { - _LIBCPP_ASSERT(__location, "null pointer given to construct_at"); - return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...); -} - -#endif - -// destroy_at - -#if _LIBCPP_STD_VER > 14 - -template <class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy(_ForwardIterator, _ForwardIterator); - -template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); - __loc->~_Tp(); -} - -#if _LIBCPP_STD_VER > 17 -template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); - _VSTD::destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc)); -} -#endif - -template <class _ForwardIterator> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy(_ForwardIterator __first, _ForwardIterator __last) { - for (; __first != __last; ++__first) - _VSTD::destroy_at(_VSTD::addressof(*__first)); -} - -template <class _ForwardIterator, class _Size> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { - for (; __n > 0; (void)++__first, --__n) - _VSTD::destroy_at(_VSTD::addressof(*__first)); - return __first; -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H +#define _LIBCPP___MEMORY_CONSTRUCT_AT_H + +#include <__config> +#include <__debug> +#include <__iterator/access.h> +#include <__memory/addressof.h> +#include <__utility/forward.h> +#include <type_traits> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// construct_at + +#if _LIBCPP_STD_VER > 17 + +template<class _Tp, class ..._Args, class = decltype( + ::new (declval<void*>()) _Tp(declval<_Args>()...) +)> +_LIBCPP_INLINE_VISIBILITY +constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { + _LIBCPP_ASSERT(__location, "null pointer given to construct_at"); + return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...); +} + +#endif + +// destroy_at + +#if _LIBCPP_STD_VER > 14 + +template <class _ForwardIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void destroy(_ForwardIterator, _ForwardIterator); + +template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); + __loc->~_Tp(); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); + _VSTD::destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc)); +} +#endif + +template <class _ForwardIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + _VSTD::destroy_at(_VSTD::addressof(*__first)); +} + +template <class _ForwardIterator, class _Size> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { + for (; __n > 0; (void)++__first, --__n) + _VSTD::destroy_at(_VSTD::addressof(*__first)); + return __first; +} + +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_safety.h b/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_safety.h index e72080393d..7eae4f63d5 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_safety.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_safety.h @@ -1,52 +1,52 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_POINTER_SAFETY_H -#define _LIBCPP___MEMORY_POINTER_SAFETY_H - -#include <__config> -#include <cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if !defined(_LIBCPP_CXX03_LANG) - -enum class pointer_safety : unsigned char { - relaxed, - preferred, - strict -}; - -inline _LIBCPP_INLINE_VISIBILITY -pointer_safety get_pointer_safety() _NOEXCEPT { - return pointer_safety::relaxed; -} - -_LIBCPP_FUNC_VIS void declare_reachable(void* __p); -_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); -_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); -_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Tp* -undeclare_reachable(_Tp* __p) -{ - return static_cast<_Tp*>(__undeclare_reachable(__p)); -} - -#endif // !C++03 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_POINTER_SAFETY_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_POINTER_SAFETY_H +#define _LIBCPP___MEMORY_POINTER_SAFETY_H + +#include <__config> +#include <cstddef> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_CXX03_LANG) + +enum class pointer_safety : unsigned char { + relaxed, + preferred, + strict +}; + +inline _LIBCPP_INLINE_VISIBILITY +pointer_safety get_pointer_safety() _NOEXCEPT { + return pointer_safety::relaxed; +} + +_LIBCPP_FUNC_VIS void declare_reachable(void* __p); +_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); +_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); +_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +undeclare_reachable(_Tp* __p) +{ + return static_cast<_Tp*>(__undeclare_reachable(__p)); +} + +#endif // !C++03 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_POINTER_SAFETY_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_traits.h b/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_traits.h index 53b2c32eda..6c1da3548d 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_traits.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/pointer_traits.h @@ -1,220 +1,220 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_POINTER_TRAITS_H -#define _LIBCPP___MEMORY_POINTER_TRAITS_H - -#include <__config> -#include <__memory/addressof.h> -#include <type_traits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp, class = void> -struct __has_element_type : false_type {}; - -template <class _Tp> -struct __has_element_type<_Tp, - typename __void_t<typename _Tp::element_type>::type> : true_type {}; - -template <class _Ptr, bool = __has_element_type<_Ptr>::value> -struct __pointer_traits_element_type; - -template <class _Ptr> -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...>, false> -{ - typedef _LIBCPP_NODEBUG _Tp type; -}; - -template <class _Tp, class = void> -struct __has_difference_type : false_type {}; - -template <class _Tp> -struct __has_difference_type<_Tp, - typename __void_t<typename _Tp::difference_type>::type> : true_type {}; - -template <class _Ptr, bool = __has_difference_type<_Ptr>::value> -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; -}; - -template <class _Tp, class _Up> -struct __has_rebind -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Xp> static __two __test(...); - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - // Fix for MSVC which allows to reference private types. Wrap into declval to prevent that. - template <class _Xp> static char __test(decltype(_VSTD::declval<typename _Xp::template rebind<_Up>*>()) = 0); - _LIBCPP_SUPPRESS_DEPRECATED_POP -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; - -template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> -struct __pointer_traits_rebind -{ -#ifndef _LIBCPP_CXX03_LANG - typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type; -#else - 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> -{ -#ifndef _LIBCPP_CXX03_LANG - typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type; -#else - 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 <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; - -#ifndef _LIBCPP_CXX03_LANG - 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;}; -#endif // _LIBCPP_CXX03_LANG - -private: - struct __nat {}; -public: - _LIBCPP_INLINE_VISIBILITY - static pointer pointer_to(typename conditional<is_void<element_type>::value, - __nat, element_type>::type& __r) - {return pointer::pointer_to(__r);} -}; - -template <class _Tp> -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*; -#else - template <class _Up> struct rebind {typedef _Up* other;}; -#endif - -private: - struct __nat {}; -public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - static pointer pointer_to(typename conditional<is_void<element_type>::value, - __nat, element_type>::type& __r) _NOEXCEPT - {return _VSTD::addressof(__r);} -}; - -template <class _From, class _To> -struct __rebind_pointer { -#ifndef _LIBCPP_CXX03_LANG - typedef typename pointer_traits<_From>::template rebind<_To> type; -#else - typedef typename pointer_traits<_From>::template rebind<_To>::other type; -#endif -}; - -// to_address - -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; -} - -// enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers -template <class _Pointer, class = __enable_if_t< - !is_pointer<_Pointer>::value && !is_array<_Pointer>::value && !is_function<_Pointer>::value -> > -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type -__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(declval<const _Pointer&>().operator->())) - __call(const _Pointer& __p) _NOEXCEPT { - return _VSTD::__to_address(__p.operator->()); - } -}; - -template <class _Pointer> -struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))> { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - static decltype(pointer_traits<_Pointer>::to_address(declval<const _Pointer&>())) - __call(const _Pointer& __p) _NOEXCEPT { - return pointer_traits<_Pointer>::to_address(__p); - } -}; - -#if _LIBCPP_STD_VER > 17 -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY constexpr -auto to_address(_Tp *__p) noexcept { - return _VSTD::__to_address(__p); -} - -template <class _Pointer> -inline _LIBCPP_INLINE_VISIBILITY constexpr -auto to_address(const _Pointer& __p) noexcept { - return _VSTD::__to_address(__p); -} -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_POINTER_TRAITS_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_POINTER_TRAITS_H +#define _LIBCPP___MEMORY_POINTER_TRAITS_H + +#include <__config> +#include <__memory/addressof.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class = void> +struct __has_element_type : false_type {}; + +template <class _Tp> +struct __has_element_type<_Tp, + typename __void_t<typename _Tp::element_type>::type> : true_type {}; + +template <class _Ptr, bool = __has_element_type<_Ptr>::value> +struct __pointer_traits_element_type; + +template <class _Ptr> +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...>, false> +{ + typedef _LIBCPP_NODEBUG _Tp type; +}; + +template <class _Tp, class = void> +struct __has_difference_type : false_type {}; + +template <class _Tp> +struct __has_difference_type<_Tp, + typename __void_t<typename _Tp::difference_type>::type> : true_type {}; + +template <class _Ptr, bool = __has_difference_type<_Ptr>::value> +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; +}; + +template <class _Tp, class _Up> +struct __has_rebind +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Xp> static __two __test(...); + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + // Fix for MSVC which allows to reference private types. Wrap into declval to prevent that. + template <class _Xp> static char __test(decltype(_VSTD::declval<typename _Xp::template rebind<_Up>*>()) = 0); + _LIBCPP_SUPPRESS_DEPRECATED_POP +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> +struct __pointer_traits_rebind +{ +#ifndef _LIBCPP_CXX03_LANG + typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type; +#else + 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> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type; +#else + 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 <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; + +#ifndef _LIBCPP_CXX03_LANG + 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;}; +#endif // _LIBCPP_CXX03_LANG + +private: + struct __nat {}; +public: + _LIBCPP_INLINE_VISIBILITY + static pointer pointer_to(typename conditional<is_void<element_type>::value, + __nat, element_type>::type& __r) + {return pointer::pointer_to(__r);} +}; + +template <class _Tp> +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*; +#else + template <class _Up> struct rebind {typedef _Up* other;}; +#endif + +private: + struct __nat {}; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + static pointer pointer_to(typename conditional<is_void<element_type>::value, + __nat, element_type>::type& __r) _NOEXCEPT + {return _VSTD::addressof(__r);} +}; + +template <class _From, class _To> +struct __rebind_pointer { +#ifndef _LIBCPP_CXX03_LANG + typedef typename pointer_traits<_From>::template rebind<_To> type; +#else + typedef typename pointer_traits<_From>::template rebind<_To>::other type; +#endif +}; + +// to_address + +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; +} + +// enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers +template <class _Pointer, class = __enable_if_t< + !is_pointer<_Pointer>::value && !is_array<_Pointer>::value && !is_function<_Pointer>::value +> > +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type +__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(declval<const _Pointer&>().operator->())) + __call(const _Pointer& __p) _NOEXCEPT { + return _VSTD::__to_address(__p.operator->()); + } +}; + +template <class _Pointer> +struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))> { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + static decltype(pointer_traits<_Pointer>::to_address(declval<const _Pointer&>())) + __call(const _Pointer& __p) _NOEXCEPT { + return pointer_traits<_Pointer>::to_address(__p); + } +}; + +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY constexpr +auto to_address(_Tp *__p) noexcept { + return _VSTD::__to_address(__p); +} + +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY constexpr +auto to_address(const _Pointer& __p) noexcept { + return _VSTD::__to_address(__p); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_POINTER_TRAITS_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/raw_storage_iterator.h b/contrib/libs/cxxsupp/libcxx/include/__memory/raw_storage_iterator.h index abe9677cb6..60de8b305a 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/raw_storage_iterator.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/raw_storage_iterator.h @@ -1,68 +1,68 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H -#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H - -#include <__config> -#include <__memory/addressof.h> -#include <cstddef> -#include <iterator> -#include <utility> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) - -_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) - : public iterator<output_iterator_tag, void, void, void, void> -#endif -{ -_LIBCPP_SUPPRESS_DEPRECATED_POP -private: - _OutputIterator __x_; -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; -#if _LIBCPP_STD_VER > 17 - 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 -}; - -#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H +#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H + +#include <__config> +#include <__memory/addressof.h> +#include <cstddef> +#include <iterator> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) + +_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) + : public iterator<output_iterator_tag, void, void, void, void> +#endif +{ +_LIBCPP_SUPPRESS_DEPRECATED_POP +private: + _OutputIterator __x_; +public: + typedef output_iterator_tag iterator_category; + typedef void value_type; +#if _LIBCPP_STD_VER > 17 + 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 +}; + +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/shared_ptr.h b/contrib/libs/cxxsupp/libcxx/include/__memory/shared_ptr.h index 6d844760c8..d78d5f0ce4 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/shared_ptr.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/shared_ptr.h @@ -1,1903 +1,1903 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_SHARED_PTR_H -#define _LIBCPP___MEMORY_SHARED_PTR_H - -#include <__availability> -#include <__config> -#include <__functional_base> -#include <__functional/binary_function.h> -#include <__functional/operations.h> -#include <__functional/reference_wrapper.h> -#include <__memory/addressof.h> -#include <__memory/allocation_guard.h> -#include <__memory/allocator_traits.h> -#include <__memory/allocator.h> -#include <__memory/compressed_pair.h> -#include <__memory/pointer_traits.h> -#include <__memory/unique_ptr.h> -#include <__utility/forward.h> -#include <cstddef> -#include <cstdlib> // abort -#include <iosfwd> -#include <stdexcept> -#include <typeinfo> -#include <type_traits> -#include <utility> -#if !defined(_LIBCPP_HAS_NO_THREADS) //!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) -# include <atomic> -#endif - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) -# include <__memory/auto_ptr.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Alloc> -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; -private: - _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_);} -}; - -// 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 -#elif defined(_LIBCPP_COMPILER_GCC) -# 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) && \ - (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) - return __atomic_load_n(__value, __ATOMIC_RELAXED); -#else - 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) && \ - (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) - return __atomic_load_n(__value, __ATOMIC_ACQUIRE); -#else - return *__value; -#endif -} - -#ifndef _LIBCPP_COMPILER_MSVC -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _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); -#else - return __t += 1; -#endif -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _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); -#else - return __t -= 1; -#endif -} -#endif - -class _LIBCPP_EXCEPTION_ABI bad_weak_ptr - : public std::exception -{ -public: - bad_weak_ptr() _NOEXCEPT = default; - bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; - virtual ~bad_weak_ptr() _NOEXCEPT; - virtual const char* what() const _NOEXCEPT; -}; - -_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY -void __throw_bad_weak_ptr() -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_weak_ptr(); -#else - _VSTD::abort(); -#endif -} - -template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; - -class _LIBCPP_TYPE_VIS __shared_count -{ - __shared_count(const __shared_count&); - __shared_count& operator=(const __shared_count&); - -protected: -#ifdef _LIBCPP_HAS_NO_THREADS - typedef long __atomic_count; -#else - typedef atomic<long> __atomic_count; -#endif - __atomic_count __shared_owners_; - - virtual ~__shared_count(); -private: - virtual void __on_zero_shared() _NOEXCEPT = 0; - -public: - _LIBCPP_INLINE_VISIBILITY - explicit __shared_count(long __refs = 0) _NOEXCEPT - : __shared_owners_(__refs) {} - -#if defined(_LIBCPP_BUILDING_LIBRARY) && \ - defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) - void __add_shared() _NOEXCEPT; - bool __release_shared() _NOEXCEPT; -#else - _LIBCPP_INLINE_VISIBILITY - void __add_shared() _NOEXCEPT { -#ifdef _LIBCPP_HAS_NO_THREADS - __libcpp_atomic_refcount_increment(__shared_owners_); -#else - __shared_owners_++; -#endif - } - _LIBCPP_INLINE_VISIBILITY - bool __release_shared() _NOEXCEPT { -#ifdef _LIBCPP_HAS_NO_THREADS - if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { -#else - if (--__shared_owners_ == -1) { -#endif - __on_zero_shared(); - return true; - } - return false; - } -#endif - _LIBCPP_INLINE_VISIBILITY - long use_count() const _NOEXCEPT { -#ifdef _LIBCPP_HAS_NO_THREADS - return __libcpp_relaxed_load(&__shared_owners_) + 1; -#else - return __shared_owners_.load(memory_order_relaxed) + 1; -#endif - } -}; - -class _LIBCPP_TYPE_VIS __shared_weak_count - : private __shared_count -{ -#ifdef _LIBCPP_HAS_NO_THREADS - typedef long __atomic_count; -#else - typedef atomic<long> __atomic_count; -#endif - __atomic_count __shared_weak_owners_; - -public: - _LIBCPP_INLINE_VISIBILITY - explicit __shared_weak_count(long __refs = 0) _NOEXCEPT - : __shared_count(__refs), - __shared_weak_owners_(__refs) {} -protected: - virtual ~__shared_weak_count(); - -public: -#if defined(_LIBCPP_BUILDING_LIBRARY) && \ - defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) - 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 { -#ifdef _LIBCPP_HAS_NO_THREADS - __libcpp_atomic_refcount_increment(__shared_weak_owners_); -#else - __shared_weak_owners_++; -#endif - } - _LIBCPP_INLINE_VISIBILITY - 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; - - virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; -private: - 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_; -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)) {} - -#ifndef _LIBCPP_NO_RTTI - virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; -#endif - -private: - virtual void __on_zero_shared() _NOEXCEPT; - virtual void __on_zero_shared_weak() _NOEXCEPT; -}; - -#ifndef _LIBCPP_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; -} - -#endif // _LIBCPP_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(); -} - -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; - - _Al __a(__data_.second()); - __data_.second().~_Alloc(); - __a.deallocate(_PTraits::pointer_to(*this), 1); -} - -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 > 17 - 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(); } - -private: - virtual void __on_zero_shared() _NOEXCEPT { -#if _LIBCPP_STD_VER > 17 - 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 - } - - virtual void __on_zero_shared_weak() _NOEXCEPT { - 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(_VSTD::move(__a)); - } - _LIBCPP_HIDE_FROM_ABI ~_Storage() { - __get_alloc()->~_Alloc(); - } - _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_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_; -}; - -struct __shared_ptr_dummy_rebind_allocator_type; -template <> -class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> -{ -public: - template <class _Other> - struct rebind - { - typedef allocator<_Other> other; - }; -}; - -template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; - -template<class _Tp, class _Up> -struct __compatible_with -#if _LIBCPP_STD_VER > 14 - : is_convertible<remove_extent_t<_Tp>*, remove_extent_t<_Up>*> {}; -#else - : is_convertible<_Tp*, _Up*> {}; -#endif // _LIBCPP_STD_VER > 14 - -template <class _Ptr, class = void> -struct __is_deletable : false_type { }; -template <class _Ptr> -struct __is_deletable<_Ptr, decltype(delete declval<_Ptr>())> : true_type { }; - -template <class _Ptr, class = void> -struct __is_array_deletable : false_type { }; -template <class _Ptr> -struct __is_array_deletable<_Ptr, decltype(delete[] declval<_Ptr>())> : true_type { }; - -template <class _Dp, class _Pt, - class = decltype(declval<_Dp>()(declval<_Pt>()))> -static true_type __well_formed_deleter_test(int); - -template <class, class> -static false_type __well_formed_deleter_test(...); - -template <class _Dp, class _Pt> -struct __well_formed_deleter : decltype(__well_formed_deleter_test<_Dp, _Pt>(0)) {}; - -template<class _Dp, class _Tp, class _Yp> -struct __shared_ptr_deleter_ctor_reqs -{ - static const bool value = __compatible_with<_Tp, _Yp>::value && - is_move_constructible<_Dp>::value && - __well_formed_deleter<_Dp, _Tp*>::value; -}; - -#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI) -# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) -#else -# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI -#endif - -template<class _Tp> -class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr -{ -public: -#if _LIBCPP_STD_VER > 14 - typedef weak_ptr<_Tp> weak_type; - typedef remove_extent_t<_Tp> element_type; -#else - typedef _Tp element_type; -#endif - -private: - element_type* __ptr_; - __shared_weak_count* __cntrl_; - - struct __nat {int __for_bool_;}; -public: - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; - - template<class _Yp, class = __enable_if_t< - _And< - __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*> > -#endif - >::value - > > - 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> - shared_ptr(_Yp* __p, _Dp __d, - typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat()); - template<class _Yp, class _Dp, class _Alloc> - shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, - typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat()); - template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); - template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); - template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - shared_ptr(const shared_ptr& __r) _NOEXCEPT; - template<class _Yp> - _LIBCPP_INLINE_VISIBILITY - shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) - _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - shared_ptr(shared_ptr&& __r) _NOEXCEPT; - template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) - _NOEXCEPT; - template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template<class _Yp> - shared_ptr(auto_ptr<_Yp>&& __r, - typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); -#endif - template <class _Yp, class _Dp> - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, - __nat - >::type = __nat()); - template <class _Yp, class _Dp> - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, - __nat - >::type = __nat()); - - ~shared_ptr(); - - _LIBCPP_INLINE_VISIBILITY - shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, - shared_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, - shared_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(shared_ptr<_Yp>&& __r); -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) - template<class _Yp> - _LIBCPP_INLINE_VISIBILITY - typename enable_if - < - !is_array<_Yp>::value && - is_convertible<_Yp*, typename _VSTD::shared_ptr<_Tp>::element_type*>::value, - shared_ptr - >::type& - operator=(auto_ptr<_Yp>&& __r); -#endif - template <class _Yp, class _Dp> - typename enable_if - < - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, typename _VSTD::shared_ptr<_Tp>::element_type*>::value, - shared_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(unique_ptr<_Yp, _Dp>&& __r); - - _LIBCPP_INLINE_VISIBILITY - void swap(shared_ptr& __r) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - void reset() _NOEXCEPT; - template<class _Yp> - typename enable_if - < - __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, - void - >::type - _LIBCPP_INLINE_VISIBILITY - reset(_Yp* __p); - template<class _Yp, class _Dp> - typename enable_if - < - __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, - void - >::type - _LIBCPP_INLINE_VISIBILITY - reset(_Yp* __p, _Dp __d); - template<class _Yp, class _Dp, class _Alloc> - typename enable_if - < - __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, - void - >::type - _LIBCPP_INLINE_VISIBILITY - reset(_Yp* __p, _Dp __d, _Alloc __a); - - _LIBCPP_INLINE_VISIBILITY - element_type* get() const _NOEXCEPT {return __ptr_;} - _LIBCPP_INLINE_VISIBILITY - typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT - {return *__ptr_;} - _LIBCPP_INLINE_VISIBILITY - 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_INLINE_VISIBILITY - long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} - _LIBCPP_INLINE_VISIBILITY - bool unique() const _NOEXCEPT {return use_count() == 1;} - _LIBCPP_INLINE_VISIBILITY - explicit operator bool() const _NOEXCEPT {return get() != nullptr;} - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT - {return __cntrl_ < __p.__cntrl_;} - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT - {return __cntrl_ < __p.__cntrl_;} - _LIBCPP_INLINE_VISIBILITY - bool - __owner_equivalent(const shared_ptr& __p) const - {return __cntrl_ == __p.__cntrl_;} - -#if _LIBCPP_STD_VER > 14 - typename add_lvalue_reference<element_type>::type - _LIBCPP_INLINE_VISIBILITY - 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_NO_RTTI - template <class _Dp> - _LIBCPP_INLINE_VISIBILITY - _Dp* __get_deleter() const _NOEXCEPT - {return static_cast<_Dp*>(__cntrl_ - ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) - : nullptr);} -#endif // _LIBCPP_NO_RTTI - - template<class _Yp, class _CntrlBlk> - 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> - _LIBCPP_INLINE_VISIBILITY - typename enable_if<is_convertible<_OrigPtr*, - const enable_shared_from_this<_Yp>* - >::value, - void>::type - __enable_weak_this(const enable_shared_from_this<_Yp>* __e, - _OrigPtr* __ptr) _NOEXCEPT - { - typedef typename remove_cv<_Yp>::type _RawYp; - if (__e && __e->__weak_this_.expired()) - { - __e->__weak_this_ = shared_ptr<_RawYp>(*this, - const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); - } - } - - _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} - - 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> - 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; -}; - -#if _LIBCPP_STD_VER >= 17 -template<class _Tp> -shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; -template<class _Tp, class _Dp> -shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; -#endif - -template<class _Tp> -inline -_LIBCPP_CONSTEXPR -shared_ptr<_Tp>::shared_ptr() _NOEXCEPT - : __ptr_(nullptr), - __cntrl_(nullptr) -{ -} - -template<class _Tp> -inline -_LIBCPP_CONSTEXPR -shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT - : __ptr_(nullptr), - __cntrl_(nullptr) -{ -} - -template<class _Tp> -template<class _Yp, class _Dp> -shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, - typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type) - : __ptr_(__p) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - 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()); -#else - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); -#endif // not _LIBCPP_CXX03_LANG - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} - -template<class _Tp> -template<class _Dp> -shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) - : __ptr_(nullptr) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - 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()); -#else - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); -#endif // not _LIBCPP_CXX03_LANG -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} - -template<class _Tp> -template<class _Yp, class _Dp, class _Alloc> -shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, - typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type) - : __ptr_(__p) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_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())) -#ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, _VSTD::move(__d), __a); -#else - _CntrlBlk(__p, __d, __a); -#endif // not _LIBCPP_CXX03_LANG - __cntrl_ = _VSTD::addressof(*__hold2.release()); - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} - -template<class _Tp> -template<class _Dp, class _Alloc> -shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) - : __ptr_(nullptr) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_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())) -#ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, _VSTD::move(__d), __a); -#else - _CntrlBlk(__p, __d, __a); -#endif // not _LIBCPP_CXX03_LANG - __cntrl_ = _VSTD::addressof(*__hold2.release()); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} - -template<class _Tp> -template<class _Yp> -inline -shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT - : __ptr_(__p), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_shared(); -} - -template<class _Tp> -inline -shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_shared(); -} - -template<class _Tp> -template<class _Yp> -inline -shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - if (__cntrl_) - __cntrl_->__add_shared(); -} - -template<class _Tp> -inline -shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; -} - -template<class _Tp> -template<class _Yp> -inline -shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; -} - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) -template<class _Tp> -template<class _Yp> -shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, - typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) - : __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 _Tp> -template <class _Yp, class _Dp> -shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, - __nat - >::type) - : __ptr_(__r.get()) -{ -#if _LIBCPP_STD_VER > 11 - 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(), __r.get_deleter(), _AllocT()); - __enable_weak_this(__r.get(), __r.get()); - } - __r.release(); -} - -template<class _Tp> -template <class _Yp, class _Dp> -shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, - __nat - >::type) - : __ptr_(__r.get()) -{ -#if _LIBCPP_STD_VER > 11 - 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<typename remove_reference<_Dp>::type>, - _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); - __enable_weak_this(__r.get(), __r.get()); - } - __r.release(); -} - -template<class _Tp> -shared_ptr<_Tp>::~shared_ptr() -{ - if (__cntrl_) - __cntrl_->__release_shared(); -} - -template<class _Tp> -inline -shared_ptr<_Tp>& -shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT -{ - shared_ptr(__r).swap(*this); - return *this; -} - -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, - shared_ptr<_Tp>& ->::type -shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT -{ - shared_ptr(__r).swap(*this); - return *this; -} - -template<class _Tp> -inline -shared_ptr<_Tp>& -shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT -{ - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; -} - -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, - shared_ptr<_Tp>& ->::type -shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) -{ - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; -} - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - !is_array<_Yp>::value && - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, - shared_ptr<_Tp> ->::type& -shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) -{ - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; -} -#endif - -template<class _Tp> -template <class _Yp, class _Dp> -inline -typename enable_if -< - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, - typename shared_ptr<_Tp>::element_type*>::value, - shared_ptr<_Tp>& ->::type -shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) -{ - shared_ptr(_VSTD::move(__r)).swap(*this); - return *this; -} - -template<class _Tp> -inline -void -shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT -{ - _VSTD::swap(__ptr_, __r.__ptr_); - _VSTD::swap(__cntrl_, __r.__cntrl_); -} - -template<class _Tp> -inline -void -shared_ptr<_Tp>::reset() _NOEXCEPT -{ - shared_ptr().swap(*this); -} - -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, - void ->::type -shared_ptr<_Tp>::reset(_Yp* __p) -{ - shared_ptr(__p).swap(*this); -} - -template<class _Tp> -template<class _Yp, class _Dp> -inline -typename enable_if -< - __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, - void ->::type -shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) -{ - shared_ptr(__p, __d).swap(*this); -} - -template<class _Tp> -template<class _Yp, class _Dp, class _Alloc> -inline -typename enable_if -< - __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, - void ->::type -shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) -{ - shared_ptr(__p, __d, __a).swap(*this); -} - -// -// 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 ..._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 _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_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_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_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_INLINE_VISIBILITY -bool -operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT -{ - return !(__x < __y); -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT -{ - return !__x; -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -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_INLINE_VISIBILITY -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_INLINE_VISIBILITY -bool -operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return less<_Tp*>()(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_INLINE_VISIBILITY -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_INLINE_VISIBILITY -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_INLINE_VISIBILITY -bool -operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT -{ - return !(nullptr < __x); -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -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_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> -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> -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())); -} - -#ifndef _LIBCPP_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>(); -} - -#endif // _LIBCPP_NO_RTTI - -template<class _Tp> -class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr -{ -public: - typedef _Tp element_type; -private: - 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<is_convertible<_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<is_convertible<_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<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) - _NOEXCEPT; - ~weak_ptr(); - - _LIBCPP_INLINE_VISIBILITY - weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; - template<class _Yp> - typename enable_if - < - is_convertible<_Yp*, element_type*>::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 - < - is_convertible<_Yp*, element_type*>::value, - weak_ptr& - >::type - _LIBCPP_INLINE_VISIBILITY - operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; - - template<class _Yp> - typename enable_if - < - is_convertible<_Yp*, element_type*>::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;} - 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; -}; - -#if _LIBCPP_STD_VER >= 17 -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<is_convertible<_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<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) - _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> -inline -weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) - _NOEXCEPT - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_) -{ - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; -} - -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 const& __r) _NOEXCEPT -{ - weak_ptr(__r).swap(*this); - return *this; -} - -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - is_convertible<_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> -inline -weak_ptr<_Tp>& -weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT -{ - weak_ptr(_VSTD::move(__r)).swap(*this); - return *this; -} - -template<class _Tp> -template<class _Yp> -inline -typename enable_if -< - is_convertible<_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> -inline -typename enable_if -< - is_convertible<_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 -void -weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT -{ - _VSTD::swap(__ptr_, __r.__ptr_); - _VSTD::swap(__cntrl_, __r.__cntrl_); -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -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> -template<class _Yp> -shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) - : __ptr_(__r.__ptr_), - __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) -{ - if (__cntrl_ == nullptr) - __throw_bad_weak_ptr(); -} - -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 > 14 -template <class _Tp = void> struct owner_less; -#else -template <class _Tp> struct owner_less; -#endif - - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > -#if !defined(_LIBCPP_ABI_NO_BINDER_BASES) - : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> -#endif -{ -_LIBCPP_SUPPRESS_DEPRECATED_POP -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> first_argument_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> second_argument_type; -#endif - _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);} -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > -#if !defined(_LIBCPP_ABI_NO_BINDER_BASES) - : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> -#endif -{ -_LIBCPP_SUPPRESS_DEPRECATED_POP -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> first_argument_type; - _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> second_argument_type; -#endif - _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);} -}; - -#if _LIBCPP_STD_VER > 14 -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; -}; -#endif - -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() {} -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_);} - -#if _LIBCPP_STD_VER > 14 - _LIBCPP_INLINE_VISIBILITY - 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_; } -#endif // _LIBCPP_STD_VER > 14 - - template <class _Up> friend class shared_ptr; -}; - -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; - -template <class _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; -#endif - - _LIBCPP_INLINE_VISIBILITY - 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>& -operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); - - -#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) - -class _LIBCPP_TYPE_VIS __sp_mut -{ - void* __lx; -public: - void lock() _NOEXCEPT; - void unlock() _NOEXCEPT; - -private: - _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; - __sp_mut(const __sp_mut&); - __sp_mut& operator=(const __sp_mut&); - - friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); -}; - -_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -__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; -} - -template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -shared_ptr<_Tp> -atomic_load(const shared_ptr<_Tp>* __p) -{ - __sp_mut& __m = __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 atomic_load(__p); -} - -template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -void -atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) -{ - __sp_mut& __m = __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) -{ - atomic_store(__p, __r); -} - -template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -shared_ptr<_Tp> -atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) -{ - __sp_mut& __m = __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 atomic_exchange(__p, __r); -} - -template <class _Tp> -_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR -bool -atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) -{ - shared_ptr<_Tp> __temp; - __sp_mut& __m = __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; - __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 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 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 atomic_compare_exchange_weak(__p, __v, __w); -} - -#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_SHARED_PTR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_SHARED_PTR_H +#define _LIBCPP___MEMORY_SHARED_PTR_H + +#include <__availability> +#include <__config> +#include <__functional_base> +#include <__functional/binary_function.h> +#include <__functional/operations.h> +#include <__functional/reference_wrapper.h> +#include <__memory/addressof.h> +#include <__memory/allocation_guard.h> +#include <__memory/allocator_traits.h> +#include <__memory/allocator.h> +#include <__memory/compressed_pair.h> +#include <__memory/pointer_traits.h> +#include <__memory/unique_ptr.h> +#include <__utility/forward.h> +#include <cstddef> +#include <cstdlib> // abort +#include <iosfwd> +#include <stdexcept> +#include <typeinfo> +#include <type_traits> +#include <utility> +#if !defined(_LIBCPP_HAS_NO_THREADS) //!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include <atomic> +#endif + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +# include <__memory/auto_ptr.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Alloc> +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; +private: + _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_);} +}; + +// 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 +#elif defined(_LIBCPP_COMPILER_GCC) +# 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) && \ + (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) + return __atomic_load_n(__value, __ATOMIC_RELAXED); +#else + 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) && \ + (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) + return __atomic_load_n(__value, __ATOMIC_ACQUIRE); +#else + return *__value; +#endif +} + +#ifndef _LIBCPP_COMPILER_MSVC +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _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); +#else + return __t += 1; +#endif +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _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); +#else + return __t -= 1; +#endif +} +#endif + +class _LIBCPP_EXCEPTION_ABI bad_weak_ptr + : public std::exception +{ +public: + bad_weak_ptr() _NOEXCEPT = default; + bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; + virtual ~bad_weak_ptr() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_weak_ptr() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_weak_ptr(); +#else + _VSTD::abort(); +#endif +} + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; + +class _LIBCPP_TYPE_VIS __shared_count +{ + __shared_count(const __shared_count&); + __shared_count& operator=(const __shared_count&); + +protected: +#ifdef _LIBCPP_HAS_NO_THREADS + typedef long __atomic_count; +#else + typedef atomic<long> __atomic_count; +#endif + __atomic_count __shared_owners_; + + virtual ~__shared_count(); +private: + virtual void __on_zero_shared() _NOEXCEPT = 0; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __shared_count(long __refs = 0) _NOEXCEPT + : __shared_owners_(__refs) {} + +#if defined(_LIBCPP_BUILDING_LIBRARY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) + void __add_shared() _NOEXCEPT; + bool __release_shared() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + void __add_shared() _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + __libcpp_atomic_refcount_increment(__shared_owners_); +#else + __shared_owners_++; +#endif + } + _LIBCPP_INLINE_VISIBILITY + bool __release_shared() _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { +#else + if (--__shared_owners_ == -1) { +#endif + __on_zero_shared(); + return true; + } + return false; + } +#endif + _LIBCPP_INLINE_VISIBILITY + long use_count() const _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + return __libcpp_relaxed_load(&__shared_owners_) + 1; +#else + return __shared_owners_.load(memory_order_relaxed) + 1; +#endif + } +}; + +class _LIBCPP_TYPE_VIS __shared_weak_count + : private __shared_count +{ +#ifdef _LIBCPP_HAS_NO_THREADS + typedef long __atomic_count; +#else + typedef atomic<long> __atomic_count; +#endif + __atomic_count __shared_weak_owners_; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __shared_weak_count(long __refs = 0) _NOEXCEPT + : __shared_count(__refs), + __shared_weak_owners_(__refs) {} +protected: + virtual ~__shared_weak_count(); + +public: +#if defined(_LIBCPP_BUILDING_LIBRARY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) + 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 { +#ifdef _LIBCPP_HAS_NO_THREADS + __libcpp_atomic_refcount_increment(__shared_weak_owners_); +#else + __shared_weak_owners_++; +#endif + } + _LIBCPP_INLINE_VISIBILITY + 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; + + virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; +private: + 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_; +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)) {} + +#ifndef _LIBCPP_NO_RTTI + virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; +#endif + +private: + virtual void __on_zero_shared() _NOEXCEPT; + virtual void __on_zero_shared_weak() _NOEXCEPT; +}; + +#ifndef _LIBCPP_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; +} + +#endif // _LIBCPP_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(); +} + +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; + + _Al __a(__data_.second()); + __data_.second().~_Alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +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 > 17 + 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(); } + +private: + virtual void __on_zero_shared() _NOEXCEPT { +#if _LIBCPP_STD_VER > 17 + 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 + } + + virtual void __on_zero_shared_weak() _NOEXCEPT { + 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(_VSTD::move(__a)); + } + _LIBCPP_HIDE_FROM_ABI ~_Storage() { + __get_alloc()->~_Alloc(); + } + _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_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_; +}; + +struct __shared_ptr_dummy_rebind_allocator_type; +template <> +class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> +{ +public: + template <class _Other> + struct rebind + { + typedef allocator<_Other> other; + }; +}; + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; + +template<class _Tp, class _Up> +struct __compatible_with +#if _LIBCPP_STD_VER > 14 + : is_convertible<remove_extent_t<_Tp>*, remove_extent_t<_Up>*> {}; +#else + : is_convertible<_Tp*, _Up*> {}; +#endif // _LIBCPP_STD_VER > 14 + +template <class _Ptr, class = void> +struct __is_deletable : false_type { }; +template <class _Ptr> +struct __is_deletable<_Ptr, decltype(delete declval<_Ptr>())> : true_type { }; + +template <class _Ptr, class = void> +struct __is_array_deletable : false_type { }; +template <class _Ptr> +struct __is_array_deletable<_Ptr, decltype(delete[] declval<_Ptr>())> : true_type { }; + +template <class _Dp, class _Pt, + class = decltype(declval<_Dp>()(declval<_Pt>()))> +static true_type __well_formed_deleter_test(int); + +template <class, class> +static false_type __well_formed_deleter_test(...); + +template <class _Dp, class _Pt> +struct __well_formed_deleter : decltype(__well_formed_deleter_test<_Dp, _Pt>(0)) {}; + +template<class _Dp, class _Tp, class _Yp> +struct __shared_ptr_deleter_ctor_reqs +{ + static const bool value = __compatible_with<_Tp, _Yp>::value && + is_move_constructible<_Dp>::value && + __well_formed_deleter<_Dp, _Tp*>::value; +}; + +#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI) +# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) +#else +# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI +#endif + +template<class _Tp> +class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr +{ +public: +#if _LIBCPP_STD_VER > 14 + typedef weak_ptr<_Tp> weak_type; + typedef remove_extent_t<_Tp> element_type; +#else + typedef _Tp element_type; +#endif + +private: + element_type* __ptr_; + __shared_weak_count* __cntrl_; + + struct __nat {int __for_bool_;}; +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; + + template<class _Yp, class = __enable_if_t< + _And< + __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*> > +#endif + >::value + > > + 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> + shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat()); + template<class _Yp, class _Dp, class _Alloc> + shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat()); + template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); + template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); + template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + shared_ptr(const shared_ptr& __r) _NOEXCEPT; + template<class _Yp> + _LIBCPP_INLINE_VISIBILITY + shared_ptr(const shared_ptr<_Yp>& __r, + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) + _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + shared_ptr(shared_ptr&& __r) _NOEXCEPT; + template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) + _NOEXCEPT; + template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template<class _Yp> + shared_ptr(auto_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); +#endif + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + + ~shared_ptr(); + + _LIBCPP_INLINE_VISIBILITY + shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, + shared_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, + shared_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(shared_ptr<_Yp>&& __r); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template<class _Yp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + !is_array<_Yp>::value && + is_convertible<_Yp*, typename _VSTD::shared_ptr<_Tp>::element_type*>::value, + shared_ptr + >::type& + operator=(auto_ptr<_Yp>&& __r); +#endif + template <class _Yp, class _Dp> + typename enable_if + < + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, typename _VSTD::shared_ptr<_Tp>::element_type*>::value, + shared_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(unique_ptr<_Yp, _Dp>&& __r); + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_ptr& __r) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void reset() _NOEXCEPT; + template<class _Yp> + typename enable_if + < + __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p); + template<class _Yp, class _Dp> + typename enable_if + < + __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p, _Dp __d); + template<class _Yp, class _Dp, class _Alloc> + typename enable_if + < + __compatible_with<_Yp, typename _VSTD::shared_ptr<_Tp>::element_type>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p, _Dp __d, _Alloc __a); + + _LIBCPP_INLINE_VISIBILITY + element_type* get() const _NOEXCEPT {return __ptr_;} + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT + {return *__ptr_;} + _LIBCPP_INLINE_VISIBILITY + 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_INLINE_VISIBILITY + long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} + _LIBCPP_INLINE_VISIBILITY + bool unique() const _NOEXCEPT {return use_count() == 1;} + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT {return get() != nullptr;} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT + {return __cntrl_ < __p.__cntrl_;} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT + {return __cntrl_ < __p.__cntrl_;} + _LIBCPP_INLINE_VISIBILITY + bool + __owner_equivalent(const shared_ptr& __p) const + {return __cntrl_ == __p.__cntrl_;} + +#if _LIBCPP_STD_VER > 14 + typename add_lvalue_reference<element_type>::type + _LIBCPP_INLINE_VISIBILITY + 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_NO_RTTI + template <class _Dp> + _LIBCPP_INLINE_VISIBILITY + _Dp* __get_deleter() const _NOEXCEPT + {return static_cast<_Dp*>(__cntrl_ + ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) + : nullptr);} +#endif // _LIBCPP_NO_RTTI + + template<class _Yp, class _CntrlBlk> + 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> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<is_convertible<_OrigPtr*, + const enable_shared_from_this<_Yp>* + >::value, + void>::type + __enable_weak_this(const enable_shared_from_this<_Yp>* __e, + _OrigPtr* __ptr) _NOEXCEPT + { + typedef typename remove_cv<_Yp>::type _RawYp; + if (__e && __e->__weak_this_.expired()) + { + __e->__weak_this_ = shared_ptr<_RawYp>(*this, + const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); + } + } + + _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} + + 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> + 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; +}; + +#if _LIBCPP_STD_VER >= 17 +template<class _Tp> +shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; +template<class _Tp, class _Dp> +shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; +#endif + +template<class _Tp> +inline +_LIBCPP_CONSTEXPR +shared_ptr<_Tp>::shared_ptr() _NOEXCEPT + : __ptr_(nullptr), + __cntrl_(nullptr) +{ +} + +template<class _Tp> +inline +_LIBCPP_CONSTEXPR +shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT + : __ptr_(nullptr), + __cntrl_(nullptr) +{ +} + +template<class _Tp> +template<class _Yp, class _Dp> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type) + : __ptr_(__p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + 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()); +#else + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); +#endif // not _LIBCPP_CXX03_LANG + __enable_weak_this(__p, __p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Dp> +shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) + : __ptr_(nullptr) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + 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()); +#else + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); +#endif // not _LIBCPP_CXX03_LANG +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Yp, class _Dp, class _Alloc> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type) + : __ptr_(__p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_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())) +#ifndef _LIBCPP_CXX03_LANG + _CntrlBlk(__p, _VSTD::move(__d), __a); +#else + _CntrlBlk(__p, __d, __a); +#endif // not _LIBCPP_CXX03_LANG + __cntrl_ = _VSTD::addressof(*__hold2.release()); + __enable_weak_this(__p, __p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Dp, class _Alloc> +shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) + : __ptr_(nullptr) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_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())) +#ifndef _LIBCPP_CXX03_LANG + _CntrlBlk(__p, _VSTD::move(__d), __a); +#else + _CntrlBlk(__p, __d, __a); +#endif // not _LIBCPP_CXX03_LANG + __cntrl_ = _VSTD::addressof(*__hold2.release()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT + : __ptr_(__p), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +template<class _Tp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +template<class _Tp> +inline +shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; +} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template<class _Tp> +template<class _Yp> +shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __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 _Tp> +template <class _Yp, class _Dp> +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) + : __ptr_(__r.get()) +{ +#if _LIBCPP_STD_VER > 11 + 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(), __r.get_deleter(), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); + } + __r.release(); +} + +template<class _Tp> +template <class _Yp, class _Dp> +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) + : __ptr_(__r.get()) +{ +#if _LIBCPP_STD_VER > 11 + 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<typename remove_reference<_Dp>::type>, + _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); + } + __r.release(); +} + +template<class _Tp> +shared_ptr<_Tp>::~shared_ptr() +{ + if (__cntrl_) + __cntrl_->__release_shared(); +} + +template<class _Tp> +inline +shared_ptr<_Tp>& +shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT +{ + shared_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT +{ + shared_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +inline +shared_ptr<_Tp>& +shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + !is_array<_Yp>::value && + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp> +>::type& +shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} +#endif + +template<class _Tp> +template <class _Yp, class _Dp> +inline +typename enable_if +< + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, + typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +template<class _Tp> +inline +void +shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT +{ + _VSTD::swap(__ptr_, __r.__ptr_); + _VSTD::swap(__cntrl_, __r.__cntrl_); +} + +template<class _Tp> +inline +void +shared_ptr<_Tp>::reset() _NOEXCEPT +{ + shared_ptr().swap(*this); +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p) +{ + shared_ptr(__p).swap(*this); +} + +template<class _Tp> +template<class _Yp, class _Dp> +inline +typename enable_if +< + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) +{ + shared_ptr(__p, __d).swap(*this); +} + +template<class _Tp> +template<class _Yp, class _Dp, class _Alloc> +inline +typename enable_if +< + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) +{ + shared_ptr(__p, __d, __a).swap(*this); +} + +// +// 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 ..._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 _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_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_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_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_INLINE_VISIBILITY +bool +operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return !__x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +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_INLINE_VISIBILITY +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_INLINE_VISIBILITY +bool +operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return less<_Tp*>()(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_INLINE_VISIBILITY +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_INLINE_VISIBILITY +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_INLINE_VISIBILITY +bool +operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return !(nullptr < __x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +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_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> +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> +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())); +} + +#ifndef _LIBCPP_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>(); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Tp> +class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr +{ +public: + typedef _Tp element_type; +private: + 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<is_convertible<_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<is_convertible<_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<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) + _NOEXCEPT; + ~weak_ptr(); + + _LIBCPP_INLINE_VISIBILITY + weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::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 + < + is_convertible<_Yp*, element_type*>::value, + weak_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; + + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::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;} + 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; +}; + +#if _LIBCPP_STD_VER >= 17 +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<is_convertible<_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<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) + _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> +inline +weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; +} + +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 const& __r) _NOEXCEPT +{ + weak_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_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> +inline +weak_ptr<_Tp>& +weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT +{ + weak_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_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> +inline +typename enable_if +< + is_convertible<_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 +void +weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT +{ + _VSTD::swap(__ptr_, __r.__ptr_); + _VSTD::swap(__cntrl_, __r.__cntrl_); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +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> +template<class _Yp> +shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) +{ + if (__cntrl_ == nullptr) + __throw_bad_weak_ptr(); +} + +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 > 14 +template <class _Tp = void> struct owner_less; +#else +template <class _Tp> struct owner_less; +#endif + + +_LIBCPP_SUPPRESS_DEPRECATED_PUSH +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > +#if !defined(_LIBCPP_ABI_NO_BINDER_BASES) + : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> +#endif +{ +_LIBCPP_SUPPRESS_DEPRECATED_POP +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> first_argument_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> second_argument_type; +#endif + _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);} +}; + +_LIBCPP_SUPPRESS_DEPRECATED_PUSH +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > +#if !defined(_LIBCPP_ABI_NO_BINDER_BASES) + : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> +#endif +{ +_LIBCPP_SUPPRESS_DEPRECATED_POP +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> first_argument_type; + _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> second_argument_type; +#endif + _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);} +}; + +#if _LIBCPP_STD_VER > 14 +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; +}; +#endif + +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() {} +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_);} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + 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_; } +#endif // _LIBCPP_STD_VER > 14 + + template <class _Up> friend class shared_ptr; +}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; + +template <class _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; +#endif + + _LIBCPP_INLINE_VISIBILITY + 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>& +operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); + + +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) + +class _LIBCPP_TYPE_VIS __sp_mut +{ + void* __lx; +public: + void lock() _NOEXCEPT; + void unlock() _NOEXCEPT; + +private: + _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; + __sp_mut(const __sp_mut&); + __sp_mut& operator=(const __sp_mut&); + + friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); +}; + +_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +__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; +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_load(const shared_ptr<_Tp>* __p) +{ + __sp_mut& __m = __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 atomic_load(__p); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +void +atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) +{ + __sp_mut& __m = __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) +{ + atomic_store(__p, __r); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) +{ + __sp_mut& __m = __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 atomic_exchange(__p, __r); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +bool +atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) +{ + shared_ptr<_Tp> __temp; + __sp_mut& __m = __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; + __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 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 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 atomic_compare_exchange_weak(__p, __v, __w); +} + +#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_SHARED_PTR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/temporary_buffer.h b/contrib/libs/cxxsupp/libcxx/include/__memory/temporary_buffer.h index 06aa6c2936..4b8683515e 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/temporary_buffer.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/temporary_buffer.h @@ -1,84 +1,84 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_TEMPORARY_BUFFER_H -#define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H - -#include <__config> -#include <cstddef> -#include <new> -#include <utility> // pair - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp> -_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI -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)); - } -#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; - } - - __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); -#endif - - if (__r.first) - { - __r.second = __n; - break; - } - __n /= 2; - } - return __r; -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -void return_temporary_buffer(_Tp* __p) _NOEXCEPT -{ - _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); -} - -struct __return_temporary_buffer -{ - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_TEMPORARY_BUFFER_H +#define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H + +#include <__config> +#include <cstddef> +#include <new> +#include <utility> // pair + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI +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)); + } +#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; + } + + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); +#endif + + if (__r.first) + { + __r.second = __n; + break; + } + __n /= 2; + } + return __r; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void return_temporary_buffer(_Tp* __p) _NOEXCEPT +{ + _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); +} + +struct __return_temporary_buffer +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h b/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h index e83d62e0db..2cd495f3e0 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h @@ -1,241 +1,241 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H -#define _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H - -#include <__config> -#include <__memory/addressof.h> -#include <__memory/construct_at.h> -#include <iterator> -#include <utility> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _InputIterator, class _ForwardIterator> -_ForwardIterator -uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; -#ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __r; - try - { -#endif - for (; __f != __l; ++__f, (void) ++__r) - ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - for (; __s != __r; ++__s) - __s->~value_type(); - throw; - } -#endif - return __r; -} - -template <class _InputIterator, class _Size, class _ForwardIterator> -_ForwardIterator -uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; -#ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __r; - try - { -#endif - for (; __n > 0; ++__f, (void) ++__r, (void) --__n) - ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - for (; __s != __r; ++__s) - __s->~value_type(); - throw; - } -#endif - return __r; -} - -template <class _ForwardIterator, class _Tp> -void -uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; -#ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __f; - try - { -#endif - for (; __f != __l; ++__f) - ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - for (; __s != __f; ++__s) - __s->~value_type(); - throw; - } -#endif -} - -template <class _ForwardIterator, class _Size, class _Tp> -_ForwardIterator -uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) -{ - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; -#ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __f; - try - { -#endif - for (; __n > 0; ++__f, (void) --__n) - ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - for (; __s != __f; ++__s) - __s->~value_type(); - throw; - } -#endif - return __f; -} - -#if _LIBCPP_STD_VER > 14 - -template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY -void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; - auto __idx = __first; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __idx != __last; ++__idx) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt; -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first, __idx); - throw; - } -#endif -} - -template <class _ForwardIterator, class _Size> -inline _LIBCPP_INLINE_VISIBILITY -_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; - auto __idx = __first; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void) --__n) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt; - return __idx; -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first, __idx); - throw; - } -#endif -} - - -template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY -void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; - auto __idx = __first; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __idx != __last; ++__idx) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first, __idx); - throw; - } -#endif -} - -template <class _ForwardIterator, class _Size> -inline _LIBCPP_INLINE_VISIBILITY -_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; - auto __idx = __first; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void) --__n) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); - return __idx; -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first, __idx); - throw; - } -#endif -} - - -template <class _InputIt, class _ForwardIt> -inline _LIBCPP_INLINE_VISIBILITY -_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { - using _Vt = typename iterator_traits<_ForwardIt>::value_type; - auto __idx = __first_res; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __first != __last; ++__idx, (void) ++__first) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); - return __idx; -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first_res, __idx); - throw; - } -#endif -} - -template <class _InputIt, class _Size, class _ForwardIt> -inline _LIBCPP_INLINE_VISIBILITY -pair<_InputIt, _ForwardIt> -uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { - using _Vt = typename iterator_traits<_ForwardIt>::value_type; - auto __idx = __first_res; -#ifndef _LIBCPP_NO_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void) ++__first, --__n) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); - return {__first, __idx}; -#ifndef _LIBCPP_NO_EXCEPTIONS - } catch (...) { - _VSTD::destroy(__first_res, __idx); - throw; - } -#endif -} - -#endif // _LIBCPP_STD_VER > 14 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H +#define _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H + +#include <__config> +#include <__memory/addressof.h> +#include <__memory/construct_at.h> +#include <iterator> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator, class _ForwardIterator> +_ForwardIterator +uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __r; + try + { +#endif + for (; __f != __l; ++__f, (void) ++__r) + ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __r; ++__s) + __s->~value_type(); + throw; + } +#endif + return __r; +} + +template <class _InputIterator, class _Size, class _ForwardIterator> +_ForwardIterator +uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __r; + try + { +#endif + for (; __n > 0; ++__f, (void) ++__r, (void) --__n) + ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __r; ++__s) + __s->~value_type(); + throw; + } +#endif + return __r; +} + +template <class _ForwardIterator, class _Tp> +void +uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __f; + try + { +#endif + for (; __f != __l; ++__f) + ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __f; ++__s) + __s->~value_type(); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size, class _Tp> +_ForwardIterator +uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __f; + try + { +#endif + for (; __n > 0; ++__f, (void) --__n) + ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __f; ++__s) + __s->~value_type(); + throw; + } +#endif + return __f; +} + +#if _LIBCPP_STD_VER > 14 + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; ++__idx, (void) --__n) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt; + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; ++__idx, (void) --__n) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _InputIt, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __first != __last; ++__idx, (void) ++__first) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + +template <class _InputIt, class _Size, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIt, _ForwardIt> +uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; ++__idx, (void) ++__first, --__n) + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); + return {__first, __idx}; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/unique_ptr.h b/contrib/libs/cxxsupp/libcxx/include/__memory/unique_ptr.h index 7a0e4645fa..f9a3573f60 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/unique_ptr.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/unique_ptr.h @@ -1,769 +1,769 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_UNIQUE_PTR_H -#define _LIBCPP___MEMORY_UNIQUE_PTR_H - -#include <__config> -#include <__functional_base> -#include <__functional/hash.h> -#include <__functional/operations.h> -#include <__memory/allocator_traits.h> // __pointer -#include <__memory/compressed_pair.h> -#include <__utility/forward.h> -#include <cstddef> -#include <stlfwd> -#include <type_traits> -#include <utility> - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) -# include <__memory/auto_ptr.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_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"); -#ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; -#else - _LIBCPP_INLINE_VISIBILITY default_delete() {} -#endif - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - default_delete(const default_delete<_Up>&, - typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = - 0) _NOEXCEPT {} - - _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { - static_assert(sizeof(_Tp) > 0, - "default_delete can not delete incomplete type"); - static_assert(!is_void<_Tp>::value, - "default_delete can not delete incomplete type"); - delete __ptr; - } -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { -private: - template <class _Up> - struct _EnableIfConvertible - : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; - -public: -#ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; -#else - _LIBCPP_INLINE_VISIBILITY default_delete() {} -#endif - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - default_delete(const default_delete<_Up[]>&, - typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - typename _EnableIfConvertible<_Up>::type - operator()(_Up* __ptr) const _NOEXCEPT { - static_assert(sizeof(_Tp) > 0, - "default_delete can not delete incomplete type"); - static_assert(!is_void<_Tp>::value, - "default_delete can not delete void type"); - delete[] __ptr; - } -}; - -template <class _Deleter> -struct __unique_ptr_deleter_sfinae { - static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); - typedef const _Deleter& __lval_ref_type; - typedef _Deleter&& __good_rval_ref_type; - typedef true_type __enable_rval_overload; -}; - -template <class _Deleter> -struct __unique_ptr_deleter_sfinae<_Deleter const&> { - typedef const _Deleter& __lval_ref_type; - typedef const _Deleter&& __bad_rval_ref_type; - typedef false_type __enable_rval_overload; -}; - -template <class _Deleter> -struct __unique_ptr_deleter_sfinae<_Deleter&> { - typedef _Deleter& __lval_ref_type; - typedef _Deleter&& __bad_rval_ref_type; - typedef false_type __enable_rval_overload; -}; - -#if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI) -# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) -#else -# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI -#endif - -template <class _Tp, class _Dp> -class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { -public: - typedef _Tp element_type; - 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"); - -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; - - template <bool _Dummy> - 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; - - template <bool _Dummy, class _Deleter = typename __dependent_type< - __identity<deleter_type>, _Dummy>::type> - using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - typename enable_if<is_default_constructible<_Deleter>::value && - !is_pointer<_Deleter>::value>::type; - - template <class _ArgType> - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = - typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; - - template <class _UPtr, class _Up> - using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if< - is_convertible<typename _UPtr::pointer, pointer>::value && - !is_array<_Up>::value - >::type; - - 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; - - template <class _UDel> - using _EnableIfDeleterAssignable = typename enable_if< - is_assignable<_Dp&, _UDel&&>::value - >::type; - -public: - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, __d) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - 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"); - } - - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { - } - - template <class _Up, class _Ep, - class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, - class = _EnableIfDeleterConvertible<_Ep> - > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::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(), __default_init_tag()) {} -#endif - - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); - return *this; - } - - template <class _Up, class _Ep, - class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, - class = _EnableIfDeleterAssignable<_Ep> - > - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { - reset(__u.release()); - __ptr_.second() = _VSTD::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) { - reset(__p.release()); - return *this; - } -#endif - -#ifdef _LIBCPP_CXX03_LANG - unique_ptr(unique_ptr const&) = delete; - unique_ptr& operator=(unique_ptr const&) = delete; -#endif - - - _LIBCPP_INLINE_VISIBILITY - ~unique_ptr() { reset(); } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(nullptr_t) _NOEXCEPT { - reset(); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - typename add_lvalue_reference<_Tp>::type - operator*() const { - return *__ptr_.first(); - } - _LIBCPP_INLINE_VISIBILITY - pointer operator->() const _NOEXCEPT { - return __ptr_.first(); - } - _LIBCPP_INLINE_VISIBILITY - pointer get() const _NOEXCEPT { - return __ptr_.first(); - } - _LIBCPP_INLINE_VISIBILITY - deleter_type& get_deleter() _NOEXCEPT { - return __ptr_.second(); - } - _LIBCPP_INLINE_VISIBILITY - const deleter_type& get_deleter() const _NOEXCEPT { - return __ptr_.second(); - } - _LIBCPP_INLINE_VISIBILITY - explicit operator bool() const _NOEXCEPT { - return __ptr_.first() != nullptr; - } - - _LIBCPP_INLINE_VISIBILITY - pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); - return __t; - } - - _LIBCPP_INLINE_VISIBILITY - void reset(pointer __p = pointer()) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; - if (__tmp) - __ptr_.second()(__tmp); - } - - _LIBCPP_INLINE_VISIBILITY - 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: - typedef _Tp element_type; - typedef _Dp deleter_type; - typedef typename __pointer<_Tp, deleter_type>::type pointer; - -private: - __compressed_pair<pointer, deleter_type> __ptr_; - - template <class _From> - struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; - - 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) - > - {}; - - typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; - - template <bool _Dummy> - 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; - - template <bool _Dummy> - using _BadRValRefType _LIBCPP_NODEBUG = - typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; - - template <bool _Dummy, class _Deleter = typename __dependent_type< - __identity<deleter_type>, _Dummy>::type> - using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - typename enable_if<is_default_constructible<_Deleter>::value && - !is_pointer<_Deleter>::value>::type; - - template <class _ArgType> - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = - typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; - - 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; - - 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; - - template <class _UDel> - using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = typename enable_if< - is_assignable<_Dp&, _UDel&&>::value - >::type; - -public: - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy> > - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} - - template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(_Pp __p) _NOEXCEPT - : __ptr_(__p, __default_init_tag()) {} - - template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, __d) {} - - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - 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 - 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"); - } - - template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > - _LIBCPP_INLINE_VISIBILITY - 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"); - } - - template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { - } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); - return *this; - } - - template <class _Up, class _Ep, - class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, - class = _EnableIfDeleterConvertible<_Ep> - > - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { - } - - template <class _Up, class _Ep, - class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, - class = _EnableIfDeleterAssignable<_Ep> - > - _LIBCPP_INLINE_VISIBILITY - unique_ptr& - operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); - return *this; - } - -#ifdef _LIBCPP_CXX03_LANG - unique_ptr(unique_ptr const&) = delete; - unique_ptr& operator=(unique_ptr const&) = delete; -#endif - -public: - _LIBCPP_INLINE_VISIBILITY - ~unique_ptr() { reset(); } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(nullptr_t) _NOEXCEPT { - reset(); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - typename add_lvalue_reference<_Tp>::type - operator[](size_t __i) const { - return __ptr_.first()[__i]; - } - _LIBCPP_INLINE_VISIBILITY - pointer get() const _NOEXCEPT { - return __ptr_.first(); - } - - _LIBCPP_INLINE_VISIBILITY - deleter_type& get_deleter() _NOEXCEPT { - return __ptr_.second(); - } - - _LIBCPP_INLINE_VISIBILITY - const deleter_type& get_deleter() const _NOEXCEPT { - return __ptr_.second(); - } - _LIBCPP_INLINE_VISIBILITY - explicit operator bool() const _NOEXCEPT { - return __ptr_.first() != nullptr; - } - - _LIBCPP_INLINE_VISIBILITY - pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); - return __t; - } - - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY - typename enable_if< - _CheckArrayPointerConversion<_Pp>::value - >::type - reset(_Pp __p) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; - if (__tmp) - __ptr_.second()(__tmp); - } - - _LIBCPP_INLINE_VISIBILITY - void reset(nullptr_t = nullptr) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = nullptr; - if (__tmp) - __ptr_.second()(__tmp); - } - - _LIBCPP_INLINE_VISIBILITY - void swap(unique_ptr& __u) _NOEXCEPT { - __ptr_.swap(__u.__ptr_); - } - -}; - -template <class _Tp, class _Dp> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if< - __is_swappable<_Dp>::value, - void ->::type -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 -bool -operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __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 !(__x == __y);} - -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()); -} - -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;} - -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);} - -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);} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT -{ - return !__x; -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -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); -} - -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); -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -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 -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 -bool -operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) -{ - return nullptr < __x; -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) -{ - return __x < nullptr; -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) -{ - return !(nullptr < __x); -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) -{ - return !(__x < nullptr); -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) -{ - return !(__x < nullptr); -} - -template <class _T1, class _D1> -inline _LIBCPP_INLINE_VISIBILITY -bool -operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) -{ - return !(nullptr < __x); -} - -#if _LIBCPP_STD_VER > 11 - -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, size_t _Np> -struct __unique_if<_Tp[_Np]> -{ - typedef void __unique_array_known_bound; -}; - -template<class _Tp, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY -typename __unique_if<_Tp>::__unique_single -make_unique(_Args&&... __args) -{ - return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -typename __unique_if<_Tp>::__unique_array_unknown_bound -make_unique(size_t __n) -{ - typedef typename remove_extent<_Tp>::type _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; - -#endif // _LIBCPP_STD_VER > 11 - -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> > -#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; -#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_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_UNIQUE_PTR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_UNIQUE_PTR_H +#define _LIBCPP___MEMORY_UNIQUE_PTR_H + +#include <__config> +#include <__functional_base> +#include <__functional/hash.h> +#include <__functional/operations.h> +#include <__memory/allocator_traits.h> // __pointer +#include <__memory/compressed_pair.h> +#include <__utility/forward.h> +#include <cstddef> +#include <stlfwd> +#include <type_traits> +#include <utility> + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +# include <__memory/auto_ptr.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_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"); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up>&, + typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = + 0) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete incomplete type"); + delete __ptr; + } +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { +private: + template <class _Up> + struct _EnableIfConvertible + : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; + +public: +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up[]>&, + typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + typename _EnableIfConvertible<_Up>::type + operator()(_Up* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete void type"); + delete[] __ptr; + } +}; + +template <class _Deleter> +struct __unique_ptr_deleter_sfinae { + static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); + typedef const _Deleter& __lval_ref_type; + typedef _Deleter&& __good_rval_ref_type; + typedef true_type __enable_rval_overload; +}; + +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter const&> { + typedef const _Deleter& __lval_ref_type; + typedef const _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; +}; + +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter&> { + typedef _Deleter& __lval_ref_type; + typedef _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; +}; + +#if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI) +# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) +#else +# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI +#endif + +template <class _Tp, class _Dp> +class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { +public: + typedef _Tp element_type; + 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"); + +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; + + template <bool _Dummy> + 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; + + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; + + template <class _ArgType> + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + + template <class _UPtr, class _Up> + using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if< + is_convertible<typename _UPtr::pointer, pointer>::value && + !is_array<_Up>::value + >::type; + + 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; + + template <class _UDel> + using _EnableIfDeleterAssignable = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; + +public: + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > + _LIBCPP_INLINE_VISIBILITY + 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"); + } + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::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(), __default_init_tag()) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::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) { + reset(__p.release()); + return *this; + } +#endif + +#ifdef _LIBCPP_CXX03_LANG + unique_ptr(unique_ptr const&) = delete; + unique_ptr& operator=(unique_ptr const&) = delete; +#endif + + + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator*() const { + return *__ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + void reset(pointer __p = pointer()) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + 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: + typedef _Tp element_type; + typedef _Dp deleter_type; + typedef typename __pointer<_Tp, deleter_type>::type pointer; + +private: + __compressed_pair<pointer, deleter_type> __ptr_; + + template <class _From> + struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; + + 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) + > + {}; + + typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; + + template <bool _Dummy> + 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; + + template <bool _Dummy> + using _BadRValRefType _LIBCPP_NODEBUG = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; + + template <class _ArgType> + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + + 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; + + 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; + + template <class _UDel> + using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; + +public: + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy> > + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>, + class = _EnableIfPointerConvertible<_Pp> > + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(_Pp __p) _NOEXCEPT + : __ptr_(__p, __default_init_tag()) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > + _LIBCPP_INLINE_VISIBILITY + 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 + 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"); + } + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > + _LIBCPP_INLINE_VISIBILITY + 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"); + } + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& + operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } + +#ifdef _LIBCPP_CXX03_LANG + unique_ptr(unique_ptr const&) = delete; + unique_ptr& operator=(unique_ptr const&) = delete; +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator[](size_t __i) const { + return __ptr_.first()[__i]; + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } + + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } + + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + _CheckArrayPointerConversion<_Pp>::value + >::type + reset(_Pp __p) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + void reset(nullptr_t = nullptr) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = nullptr; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(unique_ptr& __u) _NOEXCEPT { + __ptr_.swap(__u.__ptr_); + } + +}; + +template <class _Tp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Dp>::value, + void +>::type +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 +bool +operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __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 !(__x == __y);} + +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()); +} + +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;} + +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);} + +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);} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT +{ + return !__x; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +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); +} + +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); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +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 +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 +bool +operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return nullptr < __x; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return __x < nullptr; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return !(nullptr < __x); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return !(__x < nullptr); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return !(__x < nullptr); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return !(nullptr < __x); +} + +#if _LIBCPP_STD_VER > 11 + +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, size_t _Np> +struct __unique_if<_Tp[_Np]> +{ + typedef void __unique_array_known_bound; +}; + +template<class _Tp, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_single +make_unique(_Args&&... __args) +{ + return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_array_unknown_bound +make_unique(size_t __n) +{ + typedef typename remove_extent<_Tp>::type _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; + +#endif // _LIBCPP_STD_VER > 11 + +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> > +#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; +#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_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_UNIQUE_PTR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/uses_allocator.h b/contrib/libs/cxxsupp/libcxx/include/__memory/uses_allocator.h index 5e29b7f1df..80d8b80e7f 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/uses_allocator.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/uses_allocator.h @@ -1,61 +1,61 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_USES_ALLOCATOR_H -#define _LIBCPP___MEMORY_USES_ALLOCATOR_H - -#include <__config> -#include <cstddef> -#include <type_traits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Tp> -struct __has_allocator_type -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - // Fix for MSVC which allows to reference private types. Wrap into declval to prevent that. - template <class _Up> static char __test(decltype(_VSTD::declval<typename _Up::allocator_type*>()) = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; - -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> -{ -}; - -template <class _Tp, class _Alloc> -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> -{ -}; - -#if _LIBCPP_STD_VER > 14 -template <class _Tp, class _Alloc> -inline constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_USES_ALLOCATOR_H +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_USES_ALLOCATOR_H +#define _LIBCPP___MEMORY_USES_ALLOCATOR_H + +#include <__config> +#include <cstddef> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +struct __has_allocator_type +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + // Fix for MSVC which allows to reference private types. Wrap into declval to prevent that. + template <class _Up> static char __test(decltype(_VSTD::declval<typename _Up::allocator_type*>()) = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +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> +{ +}; + +template <class _Tp, class _Alloc> +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> +{ +}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Alloc> +inline constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_USES_ALLOCATOR_H |