diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -167,8 +167,10 @@ __memory/allocator_traits.h __memory/allocator.h __memory/auto_ptr.h + __memory/builtin_new_allocator.h __memory/compressed_pair.h __memory/construct_at.h + __memory/destruct_n.h __memory/pointer_safety.h __memory/pointer_traits.h __memory/raw_storage_iterator.h diff --git a/libcxx/include/__algorithm/equal.h b/libcxx/include/__algorithm/equal.h --- a/libcxx/include/__algorithm/equal.h +++ b/libcxx/include/__algorithm/equal.h @@ -12,8 +12,9 @@ #include <__config> #include <__algorithm/comp.h> +#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> -#include // FIXME: replace with <__iterator/distance.h> when it lands +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h --- a/libcxx/include/__algorithm/equal_range.h +++ b/libcxx/include/__algorithm/equal_range.h @@ -15,7 +15,10 @@ #include <__algorithm/half_positive.h> #include <__algorithm/lower_bound.h> #include <__algorithm/upper_bound.h> -#include +#include <__iterator/advance.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/inplace_merge.h b/libcxx/include/__algorithm/inplace_merge.h --- a/libcxx/include/__algorithm/inplace_merge.h +++ b/libcxx/include/__algorithm/inplace_merge.h @@ -17,9 +17,16 @@ #include <__algorithm/move.h> #include <__algorithm/rotate.h> #include <__algorithm/upper_bound.h> +#include <__iterator/advance.h> +#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> +#include <__iterator/reverse_iterator.h> +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> +#include <__utility/pair.h> #include <__utility/swap.h> -#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h --- a/libcxx/include/__algorithm/is_permutation.h +++ b/libcxx/include/__algorithm/is_permutation.h @@ -12,9 +12,10 @@ #include <__algorithm/comp.h> #include <__config> +#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__iterator/next.h> -#include // FIXME: replace with <__iterator/distance.h> when it lands +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h --- a/libcxx/include/__algorithm/lower_bound.h +++ b/libcxx/include/__algorithm/lower_bound.h @@ -12,7 +12,10 @@ #include <__config> #include <__algorithm/comp.h> #include <__algorithm/half_positive.h> -#include +#include <__iterator/advance.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/partition_point.h b/libcxx/include/__algorithm/partition_point.h --- a/libcxx/include/__algorithm/partition_point.h +++ b/libcxx/include/__algorithm/partition_point.h @@ -11,7 +11,9 @@ #include <__config> #include <__algorithm/half_positive.h> -#include +#include <__iterator/advance.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/rotate.h b/libcxx/include/__algorithm/rotate.h --- a/libcxx/include/__algorithm/rotate.h +++ b/libcxx/include/__algorithm/rotate.h @@ -13,11 +13,11 @@ #include <__algorithm/move_backward.h> #include <__algorithm/swap_ranges.h> #include <__config> +#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__iterator/next.h> #include <__iterator/prev.h> #include <__utility/swap.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/rotate_copy.h b/libcxx/include/__algorithm/rotate_copy.h --- a/libcxx/include/__algorithm/rotate_copy.h +++ b/libcxx/include/__algorithm/rotate_copy.h @@ -11,7 +11,6 @@ #include <__config> #include <__algorithm/copy.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__algorithm/sample.h b/libcxx/include/__algorithm/sample.h --- a/libcxx/include/__algorithm/sample.h +++ b/libcxx/include/__algorithm/sample.h @@ -11,8 +11,10 @@ #include <__config> #include <__algorithm/min.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> #include <__random/uniform_int_distribution.h> -#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h --- a/libcxx/include/__algorithm/sort.h +++ b/libcxx/include/__algorithm/sort.h @@ -15,8 +15,12 @@ #include <__algorithm/min_element.h> #include <__algorithm/partial_sort.h> #include <__algorithm/unwrap_iter.h> +#include <__iterator/iterator_traits.h> +#include <__memory/destruct_n.h> +#include <__memory/unique_ptr.h> +#include <__utility/move.h> #include <__utility/swap.h> -#include +#include #include // swap #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__algorithm/stable_partition.h b/libcxx/include/__algorithm/stable_partition.h --- a/libcxx/include/__algorithm/stable_partition.h +++ b/libcxx/include/__algorithm/stable_partition.h @@ -11,9 +11,15 @@ #include <__config> #include <__algorithm/rotate.h> +#include <__iterator/advance.h> +#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> +#include <__utility/move.h> #include <__utility/swap.h> -#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__algorithm/stable_sort.h b/libcxx/include/__algorithm/stable_sort.h --- a/libcxx/include/__algorithm/stable_sort.h +++ b/libcxx/include/__algorithm/stable_sort.h @@ -15,8 +15,11 @@ #include <__algorithm/inplace_merge.h> #include <__algorithm/sort.h> #include <__iterator/iterator_traits.h> +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> +#include <__utility/move.h> #include <__utility/swap.h> -#include #include // swap #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__algorithm/unwrap_iter.h b/libcxx/include/__algorithm/unwrap_iter.h --- a/libcxx/include/__algorithm/unwrap_iter.h +++ b/libcxx/include/__algorithm/unwrap_iter.h @@ -10,7 +10,7 @@ #define _LIBCPP___ALGORITHM_UNWRAP_ITER_H #include <__config> -#include +#include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> #include diff --git a/libcxx/include/__algorithm/upper_bound.h b/libcxx/include/__algorithm/upper_bound.h --- a/libcxx/include/__algorithm/upper_bound.h +++ b/libcxx/include/__algorithm/upper_bound.h @@ -12,7 +12,10 @@ #include <__config> #include <__algorithm/comp.h> #include <__algorithm/half_positive.h> -#include +#include <__iterator/distance.h> +#include <__iterator/advance.h> +#include <__iterator/iterator_traits.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -16,10 +16,12 @@ #include <__functional/unary_function.h> #include <__iterator/iterator_traits.h> #include <__memory/allocator_traits.h> +#include <__memory/builtin_new_allocator.h> #include <__memory/compressed_pair.h> #include <__memory/shared_ptr.h> +#include <__memory/unique_ptr.h> #include -#include // TODO: replace with <__memory/__builtin_new_allocator.h> +#include #include #include diff --git a/libcxx/include/__memory/builtin_new_allocator.h b/libcxx/include/__memory/builtin_new_allocator.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__memory/builtin_new_allocator.h @@ -0,0 +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_BUILTIN_NEW_ALLOCATOR_H +#define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H + +#include <__config> +#include <__memory/unique_ptr.h> +#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 + +// __builtin_new_allocator -- A non-templated helper for allocating and +// deallocating memory using __builtin_operator_new and +// __builtin_operator_delete. It should be used in preference to +// `std::allocator` to avoid additional instantiations. +struct __builtin_new_allocator { + struct __builtin_new_deleter { + typedef void* pointer_type; + + _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) + : __size_(__size), __align_(__align) {} + + void operator()(void* p) const _NOEXCEPT { + _VSTD::__libcpp_deallocate(p, __size_, __align_); + } + + private: + size_t __size_; + size_t __align_; + }; + + typedef unique_ptr __holder_t; + + static __holder_t __allocate_bytes(size_t __s, size_t __align) { + return __holder_t(_VSTD::__libcpp_allocate(__s, __align), + __builtin_new_deleter(__s, __align)); + } + + static void __deallocate_bytes(void* __p, size_t __s, + size_t __align) _NOEXCEPT { + _VSTD::__libcpp_deallocate(__p, __s, __align); + } + + template + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE + static __holder_t __allocate_type(size_t __n) { + return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + } + + template + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE + static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { + __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H diff --git a/libcxx/include/__memory/destruct_n.h b/libcxx/include/__memory/destruct_n.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__memory/destruct_n.h @@ -0,0 +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_DESTRUCT_N_H +#define _LIBCPP___MEMORY_DESTRUCT_N_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct __destruct_n +{ +private: + size_t __size_; + + template + _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT + {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} + + template + _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT + {++__size_;} + _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT + {__size_ = __s;} + _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT + {} +public: + _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT + : __size_(__s) {} + + template + _LIBCPP_INLINE_VISIBILITY void __incr() _NOEXCEPT + {__incr(integral_constant::value>());} + + template + _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT + {__set(__s, integral_constant::value>());} + + template + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT + {__process(__p, integral_constant::value>());} +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_DESTRUCT_N_H diff --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer --- a/libcxx/include/__split_buffer +++ b/libcxx/include/__split_buffer @@ -5,6 +5,7 @@ #include <__config> #include <__utility/forward.h> #include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -652,8 +652,6 @@ #include #include #include -#include // needed to provide swap_ranges. -#include #include #include #include diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -674,8 +674,10 @@ #include <__memory/allocator.h> #include <__memory/allocator_arg_t.h> #include <__memory/allocator_traits.h> +#include <__memory/builtin_new_allocator.h> #include <__memory/compressed_pair.h> #include <__memory/construct_at.h> +#include <__memory/destruct_n.h> #include <__memory/pointer_safety.h> #include <__memory/pointer_traits.h> #include <__memory/raw_storage_iterator.h> @@ -799,45 +801,6 @@ _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); } -struct __destruct_n -{ -private: - size_t __size_; - - template - _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT - {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} - - template - _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT - {} - - _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT - {++__size_;} - _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT - {} - - _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT - {__size_ = __s;} - _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT - {} -public: - _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT - : __size_(__s) {} - - template - _LIBCPP_INLINE_VISIBILITY void __incr() _NOEXCEPT - {__incr(integral_constant::value>());} - - template - _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT - {__set(__s, integral_constant::value>());} - - template - _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT - {__process(__p, integral_constant::value>());} -}; - _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); // --- Helper for container swap -- @@ -912,52 +875,6 @@ > : true_type {}; -// __builtin_new_allocator -- A non-templated helper for allocating and -// deallocating memory using __builtin_operator_new and -// __builtin_operator_delete. It should be used in preference to -// `std::allocator` to avoid additional instantiations. -struct __builtin_new_allocator { - struct __builtin_new_deleter { - typedef void* pointer_type; - - _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) - : __size_(__size), __align_(__align) {} - - void operator()(void* p) const _NOEXCEPT { - _VSTD::__libcpp_deallocate(p, __size_, __align_); - } - - private: - size_t __size_; - size_t __align_; - }; - - typedef unique_ptr __holder_t; - - static __holder_t __allocate_bytes(size_t __s, size_t __align) { - return __holder_t(_VSTD::__libcpp_allocate(__s, __align), - __builtin_new_deleter(__s, __align)); - } - - static void __deallocate_bytes(void* __p, size_t __s, - size_t __align) _NOEXCEPT { - _VSTD::__libcpp_deallocate(__p, __s, __align); - } - - template - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE - static __holder_t __allocate_type(size_t __n) { - return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - - template - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE - static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { - __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } -}; - - _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -539,8 +539,10 @@ module allocator_arg_t { header "__memory/allocator_arg_t.h" } module allocator_traits { header "__memory/allocator_traits.h" } module auto_ptr { header "__memory/auto_ptr.h" } + module builtin_new_allocator { header "__memory/builtin_new_allocator.h" } module compressed_pair { header "__memory/compressed_pair.h" } module construct_at { header "__memory/construct_at.h" } + module destruct_n { header "__memory/destruct_n.h" } module pointer_safety { header "__memory/pointer_safety.h" } module pointer_traits { header "__memory/pointer_traits.h" } module raw_storage_iterator { header "__memory/raw_storage_iterator.h" } diff --git a/libcxx/include/valarray b/libcxx/include/valarray --- a/libcxx/include/valarray +++ b/libcxx/include/valarray @@ -340,6 +340,7 @@ */ #include <__config> +#include <__memory/uninitialized_algorithms.h> #include #include #include diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -276,6 +276,7 @@ #include <__debug> #include <__functional_base> #include <__iterator/wrap_iter.h> +#include <__iterator/move_iterator.h> #include <__split_buffer> #include <__utility/forward.h> #include