diff options
Diffstat (limited to 'libcxx/include')
-rw-r--r-- | libcxx/include/__fwd/tuple.h | 5 | ||||
-rw-r--r-- | libcxx/include/__math/traits.h | 76 | ||||
-rw-r--r-- | libcxx/include/__memory/uses_allocator_construction.h | 1 | ||||
-rw-r--r-- | libcxx/include/__memory_resource/polymorphic_allocator.h | 1 | ||||
-rw-r--r-- | libcxx/include/__tree | 135 | ||||
-rw-r--r-- | libcxx/include/__tuple/sfinae_helpers.h | 43 | ||||
-rw-r--r-- | libcxx/include/map | 8 | ||||
-rw-r--r-- | libcxx/include/math.h | 19 | ||||
-rw-r--r-- | libcxx/include/module.modulemap.in | 5 | ||||
-rw-r--r-- | libcxx/include/set | 8 | ||||
-rw-r--r-- | libcxx/include/tuple | 7 |
11 files changed, 234 insertions, 74 deletions
diff --git a/libcxx/include/__fwd/tuple.h b/libcxx/include/__fwd/tuple.h index fb922b2..39ed94d 100644 --- a/libcxx/include/__fwd/tuple.h +++ b/libcxx/include/__fwd/tuple.h @@ -26,6 +26,11 @@ struct tuple_element; template <class...> class tuple; +template <size_t _Ip, class... _Tp> +struct tuple_element<_Ip, tuple<_Tp...> > { + using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Tp...>; +}; + template <class> struct tuple_size; diff --git a/libcxx/include/__math/traits.h b/libcxx/include/__math/traits.h index 4a6e58c..00db2a8 100644 --- a/libcxx/include/__math/traits.h +++ b/libcxx/include/__math/traits.h @@ -189,6 +189,82 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar return __builtin_isunordered((type)__x, (type)__y); } +// MS UCRT incorrectly defines some functions in a way not working with integer types. Until C++20, this was worked +// around by -fdelayed-template-parsing. Since C++20, we can use standard feature "requires" instead. + +// TODO: Remove the workaround once UCRT fixes these functions. Note that this doesn't seem planned as of 2025-07 per +// https://developercommunity.visualstudio.com/t/10294165. + +#if defined(_LIBCPP_MSVCRT) && _LIBCPP_STD_VER >= 20 +namespace __ucrt { +template <class _A1> + requires is_integral_v<_A1> +[[nodiscard]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) noexcept { + return true; +} + +template <class _A1> + requires is_integral_v<_A1> +[[nodiscard]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) noexcept { + return false; +} + +template <class _A1> + requires is_integral_v<_A1> +[[nodiscard]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) noexcept { + return false; +} + +template <class _A1> + requires is_integral_v<_A1> +[[nodiscard]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) noexcept { + return __x != 0; +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_isgreater((type)__x, (type)__y); +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_isgreaterequal((type)__x, (type)__y); +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_isless((type)__x, (type)__y); +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_islessequal((type)__x, (type)__y); +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_islessgreater((type)__x, (type)__y); +} + +template <class _A1, class _A2> + requires is_arithmetic_v<_A1> && is_arithmetic_v<_A2> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) noexcept { + using type = __promote_t<_A1, _A2>; + return __builtin_isunordered((type)__x, (type)__y); +} +} // namespace __ucrt +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__memory/uses_allocator_construction.h b/libcxx/include/__memory/uses_allocator_construction.h index 49ddf99..6733f5c 100644 --- a/libcxx/include/__memory/uses_allocator_construction.h +++ b/libcxx/include/__memory/uses_allocator_construction.h @@ -17,6 +17,7 @@ #include <__type_traits/remove_cv.h> #include <__utility/declval.h> #include <__utility/pair.h> +#include <__utility/piecewise_construct.h> #include <tuple> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 6e7a9af..9a35119 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -18,6 +18,7 @@ #include <__new/exceptions.h> #include <__new/placement_new_delete.h> #include <__utility/exception_guard.h> +#include <__utility/piecewise_construct.h> #include <limits> #include <tuple> diff --git a/libcxx/include/__tree b/libcxx/include/__tree index f8bb4f0..6ca1a62 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -1213,6 +1213,104 @@ private: __node_pointer __cache_root_; __node_pointer __cache_elem_; }; + + class __tree_deleter { + __node_allocator& __alloc_; + + public: + using pointer = __node_pointer; + + _LIBCPP_HIDE_FROM_ABI __tree_deleter(__node_allocator& __alloc) : __alloc_(__alloc) {} + +#ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function + _LIBCPP_HIDE_FROM_ABI +#endif + void + operator()(__node_pointer __ptr) { + if (!__ptr) + return; + + (*this)(static_cast<__node_pointer>(__ptr->__left_)); + + auto __right = __ptr->__right_; + + __node_traits::destroy(__alloc_, std::addressof(__ptr->__value_)); + __node_traits::deallocate(__alloc_, __ptr, 1); + + (*this)(static_cast<__node_pointer>(__right)); + } + }; + + // This copy construction will always produce a correct red-black-tree assuming the incoming tree is correct, since we + // copy the exact structure 1:1. Since this is for copy construction _only_ we know that we get a correct tree. If we + // didn't get a correct tree, the invariants of __tree are broken and we have a much bigger problem than an improperly + // balanced tree. +#ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function + _LIBCPP_HIDE_FROM_ABI +#endif + __node_pointer + __copy_construct_tree(__node_pointer __src) { + if (!__src) + return nullptr; + + __node_holder __new_node = __construct_node(__src->__value_); + + unique_ptr<__node, __tree_deleter> __left( + __copy_construct_tree(static_cast<__node_pointer>(__src->__left_)), __node_alloc_); + __node_pointer __right = __copy_construct_tree(static_cast<__node_pointer>(__src->__right_)); + + __node_pointer __new_node_ptr = __new_node.release(); + + __new_node_ptr->__is_black_ = __src->__is_black_; + __new_node_ptr->__left_ = static_cast<__node_base_pointer>(__left.release()); + __new_node_ptr->__right_ = static_cast<__node_base_pointer>(__right); + if (__new_node_ptr->__left_) + __new_node_ptr->__left_->__parent_ = static_cast<__end_node_pointer>(__new_node_ptr); + if (__new_node_ptr->__right_) + __new_node_ptr->__right_->__parent_ = static_cast<__end_node_pointer>(__new_node_ptr); + return __new_node_ptr; + } + + // This copy assignment will always produce a correct red-black-tree assuming the incoming tree is correct, since our + // own tree is a red-black-tree and the incoming tree is a red-black-tree. The invariants of a red-black-tree are + // temporarily not met until all of the incoming red-black tree is copied. +#ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function + _LIBCPP_HIDE_FROM_ABI +#endif + __node_pointer + __copy_assign_tree(__node_pointer __dest, __node_pointer __src) { + if (!__src) { + destroy(__dest); + return nullptr; + } + + __assign_value(__dest->__value_, __src->__value_); + __dest->__is_black_ = __src->__is_black_; + + // If we already have a left node in the destination tree, reuse it and copy-assign recursively + if (__dest->__left_) { + __dest->__left_ = static_cast<__node_base_pointer>(__copy_assign_tree( + static_cast<__node_pointer>(__dest->__left_), static_cast<__node_pointer>(__src->__left_))); + + // Otherwise, we must create new nodes; copy-construct from here on + } else if (__src->__left_) { + auto __new_left = __copy_construct_tree(static_cast<__node_pointer>(__src->__left_)); + __dest->__left_ = static_cast<__node_base_pointer>(__new_left); + __new_left->__parent_ = static_cast<__end_node_pointer>(__dest); + } + + // Identical to the left case above, just for the right nodes + if (__dest->__right_) { + __dest->__right_ = static_cast<__node_base_pointer>(__copy_assign_tree( + static_cast<__node_pointer>(__dest->__right_), static_cast<__node_pointer>(__src->__right_))); + } else if (__src->__right_) { + auto __new_right = __copy_construct_tree(static_cast<__node_pointer>(__src->__right_)); + __dest->__right_ = static_cast<__node_base_pointer>(__new_right); + __new_right->__parent_ = static_cast<__end_node_pointer>(__dest); + } + + return __dest; + } }; template <class _Tp, class _Compare, class _Allocator> @@ -1277,11 +1375,22 @@ __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_poin template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) { - if (this != std::addressof(__t)) { - value_comp() = __t.value_comp(); - __copy_assign_alloc(__t); - __assign_multi(__t.begin(), __t.end()); + if (this == std::addressof(__t)) + return *this; + + value_comp() = __t.value_comp(); + __copy_assign_alloc(__t); + + if (__size_ != 0) { + *__root_ptr() = static_cast<__node_base_pointer>(__copy_assign_tree(__root(), __t.__root())); + } else { + *__root_ptr() = static_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); + if (__root()) + __root()->__parent_ = __end_node(); } + __begin_node_ = static_cast<__end_node_pointer>(std::__tree_min(static_cast<__node_base_pointer>(__end_node()))); + __size_ = __t.size(); + return *this; } @@ -1327,11 +1436,17 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _ template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) - : __begin_node_(), + : __begin_node_(__end_node()), __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())), __size_(0), __value_comp_(__t.value_comp()) { - __begin_node_ = __end_node(); + if (__t.size() == 0) + return; + + *__root_ptr() = static_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); + __root()->__parent_ = __end_node(); + __begin_node_ = static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); + __size_ = __t.size(); } template <class _Tp, class _Compare, class _Allocator> @@ -1430,13 +1545,7 @@ __tree<_Tp, _Compare, _Allocator>::~__tree() { template <class _Tp, class _Compare, class _Allocator> void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT { - if (__nd != nullptr) { - destroy(static_cast<__node_pointer>(__nd->__left_)); - destroy(static_cast<__node_pointer>(__nd->__right_)); - __node_allocator& __na = __node_alloc(); - __node_traits::destroy(__na, std::addressof(__nd->__value_)); - __node_traits::deallocate(__na, __nd, 1); - } + (__tree_deleter(__node_alloc_))(__nd); } template <class _Tp, class _Compare, class _Allocator> diff --git a/libcxx/include/__tuple/sfinae_helpers.h b/libcxx/include/__tuple/sfinae_helpers.h index 9fe5e84..f314381 100644 --- a/libcxx/include/__tuple/sfinae_helpers.h +++ b/libcxx/include/__tuple/sfinae_helpers.h @@ -10,20 +10,6 @@ #define _LIBCPP___TUPLE_SFINAE_HELPERS_H #include <__config> -#include <__cstddef/size_t.h> -#include <__fwd/tuple.h> -#include <__tuple/make_tuple_types.h> -#include <__tuple/tuple_element.h> -#include <__tuple/tuple_like_ext.h> -#include <__tuple/tuple_size.h> -#include <__tuple/tuple_types.h> -#include <__type_traits/conjunction.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/integral_constant.h> -#include <__type_traits/is_constructible.h> -#include <__type_traits/is_same.h> -#include <__type_traits/remove_cvref.h> -#include <__type_traits/remove_reference.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -33,35 +19,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_CXX03_LANG -struct __tuple_sfinae_base { - template <template <class, class...> class _Trait, class... _LArgs, class... _RArgs> - static auto __do_test(__tuple_types<_LArgs...>, - __tuple_types<_RArgs...>) -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>; - template <template <class...> class> - static auto __do_test(...) -> false_type; - - template <class _FromArgs, class _ToArgs> - using __constructible _LIBCPP_NODEBUG = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{})); -}; - -// __tuple_constructible - -template <class _Tp, - class _Up, - bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value, - bool = __tuple_like_ext<_Up>::value> -struct __tuple_constructible : public false_type {}; - -template <class _Tp, class _Up> -struct __tuple_constructible<_Tp, _Up, true, true> - : public __tuple_sfinae_base::__constructible< typename __make_tuple_types<_Tp>::type, - typename __make_tuple_types<_Up>::type > {}; - -template <size_t _Ip, class... _Tp> -struct tuple_element<_Ip, tuple<_Tp...> > { - using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, __tuple_types<_Tp...> >::type; -}; - struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail { static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; } static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; } diff --git a/libcxx/include/map b/libcxx/include/map index 2251565..0a43bd0 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -970,7 +970,7 @@ public: : map(from_range, std::forward<_Range>(__range), key_compare(), __a) {} # endif - _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); } + _LIBCPP_HIDE_FROM_ABI map(const map& __m) = default; _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) = default; @@ -1637,11 +1637,7 @@ public: : multimap(from_range, std::forward<_Range>(__range), key_compare(), __a) {} # endif - _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m) - : __tree_(__m.__tree_.value_comp(), - __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) { - insert(__m.begin(), __m.end()); - } + _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m) = default; _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) = default; diff --git a/libcxx/include/math.h b/libcxx/include/math.h index 929bef6..1db6153 100644 --- a/libcxx/include/math.h +++ b/libcxx/include/math.h @@ -429,6 +429,25 @@ using std::__math::isnormal; using std::__math::isunordered; # endif // _LIBCPP_MSVCRT +# if defined(_LIBCPP_MSVCRT) && _LIBCPP_STD_VER >= 20 +// MS UCRT incorrectly defines some functions in a way not working with integer types. Until C++20, this was worked +// around by -fdelayed-template-parsing. Since C++20, we can use standard feature "requires" instead. + +// TODO: Remove the workaround once UCRT fixes these functions. Note that this doesn't seem planned as of 2025-07 per +// https://developercommunity.visualstudio.com/t/10294165. + +using std::__math::__ucrt::isfinite; +using std::__math::__ucrt::isgreater; +using std::__math::__ucrt::isgreaterequal; +using std::__math::__ucrt::isinf; +using std::__math::__ucrt::isless; +using std::__math::__ucrt::islessequal; +using std::__math::__ucrt::islessgreater; +using std::__math::__ucrt::isnan; +using std::__math::__ucrt::isnormal; +using std::__math::__ucrt::isunordered; +# endif // defined(_LIBCPP_MSVCRT) && _LIBCPP_STD_VER >= 20 + // We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math // functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads // templates. Functions are preferred over function templates during overload resolution, which means that our overload diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in index 5857a83..b07a153e 100644 --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -2168,7 +2168,10 @@ module std [system] { module is_valid_range { header "__utility/is_valid_range.h" } module move { header "__utility/move.h" } module no_destroy { header "__utility/no_destroy.h" } - module pair { header "__utility/pair.h" } + module pair { + header "__utility/pair.h" + export std.utility.piecewise_construct + } module piecewise_construct { header "__utility/piecewise_construct.h" } module priority_tag { header "__utility/priority_tag.h" } module private_constructor_tag { header "__utility/private_constructor_tag.h" } diff --git a/libcxx/include/set b/libcxx/include/set index 1f2fd7f..342a529 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -660,7 +660,7 @@ public: : set(from_range, std::forward<_Range>(__range), key_compare(), __a) {} # endif - _LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); } + _LIBCPP_HIDE_FROM_ABI set(const set& __s) = default; _LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) = default; @@ -1119,11 +1119,7 @@ public: : multiset(from_range, std::forward<_Range>(__range), key_compare(), __a) {} # endif - _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s) - : __tree_(__s.__tree_.value_comp(), - __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc())) { - insert(__s.begin(), __s.end()); - } + _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s) = default; _LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) = default; diff --git a/libcxx/include/tuple b/libcxx/include/tuple index 23a391d..be30ab5 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -233,7 +233,6 @@ template <class... Types> # include <__tuple/find_index.h> # include <__tuple/ignore.h> # include <__tuple/make_tuple_types.h> -# include <__tuple/sfinae_helpers.h> # include <__tuple/tuple_element.h> # include <__tuple/tuple_like.h> # include <__tuple/tuple_like_ext.h> @@ -247,7 +246,6 @@ template <class... Types> # include <__type_traits/disjunction.h> # include <__type_traits/enable_if.h> # include <__type_traits/invoke.h> -# include <__type_traits/is_arithmetic.h> # include <__type_traits/is_assignable.h> # include <__type_traits/is_constructible.h> # include <__type_traits/is_convertible.h> @@ -274,7 +272,6 @@ template <class... Types> # include <__utility/forward.h> # include <__utility/integer_sequence.h> # include <__utility/move.h> -# include <__utility/piecewise_construct.h> # include <__utility/swap.h> # include <version> @@ -540,7 +537,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args) : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {} - template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0> + template <class _Tuple> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept( (__all<is_nothrow_constructible< _Tp, @@ -549,7 +546,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>( std::get<_Indx>(__t)))... {} - template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0> + template <class _Alloc, class _Tuple> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) : __tuple_leaf<_Indx, _Tp>( __uses_alloc_ctor<_Tp, |