diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -13,9 +13,12 @@ __hash_table __libcpp_version __locale + __memory/allocator.h __memory/allocator_traits.h + __memory/auto_ptr.h __memory/base.h __memory/pointer_traits.h + __memory/temporary_buffer.h __memory/utilities.h __mutex_base __node_handle diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__memory/allocator.h @@ -0,0 +1,227 @@ +// -*- 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 +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class allocator; + +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) +template <> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +template <> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator +{ +public: + typedef const void* pointer; + typedef const void* const_pointer; + typedef const void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; +#endif + +// allocator + +template +class _LIBCPP_TEMPLATE_VIS allocator +{ +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 { } + + template + _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::max_size(*this)) + __throw_length_error("allocator::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(__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 + 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 + _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 _LIBCPP_TEMPLATE_VIS allocator +{ +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 { } + + template + _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::max_size(*this)) + __throw_length_error("allocator::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + if (__libcpp_is_constant_evaluated()) { + return static_cast(::operator new(__n * sizeof(_Tp))); + } else { + return static_cast(_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 + 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 + _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 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_ALLOCATOR_H diff --git a/libcxx/include/__memory/auto_ptr.h b/libcxx/include/__memory/auto_ptr.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__memory/auto_ptr.h @@ -0,0 +1,87 @@ +// -*- 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> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template +struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref +{ + _Tp* __ptr_; +}; + +template +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 _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 _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 _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT + {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} + template _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT + {return auto_ptr<_Up>(release());} +}; + +template <> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr +{ +public: + typedef void element_type; +}; +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_AUTO_PTR_H diff --git a/libcxx/include/__memory/temporary_buffer.h b/libcxx/include/__memory/temporary_buffer.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__memory/temporary_buffer.h @@ -0,0 +1,82 @@ +// -*- 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 +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +void return_temporary_buffer(_Tp* __p) _NOEXCEPT +{ + _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -680,9 +680,12 @@ #include #include #include +#include <__memory/allocator.h> #include <__memory/allocator_traits.h> +#include <__memory/auto_ptr.h> #include <__memory/base.h> #include <__memory/pointer_traits.h> +#include <__memory/temporary_buffer.h> #include <__memory/utilities.h> #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) # include @@ -723,200 +726,6 @@ #endif } -template class allocator; - -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) -template <> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator -{ -public: - typedef void* pointer; - typedef const void* const_pointer; - typedef void value_type; - - template struct rebind {typedef allocator<_Up> other;}; -}; - -template <> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator -{ -public: - typedef const void* pointer; - typedef const void* const_pointer; - typedef const void value_type; - - template struct rebind {typedef allocator<_Up> other;}; -}; -#endif - -// allocator - -template -class _LIBCPP_TEMPLATE_VIS allocator -{ -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 { } - - template - _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::max_size(*this)) - __throw_length_error("allocator::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(__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 - 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 - _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 _LIBCPP_TEMPLATE_VIS allocator -{ -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 { } - - template - _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::max_size(*this)) - __throw_length_error("allocator::allocate(size_t n)" - " 'n' exceeds maximum supported size"); - if (__libcpp_is_constant_evaluated()) { - return static_cast(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast(_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 - 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 - _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 -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} - -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} - template _LIBCPP_INLINE_VISIBILITY void __construct_forward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) { @@ -1031,117 +840,6 @@ #endif }; -template -_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 -inline _LIBCPP_INLINE_VISIBILITY -void return_temporary_buffer(_Tp* __p) _NOEXCEPT -{ - _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); -} - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) -template -struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref -{ - _Tp* __ptr_; -}; - -template -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 _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 _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 _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT - {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} - template _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT - {return auto_ptr<_Up>(release());} -}; - -template <> -class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr -{ -public: - typedef void element_type; -}; -#endif - // Tag used to default initialize one or both of the pair's elements. struct __default_init_tag {}; struct __value_init_tag {};