aboutsummaryrefslogtreecommitdiff
path: root/lib/libcxx/include/__algorithm
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-04-26 15:33:29 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-05-08 19:37:29 -0700
commit06ee65af9ed6aa5ee4d1d7f4fab9d7acecf66e76 (patch)
tree1316711b92a43dd5c599e425b8693fa8e1e0c0b7 /lib/libcxx/include/__algorithm
parentbc6ebc6f2597fda1f98842c6f545751fef2a5334 (diff)
downloadzig-06ee65af9ed6aa5ee4d1d7f4fab9d7acecf66e76.tar.gz
zig-06ee65af9ed6aa5ee4d1d7f4fab9d7acecf66e76.zip
libcxx: update to LLVM 18
release/18.x branch, commit 78b99c73ee4b96fe9ce0e294d4632326afb2db42 This adds the flag `-D_LIBCPP_HARDENING_MODE` which is determined based on the Zig optimization mode. This commit also fixes libunwind, libcxx, and libcxxabi to properly report sub compilation errors.
Diffstat (limited to 'lib/libcxx/include/__algorithm')
-rw-r--r--lib/libcxx/include/__algorithm/any_of.h2
-rw-r--r--lib/libcxx/include/__algorithm/binary_search.h20
-rw-r--r--lib/libcxx/include/__algorithm/clamp.h30
-rw-r--r--lib/libcxx/include/__algorithm/comp.h6
-rw-r--r--lib/libcxx/include/__algorithm/comp_ref_type.h69
-rw-r--r--lib/libcxx/include/__algorithm/copy.h7
-rw-r--r--lib/libcxx/include/__algorithm/copy_backward.h16
-rw-r--r--lib/libcxx/include/__algorithm/copy_if.h23
-rw-r--r--lib/libcxx/include/__algorithm/copy_move_common.h30
-rw-r--r--lib/libcxx/include/__algorithm/copy_n.h65
-rw-r--r--lib/libcxx/include/__algorithm/count.h69
-rw-r--r--lib/libcxx/include/__algorithm/count_if.h2
-rw-r--r--lib/libcxx/include/__algorithm/equal.h59
-rw-r--r--lib/libcxx/include/__algorithm/equal_range.h16
-rw-r--r--lib/libcxx/include/__algorithm/fill.h26
-rw-r--r--lib/libcxx/include/__algorithm/fill_n.h20
-rw-r--r--lib/libcxx/include/__algorithm/find.h108
-rw-r--r--lib/libcxx/include/__algorithm/find_end.h92
-rw-r--r--lib/libcxx/include/__algorithm/find_first_of.h25
-rw-r--r--lib/libcxx/include/__algorithm/find_if.h2
-rw-r--r--lib/libcxx/include/__algorithm/find_if_not.h2
-rw-r--r--lib/libcxx/include/__algorithm/find_segment_if.h62
-rw-r--r--lib/libcxx/include/__algorithm/fold.h130
-rw-r--r--lib/libcxx/include/__algorithm/for_each.h31
-rw-r--r--lib/libcxx/include/__algorithm/for_each_n.h7
-rw-r--r--lib/libcxx/include/__algorithm/generate.h10
-rw-r--r--lib/libcxx/include/__algorithm/generate_n.h16
-rw-r--r--lib/libcxx/include/__algorithm/half_positive.h26
-rw-r--r--lib/libcxx/include/__algorithm/in_found_result.h7
-rw-r--r--lib/libcxx/include/__algorithm/in_fun_result.h7
-rw-r--r--lib/libcxx/include/__algorithm/in_in_out_result.h19
-rw-r--r--lib/libcxx/include/__algorithm/in_in_result.h11
-rw-r--r--lib/libcxx/include/__algorithm/in_out_out_result.h19
-rw-r--r--lib/libcxx/include/__algorithm/in_out_result.h8
-rw-r--r--lib/libcxx/include/__algorithm/includes.h36
-rw-r--r--lib/libcxx/include/__algorithm/inplace_merge.h304
-rw-r--r--lib/libcxx/include/__algorithm/is_heap.h20
-rw-r--r--lib/libcxx/include/__algorithm/is_heap_until.h56
-rw-r--r--lib/libcxx/include/__algorithm/is_partitioned.h21
-rw-r--r--lib/libcxx/include/__algorithm/is_permutation.h177
-rw-r--r--lib/libcxx/include/__algorithm/is_sorted.h20
-rw-r--r--lib/libcxx/include/__algorithm/is_sorted_until.h33
-rw-r--r--lib/libcxx/include/__algorithm/iter_swap.h3
-rw-r--r--lib/libcxx/include/__algorithm/iterator_operations.h75
-rw-r--r--lib/libcxx/include/__algorithm/lexicographical_compare.h49
-rw-r--r--lib/libcxx/include/__algorithm/lower_bound.h15
-rw-r--r--lib/libcxx/include/__algorithm/make_heap.h16
-rw-r--r--lib/libcxx/include/__algorithm/make_projected.h49
-rw-r--r--lib/libcxx/include/__algorithm/max.h39
-rw-r--r--lib/libcxx/include/__algorithm/max_element.h33
-rw-r--r--lib/libcxx/include/__algorithm/merge.h65
-rw-r--r--lib/libcxx/include/__algorithm/min.h39
-rw-r--r--lib/libcxx/include/__algorithm/min_element.h23
-rw-r--r--lib/libcxx/include/__algorithm/min_max_result.h2
-rw-r--r--lib/libcxx/include/__algorithm/minmax.h48
-rw-r--r--lib/libcxx/include/__algorithm/minmax_element.h31
-rw-r--r--lib/libcxx/include/__algorithm/mismatch.h25
-rw-r--r--lib/libcxx/include/__algorithm/move.h8
-rw-r--r--lib/libcxx/include/__algorithm/move_backward.h8
-rw-r--r--lib/libcxx/include/__algorithm/next_permutation.h66
-rw-r--r--lib/libcxx/include/__algorithm/none_of.h2
-rw-r--r--lib/libcxx/include/__algorithm/nth_element.h377
-rw-r--r--lib/libcxx/include/__algorithm/partial_sort.h44
-rw-r--r--lib/libcxx/include/__algorithm/partial_sort_copy.h99
-rw-r--r--lib/libcxx/include/__algorithm/partition.h89
-rw-r--r--lib/libcxx/include/__algorithm/partition_copy.h36
-rw-r--r--lib/libcxx/include/__algorithm/partition_point.h34
-rw-r--r--lib/libcxx/include/__algorithm/pop_heap.h21
-rw-r--r--lib/libcxx/include/__algorithm/prev_permutation.h69
-rw-r--r--lib/libcxx/include/__algorithm/pstl_any_all_none_of.h92
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backend.h156
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backend.h15
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/any_of.h38
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/fill.h26
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/find_if.h70
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/for_each.h30
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h240
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/merge.h68
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/serial.h19
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/stable_sort.h16
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/thread.h14
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform.h82
-rw-r--r--lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h126
-rw-r--r--lib/libcxx/include/__algorithm/pstl_copy.h78
-rw-r--r--lib/libcxx/include/__algorithm/pstl_count.h52
-rw-r--r--lib/libcxx/include/__algorithm/pstl_equal.h175
-rw-r--r--lib/libcxx/include/__algorithm/pstl_fill.h56
-rw-r--r--lib/libcxx/include/__algorithm/pstl_find.h88
-rw-r--r--lib/libcxx/include/__algorithm/pstl_for_each.h58
-rw-r--r--lib/libcxx/include/__algorithm/pstl_frontend_dispatch.h9
-rw-r--r--lib/libcxx/include/__algorithm/pstl_generate.h58
-rw-r--r--lib/libcxx/include/__algorithm/pstl_is_partitioned.h25
-rw-r--r--lib/libcxx/include/__algorithm/pstl_merge.h42
-rw-r--r--lib/libcxx/include/__algorithm/pstl_move.h84
-rw-r--r--lib/libcxx/include/__algorithm/pstl_replace.h154
-rw-r--r--lib/libcxx/include/__algorithm/pstl_rotate_copy.h85
-rw-r--r--lib/libcxx/include/__algorithm/pstl_sort.h27
-rw-r--r--lib/libcxx/include/__algorithm/pstl_stable_sort.h24
-rw-r--r--lib/libcxx/include/__algorithm/pstl_transform.h59
-rw-r--r--lib/libcxx/include/__algorithm/push_heap.h24
-rw-r--r--lib/libcxx/include/__algorithm/ranges_adjacent_find.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_all_of.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_any_of.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_binary_search.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_clamp.h15
-rw-r--r--lib/libcxx/include/__algorithm/ranges_contains.h66
-rw-r--r--lib/libcxx/include/__algorithm/ranges_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_copy_backward.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_copy_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_copy_n.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_count.h14
-rw-r--r--lib/libcxx/include/__algorithm/ranges_count_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_ends_with.h201
-rw-r--r--lib/libcxx/include/__algorithm/ranges_equal.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_equal_range.h7
-rw-r--r--lib/libcxx/include/__algorithm/ranges_fill.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_fill_n.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_find.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_find_end.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_find_first_of.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_find_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_find_if_not.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_for_each.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_for_each_n.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_generate.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_generate_n.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_includes.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_inplace_merge.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_heap.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_heap_until.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_partitioned.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_permutation.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_sorted.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_is_sorted_until.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_iterator_concept.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_lower_bound.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_make_heap.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_max.h11
-rw-r--r--lib/libcxx/include/__algorithm/ranges_max_element.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_merge.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_min.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_min_element.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_minmax.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_minmax_element.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_mismatch.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_move.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_move_backward.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_next_permutation.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_none_of.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_nth_element.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_partial_sort.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_partition.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_partition_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_partition_point.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_pop_heap.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_prev_permutation.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_push_heap.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_remove.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_remove_copy.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_remove_copy_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_remove_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_replace.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_replace_copy.h9
-rw-r--r--lib/libcxx/include/__algorithm/ranges_replace_copy_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_replace_if.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_reverse_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_rotate.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_rotate_copy.h10
-rw-r--r--lib/libcxx/include/__algorithm/ranges_sample.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_search_n.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_set_difference.h6
-rw-r--r--lib/libcxx/include/__algorithm/ranges_set_intersection.h6
-rw-r--r--lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h6
-rw-r--r--lib/libcxx/include/__algorithm/ranges_set_union.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_shuffle.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_sort.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_sort_heap.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_stable_partition.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_stable_sort.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_starts_with.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_swap_ranges.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_transform.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_unique.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_unique_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/ranges_upper_bound.h4
-rw-r--r--lib/libcxx/include/__algorithm/remove.h31
-rw-r--r--lib/libcxx/include/__algorithm/remove_copy.h20
-rw-r--r--lib/libcxx/include/__algorithm/remove_copy_if.h20
-rw-r--r--lib/libcxx/include/__algorithm/remove_if.h31
-rw-r--r--lib/libcxx/include/__algorithm/replace.h12
-rw-r--r--lib/libcxx/include/__algorithm/replace_copy.h23
-rw-r--r--lib/libcxx/include/__algorithm/replace_copy_if.h23
-rw-r--r--lib/libcxx/include/__algorithm/replace_if.h12
-rw-r--r--lib/libcxx/include/__algorithm/reverse.h45
-rw-r--r--lib/libcxx/include/__algorithm/reverse_copy.h12
-rw-r--r--lib/libcxx/include/__algorithm/rotate.h269
-rw-r--r--lib/libcxx/include/__algorithm/rotate_copy.h8
-rw-r--r--lib/libcxx/include/__algorithm/sample.h87
-rw-r--r--lib/libcxx/include/__algorithm/search.h125
-rw-r--r--lib/libcxx/include/__algorithm/search_n.h96
-rw-r--r--lib/libcxx/include/__algorithm/set_difference.h7
-rw-r--r--lib/libcxx/include/__algorithm/set_intersection.h5
-rw-r--r--lib/libcxx/include/__algorithm/set_symmetric_difference.h5
-rw-r--r--lib/libcxx/include/__algorithm/set_union.h5
-rw-r--r--lib/libcxx/include/__algorithm/shift_left.h48
-rw-r--r--lib/libcxx/include/__algorithm/shift_right.h128
-rw-r--r--lib/libcxx/include/__algorithm/shuffle.h127
-rw-r--r--lib/libcxx/include/__algorithm/sift_down.h141
-rw-r--r--lib/libcxx/include/__algorithm/sort.h282
-rw-r--r--lib/libcxx/include/__algorithm/sort_heap.h21
-rw-r--r--lib/libcxx/include/__algorithm/stable_partition.h492
-rw-r--r--lib/libcxx/include/__algorithm/stable_sort.h337
-rw-r--r--lib/libcxx/include/__algorithm/swap_ranges.h16
-rw-r--r--lib/libcxx/include/__algorithm/three_way_comp_ref_type.h8
-rw-r--r--lib/libcxx/include/__algorithm/transform.h29
-rw-r--r--lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h14
-rw-r--r--lib/libcxx/include/__algorithm/unique.h5
-rw-r--r--lib/libcxx/include/__algorithm/unique_copy.h5
-rw-r--r--lib/libcxx/include/__algorithm/unwrap_iter.h12
-rw-r--r--lib/libcxx/include/__algorithm/unwrap_range.h14
222 files changed, 5242 insertions, 3187 deletions
diff --git a/lib/libcxx/include/__algorithm/any_of.h b/lib/libcxx/include/__algorithm/any_of.h
index fe0882816b..8ba7aae2b2 100644
--- a/lib/libcxx/include/__algorithm/any_of.h
+++ b/lib/libcxx/include/__algorithm/any_of.h
@@ -19,7 +19,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
for (; __first != __last; ++__first)
if (__pred(*__first))
diff --git a/lib/libcxx/include/__algorithm/binary_search.h b/lib/libcxx/include/__algorithm/binary_search.h
index 0c8f5545e0..7a77d7b544 100644
--- a/lib/libcxx/include/__algorithm/binary_search.h
+++ b/lib/libcxx/include/__algorithm/binary_search.h
@@ -22,22 +22,16 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
-{
- __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
- return __first != __last && !__comp(__value, *__first);
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
+ __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
+ return __first != __last && !__comp(__value, *__first);
}
template <class _ForwardIterator, class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
-{
- return std::binary_search(__first, __last, __value, __less<>());
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ return std::binary_search(__first, __last, __value, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/clamp.h b/lib/libcxx/include/__algorithm/clamp.h
index 31deb4fd94..003bf70dd4 100644
--- a/lib/libcxx/include/__algorithm/clamp.h
+++ b/lib/libcxx/include/__algorithm/clamp.h
@@ -20,24 +20,22 @@
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 17
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY constexpr
-const _Tp&
-clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
-{
- _LIBCPP_ASSERT_UNCATEGORIZED(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
- return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
-
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
+clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
+ _LIBCPP_LIFETIMEBOUND const _Tp& __lo,
+ _LIBCPP_LIFETIMEBOUND const _Tp& __hi,
+ _Compare __comp) {
+ _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
+ return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY constexpr
-const _Tp&
-clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
-{
- return _VSTD::clamp(__v, __lo, __hi, __less<>());
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
+clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
+ _LIBCPP_LIFETIMEBOUND const _Tp& __lo,
+ _LIBCPP_LIFETIMEBOUND const _Tp& __hi) {
+ return std::clamp(__v, __lo, __hi, __less<>());
}
#endif
diff --git a/lib/libcxx/include/__algorithm/comp.h b/lib/libcxx/include/__algorithm/comp.h
index 9474536615..3902f75603 100644
--- a/lib/libcxx/include/__algorithm/comp.h
+++ b/lib/libcxx/include/__algorithm/comp.h
@@ -11,7 +11,7 @@
#include <__config>
#include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -26,8 +26,8 @@ struct __equal_to {
}
};
-template <class _Lhs, class _Rhs>
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <class _Tp, class _Up>
+struct __desugars_to<__equal_tag, __equal_to, _Tp, _Up> : true_type {};
// The definition is required because __less is part of the ABI, but it's empty
// because all comparisons should be transparent.
diff --git a/lib/libcxx/include/__algorithm/comp_ref_type.h b/lib/libcxx/include/__algorithm/comp_ref_type.h
index d16bd0f531..aa9350c38c 100644
--- a/lib/libcxx/include/__algorithm/comp_ref_type.h
+++ b/lib/libcxx/include/__algorithm/comp_ref_type.h
@@ -20,52 +20,41 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare>
-struct __debug_less
-{
- _Compare &__comp_;
- _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
+struct __debug_less {
+ _Compare& __comp_;
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
- template <class _Tp, class _Up>
- _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
- bool operator()(const _Tp& __x, const _Up& __y)
- {
- bool __r = __comp_(__x, __y);
- if (__r)
- __do_compare_assert(0, __y, __x);
- return __r;
- }
+ template <class _Tp, class _Up>
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) {
+ bool __r = __comp_(__x, __y);
+ if (__r)
+ __do_compare_assert(0, __y, __x);
+ return __r;
+ }
- template <class _Tp, class _Up>
- _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
- bool operator()(_Tp& __x, _Up& __y)
- {
- bool __r = __comp_(__x, __y);
- if (__r)
- __do_compare_assert(0, __y, __x);
- return __r;
- }
+ template <class _Tp, class _Up>
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) {
+ bool __r = __comp_(__x, __y);
+ if (__r)
+ __do_compare_assert(0, __y, __x);
+ return __r;
+ }
- template <class _LHS, class _RHS>
- _LIBCPP_CONSTEXPR_SINCE_CXX14
- inline _LIBCPP_INLINE_VISIBILITY
- decltype((void)std::declval<_Compare&>()(
- std::declval<_LHS &>(), std::declval<_RHS &>()))
- __do_compare_assert(int, _LHS & __l, _RHS & __r) {
- _LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r),
- "Comparator does not induce a strict weak ordering");
- (void)__l;
- (void)__r;
- }
+ template <class _LHS, class _RHS>
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(
+ std::declval<_LHS&>(), std::declval<_RHS&>()))
+ __do_compare_assert(int, _LHS& __l, _RHS& __r) {
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
+ (void)__l;
+ (void)__r;
+ }
- template <class _LHS, class _RHS>
- _LIBCPP_CONSTEXPR_SINCE_CXX14
- inline _LIBCPP_INLINE_VISIBILITY
- void __do_compare_assert(long, _LHS &, _RHS &) {}
+ template <class _LHS, class _RHS>
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {}
};
-// Pass the comparator by lvalue reference. Or in debug mode, using a
-// debugging wrapper that stores a reference.
-#if _LIBCPP_ENABLE_DEBUG_MODE
+// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
+#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
template <class _Comp>
using __comp_ref_type = __debug_less<_Comp>;
#else
diff --git a/lib/libcxx/include/__algorithm/copy.h b/lib/libcxx/include/__algorithm/copy.h
index dfe9898c64..4c3815405a 100644
--- a/lib/libcxx/include/__algorithm/copy.h
+++ b/lib/libcxx/include/__algorithm/copy.h
@@ -51,9 +51,10 @@ struct __copy_loop {
_OutIter& __result_;
- _LIBCPP_HIDE_FROM_ABI _CopySegment(_OutIter& __result) : __result_(__result) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _CopySegment(_OutIter& __result)
+ : __result_(__result) {}
- _LIBCPP_HIDE_FROM_ABI void
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
__result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
}
@@ -112,7 +113,7 @@ __copy(_InIter __first, _Sent __last, _OutIter __result) {
}
template <class _InputIterator, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second;
}
diff --git a/lib/libcxx/include/__algorithm/copy_backward.h b/lib/libcxx/include/__algorithm/copy_backward.h
index d85d297b32..3ec88d8bd5 100644
--- a/lib/libcxx/include/__algorithm/copy_backward.h
+++ b/lib/libcxx/include/__algorithm/copy_backward.h
@@ -108,8 +108,7 @@ struct __copy_backward_loop {
struct __copy_backward_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
- template <class _In, class _Out,
- __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
+ template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_backward_trivial_impl(__first, __last, __result);
@@ -124,16 +123,13 @@ __copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _Bidirectiona
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_BidirectionalIterator2
-copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
- _BidirectionalIterator2 __result)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
+copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value &&
- std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible.");
+ std::is_copy_constructible<_BidirectionalIterator1>::value,
+ "Iterators must be copy constructible.");
- return std::__copy_backward<_ClassicAlgPolicy>(
- std::move(__first), std::move(__last), std::move(__result)).second;
+ return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/copy_if.h b/lib/libcxx/include/__algorithm/copy_if.h
index a5938b8719..228e4d2232 100644
--- a/lib/libcxx/include/__algorithm/copy_if.h
+++ b/lib/libcxx/include/__algorithm/copy_if.h
@@ -17,21 +17,16 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _InputIterator, class _OutputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-copy_if(_InputIterator __first, _InputIterator __last,
- _OutputIterator __result, _Predicate __pred)
-{
- for (; __first != __last; ++__first)
- {
- if (__pred(*__first))
- {
- *__result = *__first;
- ++__result;
- }
+template <class _InputIterator, class _OutputIterator, class _Predicate>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
+ for (; __first != __last; ++__first) {
+ if (__pred(*__first)) {
+ *__result = *__first;
+ ++__result;
}
- return __result;
+ }
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/copy_move_common.h b/lib/libcxx/include/__algorithm/copy_move_common.h
index c06892e9e3..0fc7a5e3ce 100644
--- a/lib/libcxx/include/__algorithm/copy_move_common.h
+++ b/lib/libcxx/include/__algorithm/copy_move_common.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// Type traits.
@@ -38,22 +41,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _From, class _To>
struct __can_lower_copy_assignment_to_memmove {
static const bool value =
- // If the types are always bitcastable, it's valid to do a bitwise copy between them.
- __is_always_bitcastable<_From, _To>::value &&
- // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
- is_trivially_assignable<_To&, const _From&>::value &&
- // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
- !is_volatile<_From>::value &&
- !is_volatile<_To>::value;
+ // If the types are always bitcastable, it's valid to do a bitwise copy between them.
+ __is_always_bitcastable<_From, _To>::value &&
+ // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
+ is_trivially_assignable<_To&, const _From&>::value &&
+ // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
+ !is_volatile<_From>::value && !is_volatile<_To>::value;
};
template <class _From, class _To>
struct __can_lower_move_assignment_to_memmove {
static const bool value =
- __is_always_bitcastable<_From, _To>::value &&
- is_trivially_assignable<_To&, _From&&>::value &&
- !is_volatile<_From>::value &&
- !is_volatile<_To>::value;
+ __is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value &&
+ !is_volatile<_From>::value && !is_volatile<_To>::value;
};
// `memmove` algorithms implementation.
@@ -95,8 +95,8 @@ struct __can_rewrap<_InIter,
_Sent,
_OutIter,
// Note that sentinels are always copy-constructible.
- __enable_if_t< is_copy_constructible<_InIter>::value &&
- is_copy_constructible<_OutIter>::value > > : true_type {};
+ __enable_if_t< is_copy_constructible<_InIter>::value && is_copy_constructible<_OutIter>::value > >
+ : true_type {};
template <class _Algorithm,
class _InIter,
@@ -108,7 +108,7 @@ __unwrap_and_dispatch(_InIter __first, _Sent __last, _OutIter __out_first) {
auto __range = std::__unwrap_range(__first, std::move(__last));
auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)),
- std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
+ std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
}
template <class _Algorithm,
@@ -135,4 +135,6 @@ __dispatch_copy_or_move(_InIter __first, _Sent __last, _OutIter __out_first) {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
diff --git a/lib/libcxx/include/__algorithm/copy_n.h b/lib/libcxx/include/__algorithm/copy_n.h
index f3701662aa..f93f39203a 100644
--- a/lib/libcxx/include/__algorithm/copy_n.h
+++ b/lib/libcxx/include/__algorithm/copy_n.h
@@ -21,45 +21,38 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _InputIterator, class _Size, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-typename enable_if
-<
- __has_input_iterator_category<_InputIterator>::value &&
- !__has_random_access_iterator_category<_InputIterator>::value,
- _OutputIterator
->::type
-copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
-{
- typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
- _IntegralSize __n = __orig_n;
- if (__n > 0)
- {
- *__result = *__first;
- ++__result;
- for (--__n; __n > 0; --__n)
- {
- ++__first;
- *__result = *__first;
- ++__result;
- }
+template <class _InputIterator,
+ class _Size,
+ class _OutputIterator,
+ __enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
+ !__has_random_access_iterator_category<_InputIterator>::value,
+ int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
+ typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
+ _IntegralSize __n = __orig_n;
+ if (__n > 0) {
+ *__result = *__first;
+ ++__result;
+ for (--__n; __n > 0; --__n) {
+ ++__first;
+ *__result = *__first;
+ ++__result;
}
- return __result;
+ }
+ return __result;
}
-template<class _InputIterator, class _Size, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-typename enable_if
-<
- __has_random_access_iterator_category<_InputIterator>::value,
- _OutputIterator
->::type
-copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
-{
- typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
- typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
- _IntegralSize __n = __orig_n;
- return _VSTD::copy(__first, __first + difference_type(__n), __result);
+template <class _InputIterator,
+ class _Size,
+ class _OutputIterator,
+ __enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
+ typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
+ typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
+ _IntegralSize __n = __orig_n;
+ return std::copy(__first, __first + difference_type(__n), __result);
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/count.h b/lib/libcxx/include/__algorithm/count.h
index 6c8c7fda35..23a7d3c4dc 100644
--- a/lib/libcxx/include/__algorithm/count.h
+++ b/lib/libcxx/include/__algorithm/count.h
@@ -10,26 +10,83 @@
#ifndef _LIBCPP___ALGORITHM_COUNT_H
#define _LIBCPP___ALGORITHM_COUNT_H
+#include <__algorithm/iterator_operations.h>
+#include <__algorithm/min.h>
+#include <__bit/invert_if.h>
+#include <__bit/popcount.h>
#include <__config>
+#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__fwd/bit_reference.h>
#include <__iterator/iterator_traits.h>
#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 _InputIterator, class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
- typename iterator_traits<_InputIterator>::difference_type
- count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
- typename iterator_traits<_InputIterator>::difference_type __r(0);
+// generic implementation
+template <class _AlgPolicy, class _Iter, class _Sent, class _Tp, class _Proj>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>
+__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
+ typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0);
for (; __first != __last; ++__first)
- if (*__first == __value)
+ if (std::__invoke(__proj, *__first) == __value)
++__r;
return __r;
}
+// __bit_iterator implementation
+template <bool _ToCount, class _Cp, bool _IsConst>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
+ using _It = __bit_iterator<_Cp, _IsConst>;
+ using __storage_type = typename _It::__storage_type;
+ using difference_type = typename _It::difference_type;
+
+ const int __bits_per_word = _It::__bits_per_word;
+ difference_type __r = 0;
+ // do first partial word
+ if (__first.__ctz_ != 0) {
+ __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+ __storage_type __dn = std::min(__clz_f, __n);
+ __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+ __r = std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
+ __n -= __dn;
+ ++__first.__seg_;
+ }
+ // do middle whole words
+ for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
+ __r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_));
+ // do last partial word
+ if (__n > 0) {
+ __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+ __r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
+ }
+ return __r;
+}
+
+template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
+__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
+ if (__value)
+ return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
+ return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
+}
+
+template <class _InputIterator, class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
+count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
+ __identity __proj;
+ return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);
+}
+
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_COUNT_H
diff --git a/lib/libcxx/include/__algorithm/count_if.h b/lib/libcxx/include/__algorithm/count_if.h
index b96521fe0a..04f52b894f 100644
--- a/lib/libcxx/include/__algorithm/count_if.h
+++ b/lib/libcxx/include/__algorithm/count_if.h
@@ -20,7 +20,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
typename iterator_traits<_InputIterator>::difference_type
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
typename iterator_traits<_InputIterator>::difference_type __r(0);
diff --git a/lib/libcxx/include/__algorithm/equal.h b/lib/libcxx/include/__algorithm/equal.h
index b69aeff92b..3c0e3060e3 100644
--- a/lib/libcxx/include/__algorithm/equal.h
+++ b/lib/libcxx/include/__algorithm/equal.h
@@ -23,13 +23,16 @@
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
#include <__utility/move.h>
#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 _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -41,13 +44,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
return true;
}
-template <
- class _Tp,
- class _Up,
- class _BinaryPredicate,
- __enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
- !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
- int> = 0>
+template <class _Tp,
+ class _Up,
+ class _BinaryPredicate,
+ __enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) {
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
@@ -69,8 +71,13 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
#if _LIBCPP_STD_VER >= 14
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
- _BinaryPredicate __pred, input_iterator_tag, input_iterator_tag) {
+__equal(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _BinaryPredicate __pred,
+ input_iterator_tag,
+ input_iterator_tag) {
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2))
return false;
@@ -94,21 +101,25 @@ template <class _Tp,
class _Pred,
class _Proj1,
class _Proj2,
- __enable_if_t<__is_trivial_equality_predicate<_Pred, _Tp, _Up>::value && __is_identity<_Proj1>::value &&
+ __enable_if_t<__desugars_to<__equal_tag, _Pred, _Tp, _Up>::value && __is_identity<_Proj1>::value &&
__is_identity<_Proj2>::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
- _Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+__equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
- _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag,
+__equal(_RandomAccessIterator1 __first1,
+ _RandomAccessIterator1 __last1,
+ _RandomAccessIterator2 __first2,
+ _RandomAccessIterator2 __last2,
+ _BinaryPredicate __pred,
+ random_access_iterator_tag,
random_access_iterator_tag) {
- if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
+ if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
return false;
__identity __proj;
return std::__equal_impl(
@@ -123,10 +134,18 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
+equal(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
_BinaryPredicate __pred) {
- return _VSTD::__equal<_BinaryPredicate&>(
- __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
+ return std::__equal<_BinaryPredicate&>(
+ __first1,
+ __last1,
+ __first2,
+ __last2,
+ __pred,
+ typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
@@ -146,4 +165,6 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_EQUAL_H
diff --git a/lib/libcxx/include/__algorithm/equal_range.h b/lib/libcxx/include/__algorithm/equal_range.h
index dc1268a6ff..a942904319 100644
--- a/lib/libcxx/include/__algorithm/equal_range.h
+++ b/lib/libcxx/include/__algorithm/equal_range.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
@@ -49,9 +52,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
__len = __half_len;
} else {
_Iter __mp1 = __mid;
- return pair<_Iter, _Iter>(
- std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
- std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
+ return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
+ std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
}
}
return pair<_Iter, _Iter>(__first, __first);
@@ -60,10 +62,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
- static_assert(is_copy_constructible<_ForwardIterator>::value,
- "Iterator has to be copy constructible");
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
return std::__equal_range<_ClassicAlgPolicy>(
std::move(__first),
std::move(__last),
@@ -80,4 +80,6 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H
diff --git a/lib/libcxx/include/__algorithm/fill.h b/lib/libcxx/include/__algorithm/fill.h
index 0753c427ae..1ce3eadb01 100644
--- a/lib/libcxx/include/__algorithm/fill.h
+++ b/lib/libcxx/include/__algorithm/fill.h
@@ -22,28 +22,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
-{
- for (; __first != __last; ++__first)
- *__first = __value;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) {
+ for (; __first != __last; ++__first)
+ *__first = __value;
}
template <class _RandomAccessIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
-{
- _VSTD::fill_n(__first, __last - __first, __value);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) {
+ std::fill_n(__first, __last - __first, __value);
}
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
-{
- _VSTD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/fill_n.h b/lib/libcxx/include/__algorithm/fill_n.h
index e7863ac7ec..36f3349d9e 100644
--- a/lib/libcxx/include/__algorithm/fill_n.h
+++ b/lib/libcxx/include/__algorithm/fill_n.h
@@ -22,21 +22,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
template <class _OutputIterator, class _Size, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
-{
- for (; __n > 0; ++__first, (void) --__n)
- *__first = __value;
- return __first;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
+ for (; __n > 0; ++__first, (void)--__n)
+ *__first = __value;
+ return __first;
}
template <class _OutputIterator, class _Size, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
-{
- return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
+ return std::__fill_n(__first, std::__convert_to_integral(__n), __value);
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/find.h b/lib/libcxx/include/__algorithm/find.h
index e0de503287..7d7631b6e9 100644
--- a/lib/libcxx/include/__algorithm/find.h
+++ b/lib/libcxx/include/__algorithm/find.h
@@ -10,12 +10,22 @@
#ifndef _LIBCPP___ALGORITHM_FIND_H
#define _LIBCPP___ALGORITHM_FIND_H
+#include <__algorithm/find_segment_if.h>
+#include <__algorithm/min.h>
#include <__algorithm/unwrap_iter.h>
+#include <__bit/countr.h>
+#include <__bit/invert_if.h>
#include <__config>
#include <__functional/identity.h>
#include <__functional/invoke.h>
+#include <__fwd/bit_reference.h>
+#include <__iterator/segmented_iterator.h>
#include <__string/constexpr_c_functions.h>
+#include <__type_traits/is_integral.h>
#include <__type_traits/is_same.h>
+#include <__type_traits/is_signed.h>
+#include <__utility/move.h>
+#include <limits>
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
# include <cwchar>
@@ -25,8 +35,12 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
+// generic implementation
template <class _Iter, class _Sent, class _Tp, class _Proj>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
__find_impl(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
@@ -36,6 +50,7 @@ __find_impl(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
return __first;
}
+// trivially equality comparable implementations
template <class _Tp,
class _Up,
class _Proj,
@@ -64,8 +79,97 @@ __find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
}
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+// TODO: This should also be possible to get right with different signedness
+// cast integral types to allow vectorization
+template <class _Tp,
+ class _Up,
+ class _Proj,
+ __enable_if_t<__is_identity<_Proj>::value && !__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value &&
+ is_integral<_Tp>::value && is_integral<_Up>::value &&
+ is_signed<_Tp>::value == is_signed<_Up>::value,
+ int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
+__find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
+ if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max())
+ return __last;
+ return std::__find_impl(__first, __last, _Tp(__value), __proj);
+}
+
+// __bit_iterator implementation
+template <bool _ToFind, class _Cp, bool _IsConst>
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst>
+__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
+ using _It = __bit_iterator<_Cp, _IsConst>;
+ using __storage_type = typename _It::__storage_type;
+
+ const int __bits_per_word = _It::__bits_per_word;
+ // do first partial word
+ if (__first.__ctz_ != 0) {
+ __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+ __storage_type __dn = std::min(__clz_f, __n);
+ __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+ __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
+ if (__b)
+ return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
+ if (__n == __dn)
+ return __first + __n;
+ __n -= __dn;
+ ++__first.__seg_;
+ }
+ // do middle whole words
+ for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) {
+ __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_);
+ if (__b)
+ return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
+ }
+ // do last partial word
+ if (__n > 0) {
+ __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+ __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
+ if (__b)
+ return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
+ }
+ return _It(__first.__seg_, static_cast<unsigned>(__n));
+}
+
+template <class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst>
+__find_impl(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
+ if (static_cast<bool>(__value))
+ return std::__find_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
+ return std::__find_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
+}
+
+// segmented iterator implementation
+
+template <class>
+struct __find_segment;
+
+template <class _SegmentedIterator,
+ class _Tp,
+ class _Proj,
+ __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
+__find_impl(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) {
+ return std::__find_segment_if(std::move(__first), std::move(__last), __find_segment<_Tp>(__value), __proj);
+}
+
+template <class _Tp>
+struct __find_segment {
+ const _Tp& __value_;
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __find_segment(const _Tp& __value) : __value_(__value) {}
+
+ template <class _InputIterator, class _Proj>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _InputIterator
+ operator()(_InputIterator __first, _InputIterator __last, _Proj& __proj) const {
+ return std::__find_impl(__first, __last, __value_, __proj);
+ }
+};
+
+// public API
template <class _InputIterator, class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
__identity __proj;
return std::__rewrap_iter(
@@ -74,4 +178,6 @@ find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_FIND_H
diff --git a/lib/libcxx/include/__algorithm/find_end.h b/lib/libcxx/include/__algorithm/find_end.h
index edb9891c66..4c26891666 100644
--- a/lib/libcxx/include/__algorithm/find_end.h
+++ b/lib/libcxx/include/__algorithm/find_end.h
@@ -28,15 +28,14 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template <
- class _AlgPolicy,
- class _Iter1,
- class _Sent1,
- class _Iter2,
- class _Sent2,
- class _Pred,
- class _Proj1,
- class _Proj2>
+template < class _AlgPolicy,
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Pred,
+ class _Proj1,
+ class _Proj2>
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl(
_Iter1 __first1,
_Sent1 __last1,
@@ -49,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
forward_iterator_tag) {
// modeled after search algorithm
_Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer
- _Iter1 __match_last = __match_first;
+ _Iter1 __match_last = __match_first;
if (__first2 == __last2)
return pair<_Iter1, _Iter1>(__match_last, __match_last);
while (true) {
@@ -66,15 +65,14 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
while (true) {
if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one
__match_first = __first1;
- __match_last = ++__m1;
+ __match_last = ++__m1;
++__first1;
break;
}
if (++__m1 == __last1) // Source exhausted, return last answer
return pair<_Iter1, _Iter1>(__match_first, __match_last);
- // mismatch, restart with a new __first
- if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2)))
- {
+ // mismatch, restart with a new __first
+ if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
++__first1;
break;
} // else there is a match, check next elements
@@ -82,15 +80,14 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
}
}
-template <
- class _IterOps,
- class _Pred,
- class _Iter1,
- class _Sent1,
- class _Iter2,
- class _Sent2,
- class _Proj1,
- class _Proj2>
+template < class _IterOps,
+ class _Pred,
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
_Iter1 __first1,
_Sent1 __sent1,
@@ -127,23 +124,21 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
return __last1;
// if there is a mismatch, restart with a new __l1
- if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2)))
- {
+ if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) {
break;
} // else there is a match, check next elements
}
}
}
-template <
- class _AlgPolicy,
- class _Pred,
- class _Iter1,
- class _Sent1,
- class _Iter2,
- class _Sent2,
- class _Proj1,
- class _Proj2>
+template < class _AlgPolicy,
+ class _Pred,
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
_Iter1 __first1,
_Sent1 __sent1,
@@ -165,8 +160,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
if (__len1 < __len2)
return __last1;
const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
- _Iter1 __l1 = __last1;
- _Iter2 __l2 = __last2;
+ _Iter1 __l1 = __last1;
+ _Iter2 __l2 = __last2;
--__l2;
while (true) {
while (true) {
@@ -189,10 +184,12 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-_ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2,
- _BinaryPredicate& __pred) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate& __pred) {
auto __proj = __identity();
return std::__find_end_impl<_ClassicAlgPolicy>(
__first1,
@@ -208,17 +205,18 @@ _ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterato
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2,
- _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate __pred) {
return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
+find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
}
diff --git a/lib/libcxx/include/__algorithm/find_first_of.h b/lib/libcxx/include/__algorithm/find_first_of.h
index 12f0109a61..14271cccc4 100644
--- a/lib/libcxx/include/__algorithm/find_first_of.h
+++ b/lib/libcxx/include/__algorithm/find_first_of.h
@@ -21,12 +21,12 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_HIDE_FROM_ABI
-_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
- _ForwardIterator1 __last1,
- _ForwardIterator2 __first2,
- _ForwardIterator2 __last2,
- _BinaryPredicate&& __pred) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate&& __pred) {
for (; __first1 != __last1; ++__first1)
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
if (__pred(*__first1, *__j))
@@ -35,14 +35,17 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardItera
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
-find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
- _ForwardIterator2 __last2, _BinaryPredicate __pred) {
- return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate __pred) {
+ return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to());
}
diff --git a/lib/libcxx/include/__algorithm/find_if.h b/lib/libcxx/include/__algorithm/find_if.h
index f4ef3ac31c..09a39f6463 100644
--- a/lib/libcxx/include/__algorithm/find_if.h
+++ b/lib/libcxx/include/__algorithm/find_if.h
@@ -19,7 +19,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
for (; __first != __last; ++__first)
if (__pred(*__first))
diff --git a/lib/libcxx/include/__algorithm/find_if_not.h b/lib/libcxx/include/__algorithm/find_if_not.h
index 96c159cf5e..bf29ebb7cd 100644
--- a/lib/libcxx/include/__algorithm/find_if_not.h
+++ b/lib/libcxx/include/__algorithm/find_if_not.h
@@ -19,7 +19,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
for (; __first != __last; ++__first)
if (!__pred(*__first))
diff --git a/lib/libcxx/include/__algorithm/find_segment_if.h b/lib/libcxx/include/__algorithm/find_segment_if.h
new file mode 100644
index 0000000000..9d6064f3e2
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/find_segment_if.h
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_FIND_SEGMENT_IF_H
+#define _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H
+
+#include <__config>
+#include <__iterator/segmented_iterator.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// __find_segment_if is a utility function for optimizing iteration over segmented iterators linearly.
+// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators and the __proj.
+// It returns an iterator to the first element that satisfies the predicate, or a one-past-the-end iterator if there was
+// no match. __proj may be anything that should be passed to __pred, but is expected to be a projection to support
+// ranges algorithms, or __identity for classic algorithms.
+
+template <class _SegmentedIterator, class _Pred, class _Proj>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
+__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj& __proj) {
+ using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
+
+ auto __sfirst = _Traits::__segment(__first);
+ auto __slast = _Traits::__segment(__last);
+
+ // We are in a single segment, so we might not be at the beginning or end
+ if (__sfirst == __slast)
+ return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last), __proj));
+
+ { // We have more than one segment. Iterate over the first segment, since we might not start at the beginning
+ auto __llast = _Traits::__end(__sfirst);
+ auto __liter = __pred(_Traits::__local(__first), __llast, __proj);
+ if (__liter != __llast)
+ return _Traits::__compose(__sfirst, __liter);
+ }
+ ++__sfirst;
+
+ // Iterate over the segments which are guaranteed to be completely in the range
+ while (__sfirst != __slast) {
+ auto __llast = _Traits::__end(__sfirst);
+ auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), __proj);
+ if (__liter != __llast)
+ return _Traits::__compose(__sfirst, __liter);
+ ++__sfirst;
+ }
+
+ // Iterate over the last segment
+ return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last), __proj));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H
diff --git a/lib/libcxx/include/__algorithm/fold.h b/lib/libcxx/include/__algorithm/fold.h
new file mode 100644
index 0000000000..1a9d76b50d
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/fold.h
@@ -0,0 +1,130 @@
+// -*- 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___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#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 >= 23
+
+namespace ranges {
+template <class _Ip, class _Tp>
+struct in_value_result {
+ _LIBCPP_NO_UNIQUE_ADDRESS _Ip in;
+ _LIBCPP_NO_UNIQUE_ADDRESS _Tp value;
+
+ template <class _I2, class _T2>
+ requires convertible_to<const _Ip&, _I2> && convertible_to<const _Tp&, _T2>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() const& {
+ return {in, value};
+ }
+
+ template <class _I2, class _T2>
+ requires convertible_to<_Ip, _I2> && convertible_to<_Tp, _T2>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() && {
+ return {std::move(in), std::move(value)};
+ }
+};
+
+template <class _Ip, class _Tp>
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template <class _Fp, class _Tp, class _Ip, class _Rp, class _Up = decay_t<_Rp>>
+concept __indirectly_binary_left_foldable_impl =
+ convertible_to<_Rp, _Up> && //
+ movable<_Tp> && //
+ movable<_Up> && //
+ convertible_to<_Tp, _Up> && //
+ invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+ assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template <class _Fp, class _Tp, class _Ip>
+concept __indirectly_binary_left_foldable =
+ copy_constructible<_Fp> && //
+ invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+ __indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+ template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+ operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+ using _Up = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+ if (__first == __last) {
+ return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), _Up(std::move(__init))};
+ }
+
+ _Up __result = std::invoke(__f, std::move(__init), *__first);
+ for (++__first; __first != __last; ++__first) {
+ __result = std::invoke(__f, std::move(__result), *__first);
+ }
+
+ return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), std::move(__result)};
+ }
+
+ template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+ auto __result = operator()(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f));
+
+ using _Up = decay_t<invoke_result_t<_Fp&, _Tp, range_reference_t<_Rp>>>;
+ return fold_left_with_iter_result<borrowed_iterator_t<_Rp>, _Up>{std::move(__result.in), std::move(__result.value)};
+ }
+};
+
+inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
+
+struct __fold_left {
+ template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+ operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+ return fold_left_with_iter(std::move(__first), std::move(__last), std::move(__init), std::ref(__f)).value;
+ }
+
+ template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+ return fold_left_with_iter(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)).value;
+ }
+};
+
+inline constexpr auto fold_left = __fold_left();
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_FOLD_H
diff --git a/lib/libcxx/include/__algorithm/for_each.h b/lib/libcxx/include/__algorithm/for_each.h
index 6564f31cd0..259e527f87 100644
--- a/lib/libcxx/include/__algorithm/for_each.h
+++ b/lib/libcxx/include/__algorithm/for_each.h
@@ -10,23 +10,48 @@
#ifndef _LIBCPP___ALGORITHM_FOR_EACH_H
#define _LIBCPP___ALGORITHM_FOR_EACH_H
+#include <__algorithm/for_each_segment.h>
#include <__config>
+#include <__iterator/segmented_iterator.h>
+#include <__ranges/movable_box.h>
+#include <__type_traits/enable_if.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
#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 _InputIterator, class _Function>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function for_each(_InputIterator __first,
- _InputIterator __last,
- _Function __f) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
+for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
for (; __first != __last; ++__first)
__f(*__first);
return __f;
}
+// __movable_box is available in C++20, but is actually a copyable-box, so optimization is only correct in C++23
+#if _LIBCPP_STD_VER >= 23
+template <class _SegmentedIterator, class _Function>
+ requires __is_segmented_iterator<_SegmentedIterator>::value
+_LIBCPP_HIDE_FROM_ABI constexpr _Function
+for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) {
+ ranges::__movable_box<_Function> __wrapped_func(in_place, std::move(__func));
+ std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
+ __wrapped_func =
+ ranges::__movable_box<_Function>(in_place, std::for_each(__lfirst, __llast, std::move(*__wrapped_func)));
+ });
+ return std::move(*__wrapped_func);
+}
+#endif // _LIBCPP_STD_VER >= 23
+
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_FOR_EACH_H
diff --git a/lib/libcxx/include/__algorithm/for_each_n.h b/lib/libcxx/include/__algorithm/for_each_n.h
index 5bd7318224..fce380b49d 100644
--- a/lib/libcxx/include/__algorithm/for_each_n.h
+++ b/lib/libcxx/include/__algorithm/for_each_n.h
@@ -22,10 +22,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 17
template <class _InputIterator, class _Size, class _Function>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator for_each_n(_InputIterator __first,
- _Size __orig_n,
- _Function __f) {
- typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
+for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) {
+ typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n;
while (__n > 0) {
__f(*__first);
diff --git a/lib/libcxx/include/__algorithm/generate.h b/lib/libcxx/include/__algorithm/generate.h
index 48e21b51e6..c95b527402 100644
--- a/lib/libcxx/include/__algorithm/generate.h
+++ b/lib/libcxx/include/__algorithm/generate.h
@@ -18,12 +18,10 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Generator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
-{
- for (; __first != __last; ++__first)
- *__first = __gen();
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
+ for (; __first != __last; ++__first)
+ *__first = __gen();
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/generate_n.h b/lib/libcxx/include/__algorithm/generate_n.h
index ff5c82d3e4..f36403fd0f 100644
--- a/lib/libcxx/include/__algorithm/generate_n.h
+++ b/lib/libcxx/include/__algorithm/generate_n.h
@@ -19,15 +19,13 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _OutputIterator, class _Size, class _Generator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
-{
- typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
- _IntegralSize __n = __orig_n;
- for (; __n > 0; ++__first, (void) --__n)
- *__first = __gen();
- return __first;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) {
+ typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
+ _IntegralSize __n = __orig_n;
+ for (; __n > 0; ++__first, (void)--__n)
+ *__first = __gen();
+ return __first;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/half_positive.h b/lib/libcxx/include/__algorithm/half_positive.h
index 5a0f4baf6a..ebda0da372 100644
--- a/lib/libcxx/include/__algorithm/half_positive.h
+++ b/lib/libcxx/include/__algorithm/half_positive.h
@@ -22,28 +22,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// Perform division by two quickly for positive integers (llvm.org/PR39129)
-template <typename _Integral>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
- is_integral<_Integral>::value,
- _Integral
->::type
-__half_positive(_Integral __value)
-{
- return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);
+template <typename _Integral, __enable_if_t<is_integral<_Integral>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Integral __half_positive(_Integral __value) {
+ return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);
}
-template <typename _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
- !is_integral<_Tp>::value,
- _Tp
->::type
-__half_positive(_Tp __value)
-{
- return __value / 2;
+template <typename _Tp, __enable_if_t<!is_integral<_Tp>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp __half_positive(_Tp __value) {
+ return __value / 2;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/in_found_result.h b/lib/libcxx/include/__algorithm/in_found_result.h
index d9ca287f01..a67ae38797 100644
--- a/lib/libcxx/include/__algorithm/in_found_result.h
+++ b/lib/libcxx/include/__algorithm/in_found_result.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -30,7 +33,7 @@ struct in_found_result {
template <class _InIter2>
requires convertible_to<const _InIter1&, _InIter2>
- _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const & {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const& {
return {in, found};
}
@@ -46,4 +49,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
diff --git a/lib/libcxx/include/__algorithm/in_fun_result.h b/lib/libcxx/include/__algorithm/in_fun_result.h
index 33374eddc3..a22069a9a8 100644
--- a/lib/libcxx/include/__algorithm/in_fun_result.h
+++ b/lib/libcxx/include/__algorithm/in_fun_result.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -30,7 +33,7 @@ struct in_fun_result {
template <class _InIter2, class _Func2>
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _Func1&, _Func2>
- _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const & {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const& {
return {in, fun};
}
@@ -46,4 +49,6 @@ struct in_fun_result {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
diff --git a/lib/libcxx/include/__algorithm/in_in_out_result.h b/lib/libcxx/include/__algorithm/in_in_out_result.h
index 6b50e0e245..ba0380b5c6 100644
--- a/lib/libcxx/include/__algorithm/in_in_out_result.h
+++ b/lib/libcxx/include/__algorithm/in_in_out_result.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -31,18 +34,16 @@ struct in_in_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
template <class _InIter3, class _InIter4, class _OutIter2>
- requires convertible_to<const _InIter1&, _InIter3>
- && convertible_to<const _InIter2&, _InIter4> && convertible_to<const _OutIter1&, _OutIter2>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
+ requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4> &&
+ convertible_to<const _OutIter1&, _OutIter2>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
return {in1, in2, out};
}
template <class _InIter3, class _InIter4, class _OutIter2>
- requires convertible_to<_InIter1, _InIter3>
- && convertible_to<_InIter2, _InIter4> && convertible_to<_OutIter1, _OutIter2>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
+ requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> &&
+ convertible_to<_OutIter1, _OutIter2>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
return {std::move(in1), std::move(in2), std::move(out)};
}
};
@@ -53,4 +54,6 @@ struct in_in_out_result {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H
diff --git a/lib/libcxx/include/__algorithm/in_in_result.h b/lib/libcxx/include/__algorithm/in_in_result.h
index 1eceb9de02..994573fc70 100644
--- a/lib/libcxx/include/__algorithm/in_in_result.h
+++ b/lib/libcxx/include/__algorithm/in_in_result.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -31,15 +34,13 @@ struct in_in_result {
template <class _InIter3, class _InIter4>
requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_in_result<_InIter3, _InIter4>() const & {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() const& {
return {in1, in2};
}
template <class _InIter3, class _InIter4>
requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_in_result<_InIter3, _InIter4>() && {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() && {
return {std::move(in1), std::move(in2)};
}
};
@@ -50,4 +51,6 @@ struct in_in_result {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H
diff --git a/lib/libcxx/include/__algorithm/in_out_out_result.h b/lib/libcxx/include/__algorithm/in_out_out_result.h
index 2f7a09b5c3..8ceb452841 100644
--- a/lib/libcxx/include/__algorithm/in_out_out_result.h
+++ b/lib/libcxx/include/__algorithm/in_out_out_result.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -30,18 +33,16 @@ struct in_out_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2;
template <class _InIter2, class _OutIter3, class _OutIter4>
- requires convertible_to<const _InIter1&, _InIter2>
- && convertible_to<const _OutIter1&, _OutIter3> && convertible_to<const _OutIter2&, _OutIter4>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
+ requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter3> &&
+ convertible_to<const _OutIter2&, _OutIter4>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
return {in, out1, out2};
}
template <class _InIter2, class _OutIter3, class _OutIter4>
- requires convertible_to<_InIter1, _InIter2>
- && convertible_to<_OutIter1, _OutIter3> && convertible_to<_OutIter2, _OutIter4>
- _LIBCPP_HIDE_FROM_ABI constexpr
- operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
+ requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter3> &&
+ convertible_to<_OutIter2, _OutIter4>
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
return {std::move(in), std::move(out1), std::move(out2)};
}
};
@@ -51,4 +52,6 @@ struct in_out_out_result {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
diff --git a/lib/libcxx/include/__algorithm/in_out_result.h b/lib/libcxx/include/__algorithm/in_out_result.h
index e4741cb71f..a7a986cf8e 100644
--- a/lib/libcxx/include/__algorithm/in_out_result.h
+++ b/lib/libcxx/include/__algorithm/in_out_result.h
@@ -27,22 +27,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
-template<class _InIter1, class _OutIter1>
+template <class _InIter1, class _OutIter1>
struct in_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
template <class _InIter2, class _OutIter2>
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter2>
- _LIBCPP_HIDE_FROM_ABI
- constexpr operator in_out_result<_InIter2, _OutIter2>() const & {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() const& {
return {in, out};
}
template <class _InIter2, class _OutIter2>
requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2>
- _LIBCPP_HIDE_FROM_ABI
- constexpr operator in_out_result<_InIter2, _OutIter2>() && {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() && {
return {std::move(in), std::move(out)};
}
};
diff --git a/lib/libcxx/include/__algorithm/includes.h b/lib/libcxx/include/__algorithm/includes.h
index 88253e2653..05d45365eb 100644
--- a/lib/libcxx/include/__algorithm/includes.h
+++ b/lib/libcxx/include/__algorithm/includes.h
@@ -22,15 +22,23 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
- _Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Comp&& __comp,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
for (; __first2 != __last2; ++__first1) {
- if (__first1 == __last1 || std::__invoke(
- __comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
+ if (__first1 == __last1 ||
+ std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
return false;
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
++__first2;
@@ -39,14 +47,14 @@ __includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes(
- _InputIterator1 __first1,
- _InputIterator1 __last1,
- _InputIterator2 __first2,
- _InputIterator2 __last2,
- _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
- "Comparator has to be callable");
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+includes(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _Compare __comp) {
+ static_assert(
+ __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
return std::__includes(
std::move(__first1),
@@ -66,4 +74,6 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_INCLUDES_H
diff --git a/lib/libcxx/include/__algorithm/inplace_merge.h b/lib/libcxx/include/__algorithm/inplace_merge.h
index 44a9425559..eb3c0bdbc2 100644
--- a/lib/libcxx/include/__algorithm/inplace_merge.h
+++ b/lib/libcxx/include/__algorithm/inplace_merge.h
@@ -42,54 +42,57 @@ template <class _Predicate>
class __invert // invert the sense of a comparison
{
private:
- _Predicate __p_;
+ _Predicate __p_;
+
public:
- _LIBCPP_INLINE_VISIBILITY __invert() {}
+ _LIBCPP_HIDE_FROM_ABI __invert() {}
- _LIBCPP_INLINE_VISIBILITY
- explicit __invert(_Predicate __p) : __p_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {}
- template <class _T1>
- _LIBCPP_INLINE_VISIBILITY
- bool operator()(const _T1& __x) {return !__p_(__x);}
+ template <class _T1>
+ _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) {
+ return !__p_(__x);
+ }
- template <class _T1, class _T2>
- _LIBCPP_INLINE_VISIBILITY
- bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);}
+ template <class _T1, class _T2>
+ _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) {
+ return __p_(__y, __x);
+ }
};
-template <class _AlgPolicy, class _Compare, class _InputIterator1, class _Sent1,
- class _InputIterator2, class _Sent2, class _OutputIterator>
-_LIBCPP_HIDE_FROM_ABI
-void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
- _InputIterator2 __first2, _Sent2 __last2,
- _OutputIterator __result, _Compare&& __comp)
-{
- for (; __first1 != __last1; ++__result)
- {
- if (__first2 == __last2)
- {
- std::__move<_AlgPolicy>(__first1, __last1, __result);
- return;
- }
+template <class _AlgPolicy,
+ class _Compare,
+ class _InputIterator1,
+ class _Sent1,
+ class _InputIterator2,
+ class _Sent2,
+ class _OutputIterator>
+_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(
+ _InputIterator1 __first1,
+ _Sent1 __last1,
+ _InputIterator2 __first2,
+ _Sent2 __last2,
+ _OutputIterator __result,
+ _Compare&& __comp) {
+ for (; __first1 != __last1; ++__result) {
+ if (__first2 == __last2) {
+ std::__move<_AlgPolicy>(__first1, __last1, __result);
+ return;
+ }
- if (__comp(*__first2, *__first1))
- {
- *__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
- ++__first2;
- }
- else
- {
- *__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
- ++__first1;
- }
+ if (__comp(*__first2, *__first1)) {
+ *__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
+ ++__first2;
+ } else {
+ *__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
+ ++__first1;
}
- // __first2 through __last2 are already in the right spot.
+ }
+ // __first2 through __last2 are already in the right spot.
}
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
-_LIBCPP_HIDE_FROM_ABI
-void __buffered_inplace_merge(
+_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge(
_BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last,
@@ -98,27 +101,25 @@ void __buffered_inplace_merge(
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff) {
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
- if (__len1 <= __len2)
- {
- value_type* __p = __buff;
- for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
- ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
- std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
- }
- else
- {
- value_type* __p = __buff;
- for (_BidirectionalIterator __i = __middle; __i != __last; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
- ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
- typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
- typedef __unconstrained_reverse_iterator<value_type*> _Rv;
- typedef __invert<_Compare> _Inverted;
- std::__half_inplace_merge<_AlgPolicy>(_Rv(__p), _Rv(__buff),
- _RBi(__middle), _RBi(__first),
- _RBi(__last), _Inverted(__comp));
- }
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
+ if (__len1 <= __len2) {
+ value_type* __p = __buff;
+ for (_BidirectionalIterator __i = __first; __i != __middle;
+ __d.template __incr<value_type>(), (void)++__i, (void)++__p)
+ ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
+ std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
+ } else {
+ value_type* __p = __buff;
+ for (_BidirectionalIterator __i = __middle; __i != __last;
+ __d.template __incr<value_type>(), (void)++__i, (void)++__p)
+ ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
+ typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
+ typedef __unconstrained_reverse_iterator<value_type*> _Rv;
+ typedef __invert<_Compare> _Inverted;
+ std::__half_inplace_merge<_AlgPolicy>(
+ _Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp));
+ }
}
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
@@ -131,107 +132,92 @@ void __inplace_merge(
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff,
ptrdiff_t __buff_size) {
- using _Ops = _IterOps<_AlgPolicy>;
-
- typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
- while (true)
- {
- // if __middle == __last, we're done
- if (__len2 == 0)
- return;
- if (__len1 <= __buff_size || __len2 <= __buff_size)
- return std::__buffered_inplace_merge<_AlgPolicy>
- (__first, __middle, __last, __comp, __len1, __len2, __buff);
- // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
- for (; true; ++__first, (void) --__len1)
- {
- if (__len1 == 0)
- return;
- if (__comp(*__middle, *__first))
- break;
- }
- // __first < __middle < __last
- // *__first > *__middle
- // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
- // all elements in:
- // [__first, __m1) <= [__middle, __m2)
- // [__middle, __m2) < [__m1, __middle)
- // [__m1, __middle) <= [__m2, __last)
- // and __m1 or __m2 is in the middle of its range
- _BidirectionalIterator __m1; // "median" of [__first, __middle)
- _BidirectionalIterator __m2; // "median" of [__middle, __last)
- difference_type __len11; // distance(__first, __m1)
- difference_type __len21; // distance(__middle, __m2)
- // binary search smaller range
- if (__len1 < __len2)
- { // __len >= 1, __len2 >= 2
- __len21 = __len2 / 2;
- __m2 = __middle;
- _Ops::advance(__m2, __len21);
- __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
- __len11 = _Ops::distance(__first, __m1);
- }
- else
- {
- if (__len1 == 1)
- { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
- // It is known *__first > *__middle
- _Ops::iter_swap(__first, __middle);
- return;
- }
- // __len1 >= 2, __len2 >= 1
- __len11 = __len1 / 2;
- __m1 = __first;
- _Ops::advance(__m1, __len11);
- __m2 = std::lower_bound(__middle, __last, *__m1, __comp);
- __len21 = _Ops::distance(__middle, __m2);
- }
- difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
- difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
- // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
- // swap middle two partitions
- __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
- // __len12 and __len21 now have swapped meanings
- // merge smaller range with recursive call and larger with tail recursion elimination
- if (__len11 + __len21 < __len12 + __len22)
- {
- std::__inplace_merge<_AlgPolicy>(
- __first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
- __first = __middle;
- __middle = __m2;
- __len1 = __len12;
- __len2 = __len22;
- }
- else
- {
- std::__inplace_merge<_AlgPolicy>(
- __middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
- __last = __middle;
- __middle = __m1;
- __len1 = __len11;
- __len2 = __len21;
- }
+ using _Ops = _IterOps<_AlgPolicy>;
+
+ typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+ while (true) {
+ // if __middle == __last, we're done
+ if (__len2 == 0)
+ return;
+ if (__len1 <= __buff_size || __len2 <= __buff_size)
+ return std::__buffered_inplace_merge<_AlgPolicy>(__first, __middle, __last, __comp, __len1, __len2, __buff);
+ // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
+ for (; true; ++__first, (void)--__len1) {
+ if (__len1 == 0)
+ return;
+ if (__comp(*__middle, *__first))
+ break;
}
+ // __first < __middle < __last
+ // *__first > *__middle
+ // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
+ // all elements in:
+ // [__first, __m1) <= [__middle, __m2)
+ // [__middle, __m2) < [__m1, __middle)
+ // [__m1, __middle) <= [__m2, __last)
+ // and __m1 or __m2 is in the middle of its range
+ _BidirectionalIterator __m1; // "median" of [__first, __middle)
+ _BidirectionalIterator __m2; // "median" of [__middle, __last)
+ difference_type __len11; // distance(__first, __m1)
+ difference_type __len21; // distance(__middle, __m2)
+ // binary search smaller range
+ if (__len1 < __len2) { // __len >= 1, __len2 >= 2
+ __len21 = __len2 / 2;
+ __m2 = __middle;
+ _Ops::advance(__m2, __len21);
+ __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
+ __len11 = _Ops::distance(__first, __m1);
+ } else {
+ if (__len1 == 1) { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
+ // It is known *__first > *__middle
+ _Ops::iter_swap(__first, __middle);
+ return;
+ }
+ // __len1 >= 2, __len2 >= 1
+ __len11 = __len1 / 2;
+ __m1 = __first;
+ _Ops::advance(__m1, __len11);
+ __m2 = std::lower_bound(__middle, __last, *__m1, __comp);
+ __len21 = _Ops::distance(__middle, __m2);
+ }
+ difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
+ difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
+ // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
+ // swap middle two partitions
+ __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
+ // __len12 and __len21 now have swapped meanings
+ // merge smaller range with recursive call and larger with tail recursion elimination
+ if (__len11 + __len21 < __len12 + __len22) {
+ std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
+ __first = __middle;
+ __middle = __m2;
+ __len1 = __len12;
+ __len2 = __len22;
+ } else {
+ std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
+ __last = __middle;
+ __middle = __m1;
+ __len1 = __len11;
+ __len2 = __len21;
+ }
+ }
}
template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
-_LIBCPP_HIDE_FROM_ABI
-void
-__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
- _Compare&& __comp)
-{
- typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
- difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
- difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
- difference_type __buf_size = _VSTD::min(__len1, __len2);
-// TODO: Remove the use of std::get_temporary_buffer
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size);
-_LIBCPP_SUPPRESS_DEPRECATED_POP
- unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
- return std::__inplace_merge<_AlgPolicy>(
- std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
+_LIBCPP_HIDE_FROM_ABI void __inplace_merge(
+ _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) {
+ typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+ typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+ difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
+ difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
+ difference_type __buf_size = std::min(__len1, __len2);
+ // TODO: Remove the use of std::get_temporary_buffer
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ pair<value_type*, ptrdiff_t> __buf = std::get_temporary_buffer<value_type>(__buf_size);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
+ return std::__inplace_merge<_AlgPolicy>(
+ std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
}
template <class _BidirectionalIterator, class _Compare>
@@ -242,11 +228,9 @@ inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
}
template <class _BidirectionalIterator>
-inline _LIBCPP_HIDE_FROM_ABI
-void
-inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
-{
- std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>());
+inline _LIBCPP_HIDE_FROM_ABI void
+inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) {
+ std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/is_heap.h b/lib/libcxx/include/__algorithm/is_heap.h
index 93d84d3380..0d2d43c2c3 100644
--- a/lib/libcxx/include/__algorithm/is_heap.h
+++ b/lib/libcxx/include/__algorithm/is_heap.h
@@ -22,21 +22,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _RandomAccessIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
-{
- return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+ return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
}
-template<class _RandomAccessIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
-{
- return _VSTD::is_heap(__first, __last, __less<>());
+template <class _RandomAccessIterator>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+ return std::is_heap(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/is_heap_until.h b/lib/libcxx/include/__algorithm/is_heap_until.h
index d7131114bd..1eae3b86b9 100644
--- a/lib/libcxx/include/__algorithm/is_heap_until.h
+++ b/lib/libcxx/include/__algorithm/is_heap_until.h
@@ -22,43 +22,39 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
-__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
-{
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- difference_type __len = __last - __first;
- difference_type __p = 0;
- difference_type __c = 1;
- _RandomAccessIterator __pp = __first;
- while (__c < __len)
- {
- _RandomAccessIterator __cp = __first + __c;
- if (__comp(*__pp, *__cp))
- return __cp;
- ++__c;
- ++__cp;
- if (__c == __len)
- return __last;
- if (__comp(*__pp, *__cp))
- return __cp;
- ++__p;
- ++__pp;
- __c = 2 * __p + 1;
- }
- return __last;
+__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ difference_type __len = __last - __first;
+ difference_type __p = 0;
+ difference_type __c = 1;
+ _RandomAccessIterator __pp = __first;
+ while (__c < __len) {
+ _RandomAccessIterator __cp = __first + __c;
+ if (__comp(*__pp, *__cp))
+ return __cp;
+ ++__c;
+ ++__cp;
+ if (__c == __len)
+ return __last;
+ if (__comp(*__pp, *__cp))
+ return __cp;
+ ++__p;
+ ++__pp;
+ __c = 2 * __p + 1;
+ }
+ return __last;
}
template <class _RandomAccessIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
-is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
-{
- return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
+is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+ return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
}
-template<class _RandomAccessIterator>
+template <class _RandomAccessIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
-is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
-{
- return _VSTD::__is_heap_until(__first, __last, __less<>());
+is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+ return std::__is_heap_until(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/is_partitioned.h b/lib/libcxx/include/__algorithm/is_partitioned.h
index ab59d3cce5..71feed3320 100644
--- a/lib/libcxx/include/__algorithm/is_partitioned.h
+++ b/lib/libcxx/include/__algorithm/is_partitioned.h
@@ -19,18 +19,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
-{
- for (; __first != __last; ++__first)
- if (!__pred(*__first))
- break;
- if ( __first == __last )
- return true;
- ++__first;
- for (; __first != __last; ++__first)
- if (__pred(*__first))
- return false;
+is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
+ for (; __first != __last; ++__first)
+ if (!__pred(*__first))
+ break;
+ if (__first == __last)
return true;
+ ++__first;
+ for (; __first != __last; ++__first)
+ if (__pred(*__first))
+ return false;
+ return true;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/is_permutation.h b/lib/libcxx/include/__algorithm/is_permutation.h
index 105a073228..4226151222 100644
--- a/lib/libcxx/include/__algorithm/is_permutation.h
+++ b/lib/libcxx/include/__algorithm/is_permutation.h
@@ -37,18 +37,24 @@ struct _ConstTimeDistance : false_type {};
#if _LIBCPP_STD_VER >= 20
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2>
-struct _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2, __enable_if_t<
- sized_sentinel_for<_Sent1, _Iter1> &&
- sized_sentinel_for<_Sent2, _Iter2>
->> : true_type {};
+struct _ConstTimeDistance<_Iter1,
+ _Sent1,
+ _Iter2,
+ _Sent2,
+ __enable_if_t< sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2> >>
+ : true_type {};
#else
template <class _Iter1, class _Iter2>
-struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t<
- is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value &&
- is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value
-> > : true_type {};
+struct _ConstTimeDistance<
+ _Iter1,
+ _Iter1,
+ _Iter2,
+ _Iter2,
+ __enable_if_t< is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value &&
+ is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value > >
+ : true_type {};
#endif // _LIBCPP_STD_VER >= 20
@@ -56,11 +62,21 @@ struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t<
// For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2)
template <class _AlgPolicy,
- class _Iter1, class _Sent1, class _Iter2, class _Sent2,
- class _Proj1, class _Proj2, class _Pred>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
- _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2,
+ class _Pred>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
using _D1 = __iter_diff_t<_Iter1>;
for (auto __i = __first1; __i != __last1; ++__i) {
@@ -97,9 +113,8 @@ __is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 _
// 2+1 iterators, predicate. Not used by range algorithms.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2,
- _BinaryPredicate&& __pred) {
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
+ _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) {
// Shorten sequences as much as possible by lopping of any equal prefix.
for (; __first1 != __last1; ++__first1, (void)++__first2) {
if (!__pred(*__first1, *__first2))
@@ -111,24 +126,39 @@ __is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterato
// __first1 != __last1 && *__first1 != *__first2
using _D1 = __iter_diff_t<_ForwardIterator1>;
- _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
+ _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
if (__l1 == _D1(1))
return false;
auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1);
return std::__is_permutation_impl<_AlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
- __pred, __identity(), __identity());
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ __pred,
+ __identity(),
+ __identity());
}
// 2+2 iterators, predicate, non-constant time `distance`.
template <class _AlgPolicy,
- class _Iter1, class _Sent1, class _Iter2, class _Sent2,
- class _Proj1, class _Proj2, class _Pred>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
- _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
- /*_ConstTimeDistance=*/false_type) {
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2,
+ class _Pred>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2,
+ /*_ConstTimeDistance=*/false_type) {
// Shorten sequences as much as possible by lopping of any equal prefix.
while (__first1 != __last1 && __first2 != __last2) {
if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
@@ -143,44 +173,73 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
return false;
using _D1 = __iter_diff_t<_Iter1>;
- _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
+ _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
using _D2 = __iter_diff_t<_Iter2>;
- _D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
+ _D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
if (__l1 != __l2)
return false;
return std::__is_permutation_impl<_AlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
- __pred, __proj1, __proj2);
+ std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
}
// 2+2 iterators, predicate, specialization for constant-time `distance` call.
template <class _AlgPolicy,
- class _Iter1, class _Sent1, class _Iter2, class _Sent2,
- class _Proj1, class _Proj2, class _Pred>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
- _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
- /*_ConstTimeDistance=*/true_type) {
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2,
+ class _Pred>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2,
+ /*_ConstTimeDistance=*/true_type) {
if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
return false;
return std::__is_permutation<_AlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
- __pred, __proj1, __proj2,
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ __pred,
+ __proj1,
+ __proj2,
/*_ConstTimeDistance=*/false_type());
}
// 2+2 iterators, predicate
template <class _AlgPolicy,
- class _Iter1, class _Sent1, class _Iter2, class _Sent2,
- class _Proj1, class _Proj2, class _Pred>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
- _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Proj1,
+ class _Proj2,
+ class _Pred>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
return std::__is_permutation<_AlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
- __pred, __proj1, __proj2,
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ __pred,
+ __proj1,
+ __proj2,
_ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>());
}
@@ -188,14 +247,12 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
// 2+1 iterators, predicate
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
- _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
+ _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
- return std::__is_permutation<_ClassicAlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), __pred);
+ return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred);
}
// 2+1 iterators
@@ -223,15 +280,23 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
// 2+2 iterators, predicate
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
- _ForwardIterator2 __last2, _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
return std::__is_permutation<_ClassicAlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
- __pred, __identity(), __identity());
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ __pred,
+ __identity(),
+ __identity());
}
#endif // _LIBCPP_STD_VER >= 14
diff --git a/lib/libcxx/include/__algorithm/is_sorted.h b/lib/libcxx/include/__algorithm/is_sorted.h
index a321c2c12d..1874cace88 100644
--- a/lib/libcxx/include/__algorithm/is_sorted.h
+++ b/lib/libcxx/include/__algorithm/is_sorted.h
@@ -22,21 +22,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
}
-template<class _ForwardIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-is_sorted(_ForwardIterator __first, _ForwardIterator __last)
-{
- return _VSTD::is_sorted(__first, __last, __less<>());
+template <class _ForwardIterator>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+is_sorted(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::is_sorted(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/is_sorted_until.h b/lib/libcxx/include/__algorithm/is_sorted_until.h
index 890b93631c..7450440df2 100644
--- a/lib/libcxx/include/__algorithm/is_sorted_until.h
+++ b/lib/libcxx/include/__algorithm/is_sorted_until.h
@@ -22,33 +22,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- if (__first != __last)
- {
- _ForwardIterator __i = __first;
- while (++__i != __last)
- {
- if (__comp(*__i, *__first))
- return __i;
- __first = __i;
- }
+__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ if (__first != __last) {
+ _ForwardIterator __i = __first;
+ while (++__i != __last) {
+ if (__comp(*__i, *__first))
+ return __i;
+ __first = __i;
}
- return __last;
+ }
+ return __last;
}
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
+is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
}
-template<class _ForwardIterator>
+template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
-{
- return _VSTD::is_sorted_until(__first, __last, __less<>());
+is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::is_sorted_until(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/iter_swap.h b/lib/libcxx/include/__algorithm/iter_swap.h
index 44422b5de0..a1412e5d87 100644
--- a/lib/libcxx/include/__algorithm/iter_swap.h
+++ b/lib/libcxx/include/__algorithm/iter_swap.h
@@ -20,8 +20,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a,
- _ForwardIterator2 __b)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
_NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) {
swap(*__a, *__b);
diff --git a/lib/libcxx/include/__algorithm/iterator_operations.h b/lib/libcxx/include/__algorithm/iterator_operations.h
index 002978014c..5cf13f0a3f 100644
--- a/lib/libcxx/include/__algorithm/iterator_operations.h
+++ b/lib/libcxx/include/__algorithm/iterator_operations.h
@@ -38,14 +38,14 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _AlgPolicy> struct _IterOps;
+template <class _AlgPolicy>
+struct _IterOps;
#if _LIBCPP_STD_VER >= 20
struct _RangeAlgPolicy {};
template <>
struct _IterOps<_RangeAlgPolicy> {
-
template <class _Iter>
using __value_type = iter_value_t<_Iter>;
@@ -55,12 +55,12 @@ struct _IterOps<_RangeAlgPolicy> {
template <class _Iter>
using __difference_type = iter_difference_t<_Iter>;
- static constexpr auto advance = ranges::advance;
- static constexpr auto distance = ranges::distance;
- static constexpr auto __iter_move = ranges::iter_move;
- static constexpr auto iter_swap = ranges::iter_swap;
- static constexpr auto next = ranges::next;
- static constexpr auto prev = ranges::prev;
+ static constexpr auto advance = ranges::advance;
+ static constexpr auto distance = ranges::distance;
+ static constexpr auto __iter_move = ranges::iter_move;
+ static constexpr auto iter_swap = ranges::iter_swap;
+ static constexpr auto next = ranges::next;
+ static constexpr auto prev = ranges::prev;
static constexpr auto __advance_to = ranges::advance;
};
@@ -70,7 +70,6 @@ struct _ClassicAlgPolicy {};
template <>
struct _IterOps<_ClassicAlgPolicy> {
-
template <class _Iter>
using __value_type = typename iterator_traits<_Iter>::value_type;
@@ -82,15 +81,14 @@ struct _IterOps<_ClassicAlgPolicy> {
// advance
template <class _Iter, class _Distance>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- static void advance(_Iter& __iter, _Distance __count) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) {
std::advance(__iter, __count);
}
// distance
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static typename iterator_traits<_Iter>::difference_type
+ distance(_Iter __first, _Iter __last) {
return std::distance(__first, __last);
}
@@ -101,37 +99,33 @@ struct _IterOps<_ClassicAlgPolicy> {
using __move_t = decltype(std::move(*std::declval<_Iter&>()));
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- static void __validate_iter_reference() {
- static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value,
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() {
+ static_assert(
+ is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value,
"It looks like your iterator's `iterator_traits<It>::reference` does not match the return type of "
"dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] "
"and can lead to dangling reference issues at runtime, so we are flagging this.");
}
// iter_move
- template <class _Iter>
+ template <class _Iter, __enable_if_t<is_reference<__deref_t<_Iter> >::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static
- // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. Note
- // that the C++03 mode doesn't support `decltype(auto)` as the return type.
- __enable_if_t<
- is_reference<__deref_t<_Iter> >::value,
- __move_t<_Iter> >
- __iter_move(_Iter&& __i) {
+ // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it.
+ // Note that the C++03 mode doesn't support `decltype(auto)` as the return type.
+ __move_t<_Iter>
+ __iter_move(_Iter&& __i) {
__validate_iter_reference<_Iter>();
return std::move(*std::forward<_Iter>(__i));
}
- template <class _Iter>
+ template <class _Iter, __enable_if_t<!is_reference<__deref_t<_Iter> >::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static
- // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a
- // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to that
- // temporary. Note that the C++03 mode doesn't support `auto` as the return type.
- __enable_if_t<
- !is_reference<__deref_t<_Iter> >::value,
- __deref_t<_Iter> >
- __iter_move(_Iter&& __i) {
+ // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a
+ // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to
+ // that temporary. Note that the C++03 mode doesn't support `auto` as the return type.
+ __deref_t<_Iter>
+ __iter_move(_Iter&& __i) {
__validate_iter_reference<_Iter>();
return *std::forward<_Iter>(__i);
@@ -139,36 +133,31 @@ struct _IterOps<_ClassicAlgPolicy> {
// iter_swap
template <class _Iter1, class _Iter2>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b));
}
// next
template <class _Iterator>
- _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
- _Iterator next(_Iterator, _Iterator __last) {
+ _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator next(_Iterator, _Iterator __last) {
return __last;
}
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
- __remove_cvref_t<_Iter> next(_Iter&& __it,
- typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
+ _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
+ next(_Iter&& __it, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
return std::next(std::forward<_Iter>(__it), __n);
}
// prev
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
- __remove_cvref_t<_Iter> prev(_Iter&& __iter,
- typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
+ _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
+ prev(_Iter&& __iter, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
return std::prev(std::forward<_Iter>(__iter), __n);
}
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
- void __advance_to(_Iter& __first, _Iter __last) {
+ _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 void __advance_to(_Iter& __first, _Iter __last) {
__first = __last;
}
};
diff --git a/lib/libcxx/include/__algorithm/lexicographical_compare.h b/lib/libcxx/include/__algorithm/lexicographical_compare.h
index 62b72edc80..3efd8e24bf 100644
--- a/lib/libcxx/include/__algorithm/lexicographical_compare.h
+++ b/lib/libcxx/include/__algorithm/lexicographical_compare.h
@@ -21,38 +21,35 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _InputIterator1, class _InputIterator2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
-__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
-{
- for (; __first2 != __last2; ++__first1, (void) ++__first2)
- {
- if (__first1 == __last1 || __comp(*__first1, *__first2))
- return true;
- if (__comp(*__first2, *__first1))
- return false;
- }
- return false;
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _Compare __comp) {
+ for (; __first2 != __last2; ++__first1, (void)++__first2) {
+ if (__first1 == __last1 || __comp(*__first1, *__first2))
+ return true;
+ if (__comp(*__first2, *__first1))
+ return false;
+ }
+ return false;
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
-{
- return _VSTD::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _Compare __comp) {
+ return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
}
template <class _InputIterator1, class _InputIterator2>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2)
-{
- return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
+ _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
+ return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/lower_bound.h b/lib/libcxx/include/__algorithm/lower_bound.h
index 91c3bdaafd..8f57f3592c 100644
--- a/lib/libcxx/include/__algorithm/lower_bound.h
+++ b/lib/libcxx/include/__algorithm/lower_bound.h
@@ -28,8 +28,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
+__lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
while (__len != 0) {
@@ -47,17 +47,16 @@ _Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __
}
template <class _ForwardIterator, class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
auto __proj = std::__identity();
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
}
template <class _ForwardIterator, class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
return std::lower_bound(__first, __last, __value, __less<>());
}
diff --git a/lib/libcxx/include/__algorithm/make_heap.h b/lib/libcxx/include/__algorithm/make_heap.h
index eaf9259c0b..e8f0cdb273 100644
--- a/lib/libcxx/include/__algorithm/make_heap.h
+++ b/lib/libcxx/include/__algorithm/make_heap.h
@@ -27,29 +27,29 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
__comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
- difference_type __n = __last - __first;
+ difference_type __n = __last - __first;
if (__n > 1) {
// start from the first parent, there is no need to consider children
for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) {
- std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
+ std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
}
}
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::make_heap(std::move(__first), std::move(__last), __less<>());
}
diff --git a/lib/libcxx/include/__algorithm/make_projected.h b/lib/libcxx/include/__algorithm/make_projected.h
index ec854763a5..bb7bc7e8c0 100644
--- a/lib/libcxx/include/__algorithm/make_projected.h
+++ b/lib/libcxx/include/__algorithm/make_projected.h
@@ -36,44 +36,38 @@ struct _ProjectedPred {
: __pred(__pred_arg), __proj(__proj_arg) {}
template <class _Tp>
- typename __invoke_of<_Pred&,
- decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))
- >::type
- _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_Tp&& __v) const {
+ typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>())) >::
+ type _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
+ operator()(_Tp&& __v) const {
return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
}
template <class _T1, class _T2>
typename __invoke_of<_Pred&,
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
- decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))
- >::type
- _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_T1&& __lhs, _T2&& __rhs) const {
- return std::__invoke(__pred,
- std::__invoke(__proj, std::forward<_T1>(__lhs)),
- std::__invoke(__proj, std::forward<_T2>(__rhs)));
+ decltype(std::__invoke(std::declval<_Proj&>(),
+ std::declval<_T2>())) >::type _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
+ operator()(_T1&& __lhs, _T2&& __rhs) const {
+ return std::__invoke(
+ __pred, std::__invoke(__proj, std::forward<_T1>(__lhs)), std::__invoke(__proj, std::forward<_T2>(__rhs)));
}
-
};
-template <class _Pred,
- class _Proj,
- __enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value &&
- __is_identity<__decay_t<_Proj> >::value),
- int> = 0>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj>
-__make_projected(_Pred& __pred, _Proj& __proj) {
+template <
+ class _Pred,
+ class _Proj,
+ __enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj) {
return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
}
// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable
// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in
// the call stack when the comparator is invoked, even in an unoptimized build.
-template <class _Pred,
- class _Proj,
- __enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value &&
- __is_identity<__decay_t<_Proj> >::value,
- int> = 0>
+template <
+ class _Pred,
+ class _Proj,
+ __enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) {
return __pred;
}
@@ -87,8 +81,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template <class _Comp, class _Proj1, class _Proj2>
-_LIBCPP_HIDE_FROM_ABI constexpr
-decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
+_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
if constexpr (__is_identity<decay_t<_Proj1>>::value && __is_identity<decay_t<_Proj2>>::value &&
!is_member_pointer_v<decay_t<_Comp>>) {
// Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
@@ -96,10 +89,10 @@ decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __p
return __comp;
} else {
- return [&](auto&& __lhs, auto&& __rhs) {
+ return [&](auto&& __lhs, auto&& __rhs) -> bool {
return std::invoke(__comp,
- std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
- std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
+ std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
+ std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
};
}
}
diff --git a/lib/libcxx/include/__algorithm/max.h b/lib/libcxx/include/__algorithm/max.h
index 5d8e64cfff..8171677f15 100644
--- a/lib/libcxx/include/__algorithm/max.h
+++ b/lib/libcxx/include/__algorithm/max.h
@@ -25,41 +25,28 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-const _Tp&
-max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
-{
- return __comp(__a, __b) ? __b : __a;
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
+max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
+ return __comp(__a, __b) ? __b : __a;
}
template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-const _Tp&
-max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
-{
- return _VSTD::max(__a, __b, __less<>());
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
+max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
+ return std::max(__a, __b, __less<>());
}
#ifndef _LIBCPP_CXX03_LANG
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Tp
-max(initializer_list<_Tp> __t, _Compare __comp)
-{
- return *_VSTD::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
+max(initializer_list<_Tp> __t, _Compare __comp) {
+ return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Tp
-max(initializer_list<_Tp> __t)
-{
- return *_VSTD::max_element(__t.begin(), __t.end(), __less<>());
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {
+ return *std::max_element(__t.begin(), __t.end(), __less<>());
}
#endif // _LIBCPP_CXX03_LANG
diff --git a/lib/libcxx/include/__algorithm/max_element.h b/lib/libcxx/include/__algorithm/max_element.h
index 8fd52c7772..f1d4f1cd09 100644
--- a/lib/libcxx/include/__algorithm/max_element.h
+++ b/lib/libcxx/include/__algorithm/max_element.h
@@ -22,33 +22,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::max_element requires a ForwardIterator");
- if (__first != __last)
- {
- _ForwardIterator __i = __first;
- while (++__i != __last)
- if (__comp(*__first, *__i))
- __first = __i;
- }
- return __first;
+__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ static_assert(
+ __has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator");
+ if (__first != __last) {
+ _ForwardIterator __i = __first;
+ while (++__i != __last)
+ if (__comp(*__first, *__i))
+ __first = __i;
+ }
+ return __first;
}
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- return _VSTD::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
+max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
}
-
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last)
-{
- return _VSTD::max_element(__first, __last, __less<>());
+max_element(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::max_element(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/merge.h b/lib/libcxx/include/__algorithm/merge.h
index 7ee7aaad71..bad663c4b9 100644
--- a/lib/libcxx/include/__algorithm/merge.h
+++ b/lib/libcxx/include/__algorithm/merge.h
@@ -22,45 +22,46 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-__merge(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
-{
- for (; __first1 != __last1; ++__result)
- {
- if (__first2 == __last2)
- return _VSTD::copy(__first1, __last1, __result);
- if (__comp(*__first2, *__first1))
- {
- *__result = *__first2;
- ++__first2;
- }
- else
- {
- *__result = *__first1;
- ++__first1;
- }
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _OutputIterator __result,
+ _Compare __comp) {
+ for (; __first1 != __last1; ++__result) {
+ if (__first2 == __last2)
+ return std::copy(__first1, __last1, __result);
+ if (__comp(*__first2, *__first1)) {
+ *__result = *__first2;
+ ++__first2;
+ } else {
+ *__result = *__first1;
+ ++__first1;
}
- return _VSTD::copy(__first2, __last2, __result);
+ }
+ return std::copy(__first2, __last2, __result);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-merge(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
-{
- return _VSTD::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+merge(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _OutputIterator __result,
+ _Compare __comp) {
+ return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-merge(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
-{
- return _VSTD::merge(__first1, __last1, __first2, __last2, __result, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+merge(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _OutputIterator __result) {
+ return std::merge(__first1, __last1, __first2, __last2, __result, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/min.h b/lib/libcxx/include/__algorithm/min.h
index 3c0debd6b0..919508486f 100644
--- a/lib/libcxx/include/__algorithm/min.h
+++ b/lib/libcxx/include/__algorithm/min.h
@@ -25,41 +25,28 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-const _Tp&
-min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
-{
- return __comp(__b, __a) ? __b : __a;
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
+min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
+ return __comp(__b, __a) ? __b : __a;
}
template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-const _Tp&
-min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
-{
- return _VSTD::min(__a, __b, __less<>());
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
+min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
+ return std::min(__a, __b, __less<>());
}
#ifndef _LIBCPP_CXX03_LANG
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Tp
-min(initializer_list<_Tp> __t, _Compare __comp)
-{
- return *_VSTD::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
+min(initializer_list<_Tp> __t, _Compare __comp) {
+ return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Tp
-min(initializer_list<_Tp> __t)
-{
- return *_VSTD::min_element(__t.begin(), __t.end(), __less<>());
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) {
+ return *std::min_element(__t.begin(), __t.end(), __less<>());
}
#endif // _LIBCPP_CXX03_LANG
diff --git a/lib/libcxx/include/__algorithm/min_element.h b/lib/libcxx/include/__algorithm/min_element.h
index 45f3e85ef9..c576d66560 100644
--- a/lib/libcxx/include/__algorithm/min_element.h
+++ b/lib/libcxx/include/__algorithm/min_element.h
@@ -28,8 +28,8 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Comp, class _Iter, class _Sent, class _Proj>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
+__min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
if (__first == __last)
return __first;
@@ -42,29 +42,26 @@ _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
}
template <class _Comp, class _Iter, class _Sent>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
auto __proj = __identity();
return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj);
}
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::min_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ static_assert(
+ __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last)
-{
- return _VSTD::min_element(__first, __last, __less<>());
+min_element(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::min_element(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/min_max_result.h b/lib/libcxx/include/__algorithm/min_max_result.h
index ef2d990380..e988df7c11 100644
--- a/lib/libcxx/include/__algorithm/min_max_result.h
+++ b/lib/libcxx/include/__algorithm/min_max_result.h
@@ -34,7 +34,7 @@ struct min_max_result {
template <class _T2>
requires convertible_to<const _T1&, _T2>
- _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const & {
+ _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const& {
return {min, max};
}
diff --git a/lib/libcxx/include/__algorithm/minmax.h b/lib/libcxx/include/__algorithm/minmax.h
index bdcf57b101..5227b88571 100644
--- a/lib/libcxx/include/__algorithm/minmax.h
+++ b/lib/libcxx/include/__algorithm/minmax.h
@@ -23,43 +23,33 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<const _Tp&, const _Tp&>
-minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
-{
- return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
- pair<const _Tp&, const _Tp&>(__a, __b);
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
+minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
+ return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<const _Tp&, const _Tp&>
-minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
-{
- return std::minmax(__a, __b, __less<>());
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
+minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
+ return std::minmax(__a, __b, __less<>());
}
#ifndef _LIBCPP_CXX03_LANG
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
- static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
- __identity __proj;
- auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
- return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t, _Compare __comp) {
+ static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
+ __identity __proj;
+ auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
+ return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Tp, _Tp>
-minmax(initializer_list<_Tp> __t)
-{
- return std::minmax(__t, __less<>());
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t) {
+ return std::minmax(__t, __less<>());
}
#endif // _LIBCPP_CXX03_LANG
diff --git a/lib/libcxx/include/__algorithm/minmax_element.h b/lib/libcxx/include/__algorithm/minmax_element.h
index 5bcaf8354d..ff8cda321c 100644
--- a/lib/libcxx/include/__algorithm/minmax_element.h
+++ b/lib/libcxx/include/__algorithm/minmax_element.h
@@ -29,19 +29,18 @@ class _MinmaxElementLessFunc {
_Proj& __proj_;
public:
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
- _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj)
+ : __comp_(__comp), __proj_(__proj) {}
template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- bool operator()(_Iter& __it1, _Iter& __it2) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Iter& __it1, _Iter& __it2) {
return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
}
};
template <class _Iter, class _Sent, class _Proj, class _Comp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter>
+__minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
pair<_Iter, _Iter> __result(__first, __first);
@@ -66,8 +65,8 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c
if (__less(__first, __i)) {
if (__less(__first, __result.first))
__result.first = __first;
- if (!__less(__i, __result.second))
- __result.second = __i;
+ if (!__less(__i, __result.second))
+ __result.second = __i;
} else {
if (__less(__i, __result.first))
__result.first = __i;
@@ -80,21 +79,21 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c
}
template <class _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_ForwardIterator, _ForwardIterator>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
+ static_assert(
+ __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator");
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
- return std::minmax_element(__first, __last, __less<>());
+ pair<_ForwardIterator, _ForwardIterator>
+ minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::minmax_element(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/mismatch.h b/lib/libcxx/include/__algorithm/mismatch.h
index e5b014f457..d345b6048a 100644
--- a/lib/libcxx/include/__algorithm/mismatch.h
+++ b/lib/libcxx/include/__algorithm/mismatch.h
@@ -22,9 +22,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
- mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
for (; __first1 != __last1; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2))
break;
@@ -32,18 +31,19 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
}
template <class _InputIterator1, class _InputIterator2>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
- mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
return std::mismatch(__first1, __last1, __first2, __equal_to());
}
#if _LIBCPP_STD_VER >= 14
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
- mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
- _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _BinaryPredicate __pred) {
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2))
break;
@@ -51,9 +51,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
}
template <class _InputIterator1, class _InputIterator2>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
- mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
}
#endif
diff --git a/lib/libcxx/include/__algorithm/move.h b/lib/libcxx/include/__algorithm/move.h
index 01aeef4e17..dba6d487ff 100644
--- a/lib/libcxx/include/__algorithm/move.h
+++ b/lib/libcxx/include/__algorithm/move.h
@@ -52,9 +52,10 @@ struct __move_loop {
_OutIter& __result_;
- _LIBCPP_HIDE_FROM_ABI _MoveSegment(_OutIter& __result) : __result_(__result) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _MoveSegment(_OutIter& __result)
+ : __result_(__result) {}
- _LIBCPP_HIDE_FROM_ABI void
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
__result_ = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
}
@@ -98,8 +99,7 @@ struct __move_loop {
struct __move_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
- template <class _In, class _Out,
- __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
+ template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_trivial_impl(__first, __last, __result);
diff --git a/lib/libcxx/include/__algorithm/move_backward.h b/lib/libcxx/include/__algorithm/move_backward.h
index e396abfe0d..aeedf4241d 100644
--- a/lib/libcxx/include/__algorithm/move_backward.h
+++ b/lib/libcxx/include/__algorithm/move_backward.h
@@ -108,8 +108,7 @@ struct __move_backward_loop {
struct __move_backward_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
- template <class _In, class _Out,
- __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
+ template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_backward_trivial_impl(__first, __last, __result);
@@ -120,14 +119,15 @@ template <class _AlgPolicy, class _BidirectionalIterator1, class _Sentinel, clas
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2>
__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) {
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value &&
- std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible.");
+ std::is_copy_constructible<_BidirectionalIterator1>::value,
+ "Iterators must be copy constructible.");
return std::__dispatch_copy_or_move<_AlgPolicy, __move_backward_loop<_AlgPolicy>, __move_backward_trivial>(
std::move(__first), std::move(__last), std::move(__result));
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
}
diff --git a/lib/libcxx/include/__algorithm/next_permutation.h b/lib/libcxx/include/__algorithm/next_permutation.h
index d89768ddc1..011ee028cc 100644
--- a/lib/libcxx/include/__algorithm/next_permutation.h
+++ b/lib/libcxx/include/__algorithm/next_permutation.h
@@ -22,56 +22,54 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
-__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
-{
- using _Result = pair<_BidirectionalIterator, bool>;
+__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
+ using _Result = pair<_BidirectionalIterator, bool>;
- _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
- _BidirectionalIterator __i = __last_iter;
- if (__first == __last || __first == --__i)
- return _Result(std::move(__last_iter), false);
+ _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
+ _BidirectionalIterator __i = __last_iter;
+ if (__first == __last || __first == --__i)
+ return _Result(std::move(__last_iter), false);
- while (true)
- {
- _BidirectionalIterator __ip1 = __i;
- if (__comp(*--__i, *__ip1))
- {
- _BidirectionalIterator __j = __last_iter;
- while (!__comp(*__i, *--__j))
- ;
- _IterOps<_AlgPolicy>::iter_swap(__i, __j);
- std::__reverse<_AlgPolicy>(__ip1, __last_iter);
- return _Result(std::move(__last_iter), true);
- }
- if (__i == __first)
- {
- std::__reverse<_AlgPolicy>(__first, __last_iter);
- return _Result(std::move(__last_iter), false);
- }
+ while (true) {
+ _BidirectionalIterator __ip1 = __i;
+ if (__comp(*--__i, *__ip1)) {
+ _BidirectionalIterator __j = __last_iter;
+ while (!__comp(*__i, *--__j))
+ ;
+ _IterOps<_AlgPolicy>::iter_swap(__i, __j);
+ std::__reverse<_AlgPolicy>(__ip1, __last_iter);
+ return _Result(std::move(__last_iter), true);
+ }
+ if (__i == __first) {
+ std::__reverse<_AlgPolicy>(__first, __last_iter);
+ return _Result(std::move(__last_iter), false);
}
+ }
}
template <class _BidirectionalIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
return std::__next_permutation<_ClassicAlgPolicy>(
- std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second;
+ std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp))
+ .second;
}
template <class _BidirectionalIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
-{
- return _VSTD::next_permutation(__first, __last, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
+ return std::next_permutation(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
diff --git a/lib/libcxx/include/__algorithm/none_of.h b/lib/libcxx/include/__algorithm/none_of.h
index 19357eb236..ce59187a3a 100644
--- a/lib/libcxx/include/__algorithm/none_of.h
+++ b/lib/libcxx/include/__algorithm/none_of.h
@@ -19,7 +19,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
for (; __first != __last; ++__first)
if (__pred(*__first))
diff --git a/lib/libcxx/include/__algorithm/nth_element.h b/lib/libcxx/include/__algorithm/nth_element.h
index dbacf58f9e..da748d7255 100644
--- a/lib/libcxx/include/__algorithm/nth_element.h
+++ b/lib/libcxx/include/__algorithm/nth_element.h
@@ -13,6 +13,7 @@
#include <__algorithm/comp_ref_type.h>
#include <__algorithm/iterator_operations.h>
#include <__algorithm/sort.h>
+#include <__assert>
#include <__config>
#include <__debug_utils/randomize_range.h>
#include <__iterator/iterator_traits.h>
@@ -22,209 +23,212 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _Compare, class _RandomAccessIterator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
-__nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j,
- _RandomAccessIterator __m, _Compare __comp)
-{
- // manually guard downward moving __j against __i
- while (true) {
- if (__i == --__j) {
- return false;
- }
- if (__comp(*__j, *__m)) {
- return true; // found guard for downward moving __j, now use unguarded partition
- }
+template <class _Compare, class _RandomAccessIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __nth_element_find_guard(
+ _RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) {
+ // manually guard downward moving __j against __i
+ while (true) {
+ if (__i == --__j) {
+ return false;
+ }
+ if (__comp(*__j, *__m)) {
+ return true; // found guard for downward moving __j, now use unguarded partition
}
+ }
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
-__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+// NOLINTNEXTLINE(readability-function-cognitive-complexity)
+__nth_element(
+ _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) {
+ using _Ops = _IterOps<_AlgPolicy>;
- // _Compare is known to be a reference type
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- const difference_type __limit = 7;
- while (true)
+ // _Compare is known to be a reference type
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ const difference_type __limit = 7;
+ while (true) {
+ if (__nth == __last)
+ return;
+ difference_type __len = __last - __first;
+ switch (__len) {
+ case 0:
+ case 1:
+ return;
+ case 2:
+ if (__comp(*--__last, *__first))
+ _Ops::iter_swap(__first, __last);
+ return;
+ case 3: {
+ _RandomAccessIterator __m = __first;
+ std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
+ return;
+ }
+ }
+ if (__len <= __limit) {
+ std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
+ return;
+ }
+ // __len > __limit >= 3
+ _RandomAccessIterator __m = __first + __len / 2;
+ _RandomAccessIterator __lm1 = __last;
+ unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
+ // *__m is median
+ // partition [__first, __m) < *__m and *__m <= [__m, __last)
+ // (this inhibits tossing elements equivalent to __m around unnecessarily)
+ _RandomAccessIterator __i = __first;
+ _RandomAccessIterator __j = __lm1;
+ // j points beyond range to be tested, *__lm1 is known to be <= *__m
+ // The search going up is known to be guarded but the search coming down isn't.
+ // Prime the downward search with a guard.
+ if (!__comp(*__i, *__m)) // if *__first == *__m
{
- if (__nth == __last)
- return;
- difference_type __len = __last - __first;
- switch (__len)
- {
- case 0:
- case 1:
- return;
- case 2:
- if (__comp(*--__last, *__first))
- _Ops::iter_swap(__first, __last);
- return;
- case 3:
- {
- _RandomAccessIterator __m = __first;
- std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
- return;
+ // *__first == *__m, *__first doesn't go in first part
+ if (std::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
+ _Ops::iter_swap(__i, __j);
+ ++__n_swaps;
+ } else {
+ // *__first == *__m, *__m <= all other elements
+ // Partition instead into [__first, __i) == *__first and *__first < [__i, __last)
+ ++__i; // __first + 1
+ __j = __last;
+ if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1)
+ while (true) {
+ if (__i == __j) {
+ return; // [__first, __last) all equivalent elements
+ } else if (__comp(*__first, *__i)) {
+ _Ops::iter_swap(__i, __j);
+ ++__n_swaps;
+ ++__i;
+ break;
}
+ ++__i;
+ }
}
- if (__len <= __limit)
- {
- std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
- return;
+ // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
+ if (__i == __j) {
+ return;
}
- // __len > __limit >= 3
- _RandomAccessIterator __m = __first + __len/2;
- _RandomAccessIterator __lm1 = __last;
- unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
- // *__m is median
- // partition [__first, __m) < *__m and *__m <= [__m, __last)
- // (this inhibits tossing elements equivalent to __m around unnecessarily)
- _RandomAccessIterator __i = __first;
- _RandomAccessIterator __j = __lm1;
- // j points beyond range to be tested, *__lm1 is known to be <= *__m
- // The search going up is known to be guarded but the search coming down isn't.
- // Prime the downward search with a guard.
- if (!__comp(*__i, *__m)) // if *__first == *__m
- {
- // *__first == *__m, *__first doesn't go in first part
- if (_VSTD::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
- _Ops::iter_swap(__i, __j);
- ++__n_swaps;
- } else {
- // *__first == *__m, *__m <= all other elements
- // Partition instead into [__first, __i) == *__first and *__first < [__i, __last)
- ++__i; // __first + 1
- __j = __last;
- if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1)
- while (true) {
- if (__i == __j) {
- return; // [__first, __last) all equivalent elements
- } else if (__comp(*__first, *__i)) {
- _Ops::iter_swap(__i, __j);
- ++__n_swaps;
- ++__i;
- break;
- }
- ++__i;
- }
- }
- // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
- if (__i == __j) {
- return;
- }
- while (true) {
- while (!__comp(*__first, *__i))
- ++__i;
- while (__comp(*__first, *--__j))
- ;
- if (__i >= __j)
- break;
- _Ops::iter_swap(__i, __j);
- ++__n_swaps;
- ++__i;
- }
- // [__first, __i) == *__first and *__first < [__i, __last)
- // The first part is sorted,
- if (__nth < __i) {
- return;
- }
- // __nth_element the second part
- // _VSTD::__nth_element<_Compare>(__i, __nth, __last, __comp);
- __first = __i;
- continue;
- }
+ while (true) {
+ while (!__comp(*__first, *__i)) {
+ ++__i;
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __i != __last,
+ "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
+ }
+ do {
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __j != __first,
+ "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
+ --__j;
+ } while (__comp(*__first, *__j));
+ if (__i >= __j)
+ break;
+ _Ops::iter_swap(__i, __j);
+ ++__n_swaps;
+ ++__i;
}
- ++__i;
- // j points beyond range to be tested, *__lm1 is known to be <= *__m
- // if not yet partitioned...
- if (__i < __j)
- {
- // known that *(__i - 1) < *__m
- while (true)
- {
- // __m still guards upward moving __i
- while (__comp(*__i, *__m))
- ++__i;
- // It is now known that a guard exists for downward moving __j
- while (!__comp(*--__j, *__m))
- ;
- if (__i >= __j)
- break;
- _Ops::iter_swap(__i, __j);
- ++__n_swaps;
- // It is known that __m != __j
- // If __m just moved, follow it
- if (__m == __i)
- __m = __j;
- ++__i;
- }
+ // [__first, __i) == *__first and *__first < [__i, __last)
+ // The first part is sorted,
+ if (__nth < __i) {
+ return;
}
- // [__first, __i) < *__m and *__m <= [__i, __last)
- if (__i != __m && __comp(*__m, *__i))
- {
- _Ops::iter_swap(__i, __m);
- ++__n_swaps;
+ // __nth_element the second part
+ // std::__nth_element<_Compare>(__i, __nth, __last, __comp);
+ __first = __i;
+ continue;
+ }
+ }
+ ++__i;
+ // j points beyond range to be tested, *__lm1 is known to be <= *__m
+ // if not yet partitioned...
+ if (__i < __j) {
+ // known that *(__i - 1) < *__m
+ while (true) {
+ // __m still guards upward moving __i
+ while (__comp(*__i, *__m)) {
+ ++__i;
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __i != __last,
+ "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
}
- // [__first, __i) < *__i and *__i <= [__i+1, __last)
- if (__nth == __i)
+ // It is now known that a guard exists for downward moving __j
+ do {
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __j != __first,
+ "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
+ --__j;
+ } while (!__comp(*__j, *__m));
+ if (__i >= __j)
+ break;
+ _Ops::iter_swap(__i, __j);
+ ++__n_swaps;
+ // It is known that __m != __j
+ // If __m just moved, follow it
+ if (__m == __i)
+ __m = __j;
+ ++__i;
+ }
+ }
+ // [__first, __i) < *__m and *__m <= [__i, __last)
+ if (__i != __m && __comp(*__m, *__i)) {
+ _Ops::iter_swap(__i, __m);
+ ++__n_swaps;
+ }
+ // [__first, __i) < *__i and *__i <= [__i+1, __last)
+ if (__nth == __i)
+ return;
+ if (__n_swaps == 0) {
+ // We were given a perfectly partitioned sequence. Coincidence?
+ if (__nth < __i) {
+ // Check for [__first, __i) already sorted
+ __j = __m = __first;
+ while (true) {
+ if (++__j == __i) {
+ // [__first, __i) sorted
return;
- if (__n_swaps == 0)
- {
- // We were given a perfectly partitioned sequence. Coincidence?
- if (__nth < __i)
- {
- // Check for [__first, __i) already sorted
- __j = __m = __first;
- while (true) {
- if (++__j == __i) {
- // [__first, __i) sorted
- return;
- }
- if (__comp(*__j, *__m)) {
- // not yet sorted, so sort
- break;
- }
- __m = __j;
- }
- }
- else
- {
- // Check for [__i, __last) already sorted
- __j = __m = __i;
- while (true) {
- if (++__j == __last) {
- // [__i, __last) sorted
- return;
- }
- if (__comp(*__j, *__m)) {
- // not yet sorted, so sort
- break;
- }
- __m = __j;
- }
- }
- }
- // __nth_element on range containing __nth
- if (__nth < __i)
- {
- // _VSTD::__nth_element<_Compare>(__first, __nth, __i, __comp);
- __last = __i;
+ }
+ if (__comp(*__j, *__m)) {
+ // not yet sorted, so sort
+ break;
+ }
+ __m = __j;
}
- else
- {
- // _VSTD::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
- __first = ++__i;
+ } else {
+ // Check for [__i, __last) already sorted
+ __j = __m = __i;
+ while (true) {
+ if (++__j == __last) {
+ // [__i, __last) sorted
+ return;
+ }
+ if (__comp(*__j, *__m)) {
+ // not yet sorted, so sort
+ break;
+ }
+ __m = __j;
}
+ }
}
+ // __nth_element on range containing __nth
+ if (__nth < __i) {
+ // std::__nth_element<_Compare>(__first, __nth, __i, __comp);
+ __last = __i;
+ } else {
+ // std::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
+ __first = ++__i;
+ }
+ }
}
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
- _Compare& __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __nth_element_impl(
+ _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) {
if (__nth == __last)
return;
@@ -239,18 +243,19 @@ void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __n
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
- _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) {
std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp);
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H
diff --git a/lib/libcxx/include/__algorithm/partial_sort.h b/lib/libcxx/include/__algorithm/partial_sort.h
index 56bc9052c7..85a8fdc77a 100644
--- a/lib/libcxx/include/__algorithm/partial_sort.h
+++ b/lib/libcxx/include/__algorithm/partial_sort.h
@@ -26,11 +26,13 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator __partial_sort_impl(
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort_impl(
_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) {
if (__first == __middle) {
return _IterOps<_AlgPolicy>::next(__middle, __last);
@@ -39,14 +41,12 @@ _RandomAccessIterator __partial_sort_impl(
std::__make_heap<_AlgPolicy>(__first, __middle, __comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
- _RandomAccessIterator __i = __middle;
- for (; __i != __last; ++__i)
- {
- if (__comp(*__i, *__first))
- {
- _IterOps<_AlgPolicy>::iter_swap(__i, __first);
- std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
- }
+ _RandomAccessIterator __i = __middle;
+ for (; __i != __last; ++__i) {
+ if (__comp(*__i, *__first)) {
+ _IterOps<_AlgPolicy>::iter_swap(__i, __first);
+ std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
+ }
}
std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp);
@@ -54,11 +54,10 @@ _RandomAccessIterator __partial_sort_impl(
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last,
- _Compare& __comp) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
+__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) {
if (__first == __middle)
- return _IterOps<_AlgPolicy>::next(__middle, __last);
+ return _IterOps<_AlgPolicy>::next(__middle, __last);
std::__debug_randomize_range<_AlgPolicy>(__first, __last);
@@ -71,11 +70,8 @@ _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAcces
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
- _Compare __comp)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort(
+ _RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) {
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@@ -83,13 +79,13 @@ partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
}
template <class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
-{
- _VSTD::partial_sort(__first, __middle, __last, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) {
+ std::partial_sort(__first, __middle, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H
diff --git a/lib/libcxx/include/__algorithm/partial_sort_copy.h b/lib/libcxx/include/__algorithm/partial_sort_copy.h
index b9635c51d5..ef7c9d34d9 100644
--- a/lib/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/lib/libcxx/include/__algorithm/partial_sort_copy.h
@@ -28,60 +28,79 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _AlgPolicy, class _Compare,
- class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
- class _Proj1, class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator>
-__partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
- _RandomAccessIterator __result_first, _Sentinel2 __result_last,
- _Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
-{
- _RandomAccessIterator __r = __result_first;
- auto&& __projected_comp = std::__make_projected(__comp, __proj2);
+template <class _AlgPolicy,
+ class _Compare,
+ class _InputIterator,
+ class _Sentinel1,
+ class _RandomAccessIterator,
+ class _Sentinel2,
+ class _Proj1,
+ class _Proj2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy(
+ _InputIterator __first,
+ _Sentinel1 __last,
+ _RandomAccessIterator __result_first,
+ _Sentinel2 __result_last,
+ _Compare&& __comp,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
+ _RandomAccessIterator __r = __result_first;
+ auto&& __projected_comp = std::__make_projected(__comp, __proj2);
- if (__r != __result_last)
- {
- for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
- *__r = *__first;
- std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
- for (; __first != __last; ++__first)
- if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
- *__result_first = *__first;
- std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
- }
- std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- }
+ if (__r != __result_last) {
+ for (; __first != __last && __r != __result_last; ++__first, (void)++__r)
+ *__r = *__first;
+ std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
+ for (; __first != __last; ++__first)
+ if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
+ *__result_first = *__first;
+ std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
+ }
+ std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ }
- return pair<_InputIterator, _RandomAccessIterator>(
- _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
+ return pair<_InputIterator, _RandomAccessIterator>(
+ _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator
-partial_sort_copy(_InputIterator __first, _InputIterator __last,
- _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
-{
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _RandomAccessIterator __result_first,
+ _RandomAccessIterator __result_last,
+ _Compare __comp) {
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
- auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
- static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
+ auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
+ __first,
+ __last,
+ __result_first,
+ __result_last,
+ static_cast<__comp_ref_type<_Compare> >(__comp),
+ __identity(),
+ __identity());
return __result.second;
}
template <class _InputIterator, class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator
-partial_sort_copy(_InputIterator __first, _InputIterator __last,
- _RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
-{
- return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _RandomAccessIterator __result_first,
+ _RandomAccessIterator __result_last) {
+ return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
diff --git a/lib/libcxx/include/__algorithm/partition.h b/lib/libcxx/include/__algorithm/partition.h
index a58dd6464a..824e49b9ec 100644
--- a/lib/libcxx/include/__algorithm/partition.h
+++ b/lib/libcxx/include/__algorithm/partition.h
@@ -19,74 +19,65 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
-__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag)
-{
- while (true)
- {
- if (__first == __last)
- return std::make_pair(std::move(__first), std::move(__first));
- if (!__pred(*__first))
- break;
- ++__first;
- }
+__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) {
+ while (true) {
+ if (__first == __last)
+ return std::make_pair(std::move(__first), std::move(__first));
+ if (!__pred(*__first))
+ break;
+ ++__first;
+ }
- _ForwardIterator __p = __first;
- while (++__p != __last)
- {
- if (__pred(*__p))
- {
- _IterOps<_AlgPolicy>::iter_swap(__first, __p);
- ++__first;
- }
+ _ForwardIterator __p = __first;
+ while (++__p != __last) {
+ if (__pred(*__p)) {
+ _IterOps<_AlgPolicy>::iter_swap(__first, __p);
+ ++__first;
}
- return std::make_pair(std::move(__first), std::move(__p));
+ }
+ return std::make_pair(std::move(__first), std::move(__p));
}
template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator>
-__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred,
- bidirectional_iterator_tag)
-{
- _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
- _BidirectionalIterator __last = __original_last;
+__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) {
+ _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
+ _BidirectionalIterator __last = __original_last;
- while (true)
- {
- while (true)
- {
- if (__first == __last)
- return std::make_pair(std::move(__first), std::move(__original_last));
- if (!__pred(*__first))
- break;
- ++__first;
- }
- do
- {
- if (__first == --__last)
- return std::make_pair(std::move(__first), std::move(__original_last));
- } while (!__pred(*__last));
- _IterOps<_AlgPolicy>::iter_swap(__first, __last);
- ++__first;
+ while (true) {
+ while (true) {
+ if (__first == __last)
+ return std::make_pair(std::move(__first), std::move(__original_last));
+ if (!__pred(*__first))
+ break;
+ ++__first;
}
+ do {
+ if (__first == --__last)
+ return std::make_pair(std::move(__first), std::move(__original_last));
+ } while (!__pred(*__last));
+ _IterOps<_AlgPolicy>::iter_swap(__first, __last);
+ ++__first;
+ }
}
template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-pair<_ForwardIterator, _ForwardIterator> __partition(
- _ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
+__partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>(
std::move(__first), std::move(__last), __pred, __iter_category);
}
template <class _ForwardIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator
-partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
return __result.first;
@@ -94,4 +85,6 @@ partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PARTITION_H
diff --git a/lib/libcxx/include/__algorithm/partition_copy.h b/lib/libcxx/include/__algorithm/partition_copy.h
index ff8826a937..147b45c788 100644
--- a/lib/libcxx/include/__algorithm/partition_copy.h
+++ b/lib/libcxx/include/__algorithm/partition_copy.h
@@ -19,27 +19,23 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _InputIterator, class _OutputIterator1,
- class _OutputIterator2, class _Predicate>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2>
-partition_copy(_InputIterator __first, _InputIterator __last,
- _OutputIterator1 __out_true, _OutputIterator2 __out_false,
- _Predicate __pred)
-{
- for (; __first != __last; ++__first)
- {
- if (__pred(*__first))
- {
- *__out_true = *__first;
- ++__out_true;
- }
- else
- {
- *__out_false = *__first;
- ++__out_false;
- }
+template <class _InputIterator, class _OutputIterator1, class _OutputIterator2, class _Predicate>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _OutputIterator1 __out_true,
+ _OutputIterator2 __out_false,
+ _Predicate __pred) {
+ for (; __first != __last; ++__first) {
+ if (__pred(*__first)) {
+ *__out_true = *__first;
+ ++__out_true;
+ } else {
+ *__out_false = *__first;
+ ++__out_false;
}
- return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
+ }
+ return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/partition_point.h b/lib/libcxx/include/__algorithm/partition_point.h
index 6ede71a264..504dbf1d1a 100644
--- a/lib/libcxx/include/__algorithm/partition_point.h
+++ b/lib/libcxx/include/__algorithm/partition_point.h
@@ -21,26 +21,22 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _ForwardIterator, class _Predicate>
+template <class _ForwardIterator, class _Predicate>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
-{
- typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
- difference_type __len = _VSTD::distance(__first, __last);
- while (__len != 0)
- {
- difference_type __l2 = _VSTD::__half_positive(__len);
- _ForwardIterator __m = __first;
- _VSTD::advance(__m, __l2);
- if (__pred(*__m))
- {
- __first = ++__m;
- __len -= __l2 + 1;
- }
- else
- __len = __l2;
- }
- return __first;
+partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+ difference_type __len = std::distance(__first, __last);
+ while (__len != 0) {
+ difference_type __l2 = std::__half_positive(__len);
+ _ForwardIterator __m = __first;
+ std::advance(__m, __l2);
+ if (__pred(*__m)) {
+ __first = ++__m;
+ __len -= __l2 + 1;
+ } else
+ __len = __l2;
+ }
+ return __first;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/pop_heap.h b/lib/libcxx/include/__algorithm/pop_heap.h
index 033af6f2f8..798a1d0993 100644
--- a/lib/libcxx/include/__algorithm/pop_heap.h
+++ b/lib/libcxx/include/__algorithm/pop_heap.h
@@ -31,16 +31,19 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
- _LIBCPP_ASSERT_UNCATEGORIZED(__len > 0, "The heap given to pop_heap must be non-empty");
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__pop_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+ _Compare& __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
+ // Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op.
+ _LIBCPP_ASSERT_PEDANTIC(__len > 0, "The heap given to pop_heap must be non-empty");
__comp_ref_type<_Compare> __comp_ref = __comp;
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
if (__len > 1) {
- value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first
+ value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first
_RandomAccessIterator __hole = std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len);
--__last;
@@ -56,8 +59,8 @@ void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@@ -66,8 +69,8 @@ void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::pop_heap(std::move(__first), std::move(__last), __less<>());
}
diff --git a/lib/libcxx/include/__algorithm/prev_permutation.h b/lib/libcxx/include/__algorithm/prev_permutation.h
index 187f1e3e5b..8d15b68064 100644
--- a/lib/libcxx/include/__algorithm/prev_permutation.h
+++ b/lib/libcxx/include/__algorithm/prev_permutation.h
@@ -22,57 +22,54 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-pair<_BidirectionalIterator, bool>
-__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
-{
- using _Result = pair<_BidirectionalIterator, bool>;
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
+__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
+ using _Result = pair<_BidirectionalIterator, bool>;
- _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
- _BidirectionalIterator __i = __last_iter;
- if (__first == __last || __first == --__i)
- return _Result(std::move(__last_iter), false);
+ _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
+ _BidirectionalIterator __i = __last_iter;
+ if (__first == __last || __first == --__i)
+ return _Result(std::move(__last_iter), false);
- while (true)
- {
- _BidirectionalIterator __ip1 = __i;
- if (__comp(*__ip1, *--__i))
- {
- _BidirectionalIterator __j = __last_iter;
- while (!__comp(*--__j, *__i))
- ;
- _IterOps<_AlgPolicy>::iter_swap(__i, __j);
- std::__reverse<_AlgPolicy>(__ip1, __last_iter);
- return _Result(std::move(__last_iter), true);
- }
- if (__i == __first)
- {
- std::__reverse<_AlgPolicy>(__first, __last_iter);
- return _Result(std::move(__last_iter), false);
- }
+ while (true) {
+ _BidirectionalIterator __ip1 = __i;
+ if (__comp(*__ip1, *--__i)) {
+ _BidirectionalIterator __j = __last_iter;
+ while (!__comp(*--__j, *__i))
+ ;
+ _IterOps<_AlgPolicy>::iter_swap(__i, __j);
+ std::__reverse<_AlgPolicy>(__ip1, __last_iter);
+ return _Result(std::move(__last_iter), true);
+ }
+ if (__i == __first) {
+ std::__reverse<_AlgPolicy>(__first, __last_iter);
+ return _Result(std::move(__last_iter), false);
}
+ }
}
template <class _BidirectionalIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
return std::__prev_permutation<_ClassicAlgPolicy>(
- std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second;
+ std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp))
+ .second;
}
template <class _BidirectionalIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-bool
-prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
-{
- return _VSTD::prev_permutation(__first, __last, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
+ return std::prev_permutation(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
diff --git a/lib/libcxx/include/__algorithm/pstl_any_all_none_of.h b/lib/libcxx/include/__algorithm/pstl_any_all_none_of.h
index 0e50e0ed36..4b1e0e61b5 100644
--- a/lib/libcxx/include/__algorithm/pstl_any_all_none_of.h
+++ b/lib/libcxx/include/__algorithm/pstl_any_all_none_of.h
@@ -13,17 +13,19 @@
#include <__algorithm/pstl_frontend_dispatch.h>
#include <__config>
#include <__iterator/cpp17_iterator_concepts.h>
-#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,19 +38,35 @@ template <class _ExecutionPolicy,
class _Predicate,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
-any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool> __any_of(
+ _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) noexcept {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
- return std::find_if(__policy, __g_first, __g_last, __g_pred) != __g_last;
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) -> optional<bool> {
+ auto __res = std::__find_if(__policy, __g_first, __g_last, __g_pred);
+ if (!__res)
+ return nullopt;
+ return *__res != __g_last;
},
std::move(__first),
std::move(__last),
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Predicate,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
+any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__any_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
template <class>
void __pstl_all_of(); // declaration needed for the frontend dispatch below
@@ -57,21 +75,37 @@ template <class _ExecutionPolicy,
class _Pred,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
-all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
+__all_of(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Pred&& __pred) noexcept {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
- return !std::any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) -> optional<bool> {
+ auto __res = std::__any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
return !__g_pred(__value);
});
+ if (!__res)
+ return nullopt;
+ return !*__res;
},
std::move(__first),
std::move(__last),
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
+all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__all_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
template <class>
void __pstl_none_of(); // declaration needed for the frontend dispatch below
@@ -80,21 +114,39 @@ template <class _ExecutionPolicy,
class _Pred,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
-none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
+__none_of(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Pred&& __pred) noexcept {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
- return !std::any_of(__policy, __g_first, __g_last, __g_pred);
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) -> optional<bool> {
+ auto __res = std::__any_of(__policy, __g_first, __g_last, __g_pred);
+ if (!__res)
+ return nullopt;
+ return !*__res;
},
std::move(__first),
std::move(__last),
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
+none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__none_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backend.h b/lib/libcxx/include/__algorithm/pstl_backend.h
index 93372f0190..3af03ce2fb 100644
--- a/lib/libcxx/include/__algorithm/pstl_backend.h
+++ b/lib/libcxx/include/__algorithm/pstl_backend.h
@@ -27,23 +27,38 @@ TODO: Documentation of how backends work
A PSTL parallel backend is a tag type to which the following functions are associated, at minimum:
template <class _ExecutionPolicy, class _Iterator, class _Func>
- void __pstl_for_each(_Backend, _ExecutionPolicy&&, _Iterator __first, _Iterator __last, _Func __f);
+ optional<__empty> __pstl_for_each(_Backend, _ExecutionPolicy&&, _Iterator __first, _Iterator __last, _Func __f);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- _Iterator __pstl_find_if(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
+ optional<_Iterator> __pstl_find_if(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Comp>
- void __pstl_stable_sort(_Backend, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp);
+ optional<__empty>
+ __pstl_stable_sort(_Backend, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp);
+
+ template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _ForwardOutIterator,
+ class _Comp>
+ optional<_ForwardOutIterator> __pstl_merge(_Backend,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _ForwardOutIterator __result,
+ _Comp __comp);
template <class _ExecutionPolicy, class _InIterator, class _OutIterator, class _UnaryOperation>
- _OutIterator __pstl_transform(_InIterator __first, _InIterator __last, _OutIterator __result, _UnaryOperation __op);
+ optional<_OutIterator>
+ __pstl_transform(_Backend, _InIterator __first, _InIterator __last, _OutIterator __result, _UnaryOperation __op);
template <class _ExecutionPolicy, class _InIterator1, class _InIterator2, class _OutIterator, class _BinaryOperation>
- _OutIterator __pstl_transform(_InIterator1 __first1,
- _InIterator1 __last1,
- _InIterator2 __first2,
- _OutIterator __result,
- _BinaryOperation __op);
+ optional<_OutIterator> __pstl_transform(_InIterator1 __first1,
+ _InIterator2 __first2,
+ _InIterator1 __last1,
+ _OutIterator __result,
+ _BinaryOperation __op);
template <class _ExecutionPolicy,
class _Iterator1,
@@ -51,22 +66,22 @@ A PSTL parallel backend is a tag type to which the following functions are assoc
class _Tp,
class _BinaryOperation1,
class _BinaryOperation2>
- _Tp __pstl_transform_reduce(_Backend,
- _Iterator1 __first1,
- _Iterator1 __last1,
- _Iterator2 __first2,
- _Iterator2 __last2,
- _Tp __init,
- _BinaryOperation1 __reduce,
- _BinaryOperation2 __transform);
+ optional<_Tp> __pstl_transform_reduce(_Backend,
+ _Iterator1 __first1,
+ _Iterator1 __last1,
+ _Iterator2 __first2,
+ _Iterator2 __last2,
+ _Tp __init,
+ _BinaryOperation1 __reduce,
+ _BinaryOperation2 __transform);
template <class _ExecutionPolicy, class _Iterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
- _Tp __pstl_transform_reduce(_Backend,
- _Iterator __first,
- _Iterator __last,
- _Tp __init,
- _BinaryOperation __reduce,
- _UnaryOperation __transform);
+ optional<_Tp> __pstl_transform_reduce(_Backend,
+ _Iterator __first,
+ _Iterator __last,
+ _Tp __init,
+ _BinaryOperation __reduce,
+ _UnaryOperation __transform);
// TODO: Complete this list
@@ -75,86 +90,105 @@ algorithms, otherwise they are implemented in terms of other algorithms. If none
implemented, all the algorithms will eventually forward to the basis algorithms listed above:
template <class _ExecutionPolicy, class _Iterator, class _Size, class _Func>
- void __pstl_for_each_n(_Backend, _Iterator __first, _Size __n, _Func __f);
+ optional<__empty> __pstl_for_each_n(_Backend, _Iterator __first, _Size __n, _Func __f);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- bool __pstl_any_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
+ optional<bool> __pstl_any_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- bool __pstl_all_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
+ optional<bool> __pstl_all_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- bool __pstl_none_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
+ optional<bool> __pstl_none_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Tp>
- _Iterator __pstl_find(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
+ optional<_Iterator> __pstl_find(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- _Iterator __pstl_find_if_not(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
+ optional<_Iterator> __pstl_find_if_not(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Tp>
- void __pstl_fill(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
+ optional<__empty> __pstl_fill(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
template <class _ExecutionPolicy, class _Iterator, class _SizeT, class _Tp>
- void __pstl_fill_n(_Backend, _Iterator __first, _SizeT __n, const _Tp& __value);
+ optional<__empty> __pstl_fill_n(_Backend, _Iterator __first, _SizeT __n, const _Tp& __value);
template <class _ExecutionPolicy, class _Iterator, class _Generator>
- void __pstl_generate(_Backend, _Iterator __first, _Iterator __last, _Generator __gen);
+ optional<__empty> __pstl_generate(_Backend, _Iterator __first, _Iterator __last, _Generator __gen);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- void __pstl_is_partitioned(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
+ optional<__empty> __pstl_is_partitioned(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Size, class _Generator>
- void __pstl_generator_n(_Backend, _Iterator __first, _Size __n, _Generator __gen);
+ optional<__empty> __pstl_generator_n(_Backend, _Iterator __first, _Size __n, _Generator __gen);
template <class _ExecutionPolicy, class _terator1, class _Iterator2, class _OutIterator, class _Comp>
- _OutIterator __pstl_merge(_Backend,
- _Iterator1 __first1,
- _Iterator1 __last1,
- _Iterator2 __first2,
- _Iterator2 __last2,
- _OutIterator __result,
- _Comp __comp);
+ optional<_OutIterator> __pstl_merge(_Backend,
+ _Iterator1 __first1,
+ _Iterator1 __last1,
+ _Iterator2 __first2,
+ _Iterator2 __last2,
+ _OutIterator __result,
+ _Comp __comp);
+
+ template <class _ExecutionPolicy, class _Iterator, class _OutIterator>
+ optional<_OutIterator> __pstl_move(_Backend, _Iterator __first, _Iterator __last, _OutIterator __result);
template <class _ExecutionPolicy, class _Iterator, class _Tp, class _BinaryOperation>
- _Tp __pstl_reduce(_Backend, _Iterator __first, _Iterator __last, _Tp __init, _BinaryOperation __op);
+ optional<_Tp> __pstl_reduce(_Backend, _Iterator __first, _Iterator __last, _Tp __init, _BinaryOperation __op);
temlate <class _ExecutionPolicy, class _Iterator>
- __iter_value_type<_Iterator> __pstl_reduce(_Backend, _Iterator __first, _Iterator __last);
+ optional<__iter_value_type<_Iterator>> __pstl_reduce(_Backend, _Iterator __first, _Iterator __last);
- template <class _ExecuitonPolicy, class _Iterator, class _Tp>
- __iter_diff_t<_Iterator> __pstl_count(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
+ template <class _ExecutionPolicy, class _Iterator, class _Tp>
+ optional<__iter_diff_t<_Iterator>> __pstl_count(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
- __iter_diff_t<_Iterator> __pstl_count_if(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
+ optional<__iter_diff_t<_Iterator>> __pstl_count_if(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
template <class _ExecutionPolicy, class _Iterator, class _Tp>
- void __pstl_replace(_Backend, _Iterator __first, _Iterator __last, const _Tp& __old_value, const _Tp& __new_value);
+ optional<__empty>
+ __pstl_replace(_Backend, _Iterator __first, _Iterator __last, const _Tp& __old_value, const _Tp& __new_value);
template <class _ExecutionPolicy, class _Iterator, class _Pred, class _Tp>
- void __pstl_replace_if(_Backend, _Iterator __first, _Iterator __last, _Pred __pred, const _Tp& __new_value);
+ optional<__empty>
+ __pstl_replace_if(_Backend, _Iterator __first, _Iterator __last, _Pred __pred, const _Tp& __new_value);
template <class _ExecutionPolicy, class _Iterator, class _OutIterator, class _Tp>
- void __pstl_replace_copy(_Backend,
- _Iterator __first,
- _Iterator __last,
- _OutIterator __result,
- const _Tp& __old_value,
- const _Tp& __new_value);
+ optional<__empty> __pstl_replace_copy(_Backend,
+ _Iterator __first,
+ _Iterator __last,
+ _OutIterator __result,
+ const _Tp& __old_value,
+ const _Tp& __new_value);
template <class _ExecutionPolicy, class _Iterator, class _OutIterator, class _Pred, class _Tp>
- void __pstl_replace_copy_if(_Backend,
- _Iterator __first,
- _Iterator __last,
- _OutIterator __result,
- _Pred __pred,
- const _Tp& __new_value);
+ optional<__empty> __pstl_replace_copy_if(_Backend,
+ _Iterator __first,
+ _Iterator __last,
+ _OutIterator __result,
+ _Pred __pred,
+ const _Tp& __new_value);
+
+ template <class _ExecutionPolicy, class _Iterator, class _OutIterator>
+ optional<_Iterator> __pstl_rotate_copy(
+ _Backend, _Iterator __first, _Iterator __middle, _Iterator __last, _OutIterator __result);
template <class _ExecutionPolicy, class _Iterator, class _Comp>
- void __pstl_sort(_Backend, _Iterator __first, _Iterator __last, _Comp __comp);
+ optional<__empty> __pstl_sort(_Backend, _Iterator __first, _Iterator __last, _Comp __comp);
+
+ template <class _ExecutionPolicy, class _Iterator1, class _Iterator2, class _Comp>
+ optional<bool> __pstl_equal(_Backend, _Iterator1 first1, _Iterator1 last1, _Iterator2 first2, _Comp __comp);
// TODO: Complete this list
+Exception handling
+==================
+
+PSTL backends are expected to report errors (i.e. failure to allocate) by returning a disengaged `optional` from their
+implementation. Exceptions shouldn't be used to report an internal failure-to-allocate, since all exceptions are turned
+into a program termination at the front-end level. When a backend returns a disengaged `optional` to the frontend, the
+frontend will turn that into a call to `std::__throw_bad_alloc();` to report the internal failure to the user.
*/
template <class _ExecutionPolicy>
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backend.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backend.h
index e54f331b94..6980ded189 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backend.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backend.h
@@ -15,10 +15,11 @@
// _Functor takes a subrange for [__first, __last) that should be executed in serial
template <class _RandomAccessIterator, class _Functor>
- void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
+ optional<__empty> __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
template <class _Iterator, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduction>
- _Tp __parallel_transform_reduce(_Iterator __first, _Iterator __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduction);
+ optional<_Tp>
+ __parallel_transform_reduce(_Iterator __first, _Iterator __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduction);
// Cancel the execution of other jobs - they aren't needed anymore
void __cancel_execution();
@@ -28,7 +29,7 @@
class _RandomAccessIterator3,
class _Compare,
class _LeafMerge>
- void __parallel_merge(
+ optional<void> __parallel_merge(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
@@ -44,6 +45,14 @@
_LeafSort __leaf_sort);
TODO: Document the parallel backend
+
+Exception handling
+==================
+
+CPU backends are expected to report errors (i.e. failure to allocate) by returning a disengaged `optional` from their
+implementation. Exceptions shouldn't be used to report an internal failure-to-allocate, since all exceptions are turned
+into a program termination at the front-end level. When a backend returns a disengaged `optional` to the frontend, the
+frontend will turn that into a call to `std::__throw_bad_alloc();` to report the internal failure to the user.
*/
#include <__algorithm/pstl_backends/cpu_backends/any_of.h>
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/any_of.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/any_of.h
index 8fe26797bf..13dff80086 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/any_of.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/any_of.h
@@ -16,26 +16,32 @@
#include <__atomic/memory_order.h>
#include <__config>
#include <__functional/operations.h>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/concepts.h>
#include <__type_traits/is_execution_policy.h>
+#include <__utility/move.h>
#include <__utility/pair.h>
-#include <__utility/terminate_on_exception.h>
#include <cstdint>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_PUSH_MACROS
+# include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Index, class _Brick>
-_LIBCPP_HIDE_FROM_ABI bool __parallel_or(_Index __first, _Index __last, _Brick __f) {
+_LIBCPP_HIDE_FROM_ABI optional<bool> __parallel_or(_Index __first, _Index __last, _Brick __f) {
std::atomic<bool> __found(false);
- __par_backend::__parallel_for(__first, __last, [__f, &__found](_Index __i, _Index __j) {
+ auto __ret = __par_backend::__parallel_for(__first, __last, [__f, &__found](_Index __i, _Index __j) {
if (!__found.load(std::memory_order_relaxed) && __f(__i, __j)) {
__found.store(true, std::memory_order_relaxed);
__par_backend::__cancel_execution();
}
});
- return __found;
+ if (!__ret)
+ return nullopt;
+ return static_cast<bool>(__found);
}
// TODO: check whether __simd_first() can be used here
@@ -64,19 +70,19 @@ _LIBCPP_HIDE_FROM_ABI bool __simd_or(_Index __first, _DifferenceType __n, _Pred
}
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-_LIBCPP_HIDE_FROM_ABI bool
+_LIBCPP_HIDE_FROM_ABI optional<bool>
__pstl_any_of(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- return std::__terminate_on_exception([&] {
- return std::__parallel_or(
- __first, __last, [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
- return std::__pstl_any_of<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{}, __brick_first, __brick_last, __pred);
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ return std::__parallel_or(
+ __first, __last, [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
+ auto __res = std::__pstl_any_of<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{}, __brick_first, __brick_last, __pred);
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ return *std::move(__res);
+ });
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
return std::__simd_or(__first, __last - __first, __pred);
} else {
return std::any_of(__first, __last, __pred);
@@ -85,6 +91,8 @@ __pstl_any_of(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __la
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/fill.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/fill.h
index 5e5e0a23bf..64babe9fd2 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/fill.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/fill.h
@@ -12,9 +12,10 @@
#include <__algorithm/fill.h>
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__config>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/concepts.h>
#include <__type_traits/is_execution_policy.h>
-#include <__utility/terminate_on_exception.h>
+#include <__utility/empty.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -34,22 +35,23 @@ _LIBCPP_HIDE_FROM_ABI _Index __simd_fill_n(_Index __first, _DifferenceType __n,
}
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-_LIBCPP_HIDE_FROM_ABI void
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
__pstl_fill(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- std::__terminate_on_exception([&] {
- __par_backend::__parallel_for(
- __first, __last, [&__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
- std::__pstl_fill<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{}, __brick_first, __brick_last, __value);
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ return __par_backend::__parallel_for(
+ __first, __last, [&__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
+ [[maybe_unused]] auto __res = std::__pstl_fill<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{}, __brick_first, __brick_last, __value);
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ });
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
std::__simd_fill_n(__first, __last - __first, __value);
+ return __empty{};
} else {
std::fill(__first, __last, __value);
+ return __empty{};
}
}
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/find_if.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/find_if.h
index 3fa49549e6..170470e4fb 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/find_if.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/find_if.h
@@ -14,11 +14,13 @@
#include <__atomic/atomic.h>
#include <__config>
#include <__functional/operations.h>
+#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__type_traits/is_execution_policy.h>
+#include <__utility/move.h>
#include <__utility/pair.h>
-#include <__utility/terminate_on_exception.h>
#include <cstddef>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -26,31 +28,37 @@
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_PUSH_MACROS
+# include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Index, class _Brick, class _Compare>
-_LIBCPP_HIDE_FROM_ABI _Index
+_LIBCPP_HIDE_FROM_ABI optional<_Index>
__parallel_find(_Index __first, _Index __last, _Brick __f, _Compare __comp, bool __b_first) {
typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType;
const _DifferenceType __n = __last - __first;
_DifferenceType __initial_dist = __b_first ? __n : -1;
std::atomic<_DifferenceType> __extremum(__initial_dist);
// TODO: find out what is better here: parallel_for or parallel_reduce
- __par_backend::__parallel_for(__first, __last, [__comp, __f, __first, &__extremum](_Index __i, _Index __j) {
- // See "Reducing Contention Through Priority Updates", PPoPP '13, for discussion of
- // why using a shared variable scales fairly well in this situation.
- if (__comp(__i - __first, __extremum)) {
- _Index __res = __f(__i, __j);
- // If not '__last' returned then we found what we want so put this to extremum
- if (__res != __j) {
- const _DifferenceType __k = __res - __first;
- for (_DifferenceType __old = __extremum; __comp(__k, __old); __old = __extremum) {
- __extremum.compare_exchange_weak(__old, __k);
+ auto __res =
+ __par_backend::__parallel_for(__first, __last, [__comp, __f, __first, &__extremum](_Index __i, _Index __j) {
+ // See "Reducing Contention Through Priority Updates", PPoPP '13, for discussion of
+ // why using a shared variable scales fairly well in this situation.
+ if (__comp(__i - __first, __extremum)) {
+ _Index __result = __f(__i, __j);
+ // If not '__last' returned then we found what we want so put this to extremum
+ if (__result != __j) {
+ const _DifferenceType __k = __result - __first;
+ for (_DifferenceType __old = __extremum; __comp(__k, __old); __old = __extremum) {
+ __extremum.compare_exchange_weak(__old, __k);
+ }
+ }
}
- }
- }
- });
- return __extremum != __initial_dist ? __first + __extremum : __last;
+ });
+ if (!__res)
+ return nullopt;
+ return __extremum.load() != __initial_dist ? __first + __extremum.load() : __last;
}
template <class _Index, class _DifferenceType, class _Compare>
@@ -90,23 +98,23 @@ __simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Co
}
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-_LIBCPP_HIDE_FROM_ABI _ForwardIterator
+_LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator>
__pstl_find_if(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- return std::__terminate_on_exception([&] {
- return std::__parallel_find(
- __first,
- __last,
- [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
- return std::__pstl_find_if<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{}, __brick_first, __brick_last, __pred);
- },
- less<>{},
- true);
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ return std::__parallel_find(
+ __first,
+ __last,
+ [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
+ auto __res = std::__pstl_find_if<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{}, __brick_first, __brick_last, __pred);
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ return *std::move(__res);
+ },
+ less<>{},
+ true);
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
using __diff_t = __iter_diff_t<_ForwardIterator>;
return std::__simd_first(__first, __diff_t(0), __last - __first, [&__pred](_ForwardIterator __iter, __diff_t __i) {
return __pred(__iter[__i]);
@@ -118,6 +126,8 @@ __pstl_find_if(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __l
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/for_each.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/for_each.h
index 36d0ac238e..81fd4526b8 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/for_each.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/for_each.h
@@ -12,9 +12,10 @@
#include <__algorithm/for_each.h>
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__config>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/concepts.h>
#include <__type_traits/is_execution_policy.h>
-#include <__utility/terminate_on_exception.h>
+#include <__utility/empty.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -25,7 +26,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iterator, class _DifferenceType, class _Function>
-_LIBCPP_HIDE_FROM_ABI _Iterator __simd_walk_1(_Iterator __first, _DifferenceType __n, _Function __f) noexcept {
+_LIBCPP_HIDE_FROM_ABI _Iterator __simd_walk(_Iterator __first, _DifferenceType __n, _Function __f) noexcept {
_PSTL_PRAGMA_SIMD
for (_DifferenceType __i = 0; __i < __n; ++__i)
__f(__first[__i]);
@@ -34,22 +35,23 @@ _LIBCPP_HIDE_FROM_ABI _Iterator __simd_walk_1(_Iterator __first, _DifferenceType
}
template <class _ExecutionPolicy, class _ForwardIterator, class _Functor>
-_LIBCPP_HIDE_FROM_ABI void
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
__pstl_for_each(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Functor __func) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- std::__terminate_on_exception([&] {
- std::__par_backend::__parallel_for(
- __first, __last, [__func](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
- std::__pstl_for_each<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{}, __brick_first, __brick_last, __func);
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ return std::__par_backend::__parallel_for(
+ __first, __last, [__func](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
+ [[maybe_unused]] auto __res = std::__pstl_for_each<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{}, __brick_first, __brick_last, __func);
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ });
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- std::__simd_walk_1(__first, __last - __first, __func);
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ std::__simd_walk(__first, __last - __first, __func);
+ return __empty{};
} else {
std::for_each(__first, __last, __func);
+ return __empty{};
}
}
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h
index bab6a3639b..e885e7f225 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h
@@ -9,8 +9,10 @@
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_LIBDISPATCH_H
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_LIBDISPATCH_H
+#include <__algorithm/inplace_merge.h>
#include <__algorithm/lower_bound.h>
#include <__algorithm/max.h>
+#include <__algorithm/merge.h>
#include <__algorithm/upper_bound.h>
#include <__atomic/atomic.h>
#include <__config>
@@ -21,12 +23,13 @@
#include <__memory/construct_at.h>
#include <__memory/unique_ptr.h>
#include <__numeric/reduce.h>
+#include <__utility/empty.h>
#include <__utility/exception_guard.h>
#include <__utility/move.h>
#include <__utility/pair.h>
-#include <__utility/terminate_on_exception.h>
#include <cstddef>
#include <new>
+#include <optional>
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
@@ -57,13 +60,11 @@ struct __chunk_partitions {
ptrdiff_t __first_chunk_size_;
};
-[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI __chunk_partitions __partition_chunks(ptrdiff_t __size);
+[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI __chunk_partitions __partition_chunks(ptrdiff_t __size) noexcept;
template <class _RandomAccessIterator, class _Functor>
-_LIBCPP_HIDE_FROM_ABI void
-__parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func) {
- auto __partitions = __libdispatch::__partition_chunks(__last - __first);
-
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
+__dispatch_parallel_for(__chunk_partitions __partitions, _RandomAccessIterator __first, _Functor __func) {
// Perform the chunked execution.
__libdispatch::__dispatch_apply(__partitions.__chunk_count_, [&](size_t __chunk) {
auto __this_chunk_size = __chunk == 0 ? __partitions.__first_chunk_size_ : __partitions.__chunk_size_;
@@ -73,6 +74,15 @@ __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fun
: (__chunk * __partitions.__chunk_size_) + (__partitions.__first_chunk_size_ - __partitions.__chunk_size_);
__func(__first + __index, __first + __index + __this_chunk_size);
});
+
+ return __empty{};
+}
+
+template <class _RandomAccessIterator, class _Functor>
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
+__parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func) {
+ return __libdispatch::__dispatch_parallel_for(
+ __libdispatch::__partition_chunks(__last - __first), std::move(__first), std::move(__func));
}
template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIteratorOut>
@@ -90,23 +100,23 @@ template <typename _RandomAccessIterator1,
typename _RandomAccessIterator3,
typename _Compare,
typename _LeafMerge>
-_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_merge(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2,
_RandomAccessIterator3 __result,
_Compare __comp,
- _LeafMerge __leaf_merge) {
+ _LeafMerge __leaf_merge) noexcept {
__chunk_partitions __partitions =
__libdispatch::__partition_chunks(std::max<ptrdiff_t>(__last1 - __first1, __last2 - __first2));
if (__partitions.__chunk_count_ == 0)
- return;
+ return __empty{};
if (__partitions.__chunk_count_ == 1) {
__leaf_merge(__first1, __last1, __first2, __last2, __result, __comp);
- return;
+ return __empty{};
}
using __merge_range_t = __merge_range<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator3>;
@@ -117,61 +127,76 @@ _LIBCPP_HIDE_FROM_ABI void __parallel_merge(
std::destroy_n(__ptr, __n_ranges);
std::allocator<__merge_range_t>().deallocate(__ptr, __n_ranges);
};
- unique_ptr<__merge_range_t[], decltype(__destroy)> __ranges(
- std::allocator<__merge_range_t>().allocate(__n_ranges), __destroy);
- // TODO: Improve the case where the smaller range is merged into just a few (or even one) chunks of the larger case
- std::__terminate_on_exception([&] {
- __merge_range_t* __r = __ranges.get();
- std::__construct_at(__r++, __first1, __first2, __result);
-
- bool __iterate_first_range = __last1 - __first1 > __last2 - __first2;
-
- auto __compute_chunk = [&](size_t __chunk_size) -> __merge_range_t {
- auto [__mid1, __mid2] = [&] {
- if (__iterate_first_range) {
- auto __m1 = __first1 + __chunk_size;
- auto __m2 = std::lower_bound(__first2, __last2, __m1[-1], __comp);
- return std::make_pair(__m1, __m2);
- } else {
- auto __m2 = __first2 + __chunk_size;
- auto __m1 = std::lower_bound(__first1, __last1, __m2[-1], __comp);
- return std::make_pair(__m1, __m2);
+ unique_ptr<__merge_range_t[], decltype(__destroy)> __ranges(
+ [&]() -> __merge_range_t* {
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+# endif
+ return std::allocator<__merge_range_t>().allocate(__n_ranges);
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (const std::bad_alloc&) {
+ return nullptr;
}
- }();
+# endif
+ }(),
+ __destroy);
- __result += (__mid1 - __first1) + (__mid2 - __first2);
- __first1 = __mid1;
- __first2 = __mid2;
- return {std::move(__mid1), std::move(__mid2), __result};
- };
+ if (!__ranges)
+ return nullopt;
+
+ // TODO: Improve the case where the smaller range is merged into just a few (or even one) chunks of the larger case
+ __merge_range_t* __r = __ranges.get();
+ std::__construct_at(__r++, __first1, __first2, __result);
+
+ bool __iterate_first_range = __last1 - __first1 > __last2 - __first2;
+
+ auto __compute_chunk = [&](size_t __chunk_size) -> __merge_range_t {
+ auto [__mid1, __mid2] = [&] {
+ if (__iterate_first_range) {
+ auto __m1 = __first1 + __chunk_size;
+ auto __m2 = std::lower_bound(__first2, __last2, __m1[-1], __comp);
+ return std::make_pair(__m1, __m2);
+ } else {
+ auto __m2 = __first2 + __chunk_size;
+ auto __m1 = std::lower_bound(__first1, __last1, __m2[-1], __comp);
+ return std::make_pair(__m1, __m2);
+ }
+ }();
+
+ __result += (__mid1 - __first1) + (__mid2 - __first2);
+ __first1 = __mid1;
+ __first2 = __mid2;
+ return {std::move(__mid1), std::move(__mid2), __result};
+ };
- // handle first chunk
- std::__construct_at(__r++, __compute_chunk(__partitions.__first_chunk_size_));
-
- // handle 2 -> N - 1 chunks
- for (ptrdiff_t __i = 0; __i != __partitions.__chunk_count_ - 2; ++__i)
- std::__construct_at(__r++, __compute_chunk(__partitions.__chunk_size_));
-
- // handle last chunk
- std::__construct_at(__r, __last1, __last2, __result);
-
- __libdispatch::__dispatch_apply(__partitions.__chunk_count_, [&](size_t __index) {
- auto __first_iters = __ranges[__index];
- auto __last_iters = __ranges[__index + 1];
- __leaf_merge(
- __first_iters.__mid1_,
- __last_iters.__mid1_,
- __first_iters.__mid2_,
- __last_iters.__mid2_,
- __first_iters.__result_,
- __comp);
- });
+ // handle first chunk
+ std::__construct_at(__r++, __compute_chunk(__partitions.__first_chunk_size_));
+
+ // handle 2 -> N - 1 chunks
+ for (ptrdiff_t __i = 0; __i != __partitions.__chunk_count_ - 2; ++__i)
+ std::__construct_at(__r++, __compute_chunk(__partitions.__chunk_size_));
+
+ // handle last chunk
+ std::__construct_at(__r, __last1, __last2, __result);
+
+ __libdispatch::__dispatch_apply(__partitions.__chunk_count_, [&](size_t __index) {
+ auto __first_iters = __ranges[__index];
+ auto __last_iters = __ranges[__index + 1];
+ __leaf_merge(
+ __first_iters.__mid1_,
+ __last_iters.__mid1_,
+ __first_iters.__mid2_,
+ __last_iters.__mid2_,
+ __first_iters.__result_,
+ __comp);
});
+
+ return __empty{};
}
template <class _RandomAccessIterator, class _Transform, class _Value, class _Combiner, class _Reduction>
-_LIBCPP_HIDE_FROM_ABI _Value __parallel_transform_reduce(
+_LIBCPP_HIDE_FROM_ABI optional<_Value> __parallel_transform_reduce(
_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Transform __transform,
@@ -211,20 +236,101 @@ _LIBCPP_HIDE_FROM_ABI _Value __parallel_transform_reduce(
}
});
- return std::__terminate_on_exception([&] {
- return std::reduce(
- std::make_move_iterator(__values.get()),
- std::make_move_iterator(__values.get() + __partitions.__chunk_count_),
- std::move(__init),
- __combiner);
- });
+ return std::reduce(
+ std::make_move_iterator(__values.get()),
+ std::make_move_iterator(__values.get() + __partitions.__chunk_count_),
+ std::move(__init),
+ __combiner);
}
-// TODO: parallelize this
template <class _RandomAccessIterator, class _Comp, class _LeafSort>
-_LIBCPP_HIDE_FROM_ABI void __parallel_stable_sort(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_stable_sort(
_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp, _LeafSort __leaf_sort) {
- __leaf_sort(__first, __last, __comp);
+ const auto __size = __last - __first;
+ auto __partitions = __libdispatch::__partition_chunks(__size);
+
+ if (__partitions.__chunk_count_ == 0)
+ return __empty{};
+
+ if (__partitions.__chunk_count_ == 1) {
+ __leaf_sort(__first, __last, __comp);
+ return __empty{};
+ }
+
+ using _Value = __iter_value_type<_RandomAccessIterator>;
+
+ auto __destroy = [__size](_Value* __ptr) {
+ std::destroy_n(__ptr, __size);
+ std::allocator<_Value>().deallocate(__ptr, __size);
+ };
+
+ // TODO: use __uninitialized_buffer
+ unique_ptr<_Value[], decltype(__destroy)> __values(std::allocator<_Value>().allocate(__size), __destroy);
+
+ // Initialize all elements to a moved-from state
+ // TODO: Don't do this - this can be done in the first merge - see https://llvm.org/PR63928
+ std::__construct_at(__values.get(), std::move(*__first));
+ for (__iter_diff_t<_RandomAccessIterator> __i = 1; __i != __size; ++__i) {
+ std::__construct_at(__values.get() + __i, std::move(__values.get()[__i - 1]));
+ }
+ *__first = std::move(__values.get()[__size - 1]);
+
+ __libdispatch::__dispatch_parallel_for(
+ __partitions,
+ __first,
+ [&__leaf_sort, &__comp](_RandomAccessIterator __chunk_first, _RandomAccessIterator __chunk_last) {
+ __leaf_sort(std::move(__chunk_first), std::move(__chunk_last), __comp);
+ });
+
+ bool __objects_are_in_buffer = false;
+ do {
+ const auto __old_chunk_size = __partitions.__chunk_size_;
+ if (__partitions.__chunk_count_ % 2 == 1) {
+ auto __inplace_merge_chunks = [&__comp, &__partitions](auto __first_chunk_begin) {
+ std::inplace_merge(
+ __first_chunk_begin,
+ __first_chunk_begin + __partitions.__first_chunk_size_,
+ __first_chunk_begin + __partitions.__first_chunk_size_ + __partitions.__chunk_size_,
+ __comp);
+ };
+ if (__objects_are_in_buffer)
+ __inplace_merge_chunks(__values.get());
+ else
+ __inplace_merge_chunks(__first);
+ __partitions.__first_chunk_size_ += 2 * __partitions.__chunk_size_;
+ } else {
+ __partitions.__first_chunk_size_ += __partitions.__chunk_size_;
+ }
+
+ __partitions.__chunk_size_ *= 2;
+ __partitions.__chunk_count_ /= 2;
+
+ auto __merge_chunks = [__partitions, __old_chunk_size, &__comp](auto __from_first, auto __to_first) {
+ __libdispatch::__dispatch_parallel_for(
+ __partitions,
+ __from_first,
+ [__old_chunk_size, &__from_first, &__to_first, &__comp](auto __chunk_first, auto __chunk_last) {
+ std::merge(std::make_move_iterator(__chunk_first),
+ std::make_move_iterator(__chunk_last - __old_chunk_size),
+ std::make_move_iterator(__chunk_last - __old_chunk_size),
+ std::make_move_iterator(__chunk_last),
+ __to_first + (__chunk_first - __from_first),
+ __comp);
+ });
+ };
+
+ if (__objects_are_in_buffer)
+ __merge_chunks(__values.get(), __first);
+ else
+ __merge_chunks(__first, __values.get());
+ __objects_are_in_buffer = !__objects_are_in_buffer;
+ } while (__partitions.__chunk_count_ > 1);
+
+ if (__objects_are_in_buffer) {
+ std::move(__values.get(), __values.get() + __size, __first);
+ }
+
+ return __empty{};
}
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/merge.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/merge.h
index d5be1e302d..b0db70f58b 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/merge.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/merge.h
@@ -12,10 +12,10 @@
#include <__algorithm/merge.h>
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__config>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/concepts.h>
#include <__type_traits/is_execution_policy.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -23,6 +23,9 @@
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_PUSH_MACROS
+# include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ExecutionPolicy,
@@ -30,7 +33,7 @@ template <class _ExecutionPolicy,
class _ForwardIterator2,
class _ForwardOutIterator,
class _Comp>
-_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
+_LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> __pstl_merge(
__cpu_backend_tag,
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
@@ -39,34 +42,35 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
_ForwardOutIterator __result,
_Comp __comp) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator1>::value &&
- __has_random_access_iterator_category<_ForwardIterator2>::value &&
- __has_random_access_iterator_category<_ForwardOutIterator>::value) {
- return std::__terminate_on_exception([&] {
- __par_backend::__parallel_merge(
- __first1,
- __last1,
- __first2,
- __last2,
- __result,
- __comp,
- [](_ForwardIterator1 __g_first1,
- _ForwardIterator1 __g_last1,
- _ForwardIterator2 __g_first2,
- _ForwardIterator2 __g_last2,
- _ForwardOutIterator __g_result,
- _Comp __g_comp) {
- return std::__pstl_merge<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{},
- std::move(__g_first1),
- std::move(__g_last1),
- std::move(__g_first2),
- std::move(__g_last2),
- std::move(__g_result),
- std::move(__g_comp));
- });
- return __result + (__last1 - __first1) + (__last2 - __first2);
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
+ auto __res = __par_backend::__parallel_merge(
+ __first1,
+ __last1,
+ __first2,
+ __last2,
+ __result,
+ __comp,
+ [](_ForwardIterator1 __g_first1,
+ _ForwardIterator1 __g_last1,
+ _ForwardIterator2 __g_first2,
+ _ForwardIterator2 __g_last2,
+ _ForwardOutIterator __g_result,
+ _Comp __g_comp) {
+ [[maybe_unused]] auto __g_res = std::__pstl_merge<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{},
+ std::move(__g_first1),
+ std::move(__g_last1),
+ std::move(__g_first2),
+ std::move(__g_last2),
+ std::move(__g_result),
+ std::move(__g_comp));
+ _LIBCPP_ASSERT_INTERNAL(__g_res, "unsed/sed should never try to allocate!");
+ });
+ if (!__res)
+ return nullopt;
+ return __result + (__last1 - __first1) + (__last2 - __first2);
} else {
return std::merge(__first1, __last1, __first2, __last2, __result, __comp);
}
@@ -74,6 +78,8 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/serial.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/serial.h
index f151c3b098..afcc7ffb26 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/serial.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/serial.h
@@ -11,8 +11,10 @@
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
#include <__config>
+#include <__utility/empty.h>
#include <__utility/move.h>
#include <cstddef>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -20,26 +22,32 @@
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_PUSH_MACROS
+# include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __par_backend {
inline namespace __serial_cpu_backend {
template <class _RandomAccessIterator, class _Fp>
-_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
+__parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
__f(__first, __last);
+ return __empty{};
}
template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
-_LIBCPP_HIDE_FROM_ABI _Tp
+_LIBCPP_HIDE_FROM_ABI optional<_Tp>
__parallel_transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {
return __reduce(std::move(__first), std::move(__last), std::move(__init));
}
template <class _RandomAccessIterator, class _Compare, class _LeafSort>
-_LIBCPP_HIDE_FROM_ABI void __parallel_stable_sort(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_stable_sort(
_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {
__leaf_sort(__first, __last, __comp);
+ return __empty{};
}
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
@@ -49,7 +57,7 @@ template <class _RandomAccessIterator1,
class _RandomAccessIterator3,
class _Compare,
class _LeafMerge>
-_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_merge(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
@@ -58,6 +66,7 @@ _LIBCPP_HIDE_FROM_ABI void __parallel_merge(
_Compare __comp,
_LeafMerge __leaf_merge) {
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
+ return __empty{};
}
// TODO: Complete this list
@@ -67,6 +76,8 @@ _LIBCPP_HIDE_FROM_ABI void __parallel_merge(
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/stable_sort.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/stable_sort.h
index 0a701443b3..34c423586c 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/stable_sort.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/stable_sort.h
@@ -13,7 +13,8 @@
#include <__algorithm/stable_sort.h>
#include <__config>
#include <__type_traits/is_execution_policy.h>
-#include <__utility/terminate_on_exception.h>
+#include <__utility/empty.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -24,17 +25,16 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Comp>
-_LIBCPP_HIDE_FROM_ABI void
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
__pstl_stable_sort(__cpu_backend_tag, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy>) {
- std::__terminate_on_exception([&] {
- __par_backend::__parallel_stable_sort(
- __first, __last, __comp, [](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
- std::stable_sort(__g_first, __g_last, __g_comp);
- });
- });
+ return __par_backend::__parallel_stable_sort(
+ __first, __last, __comp, [](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
+ std::stable_sort(__g_first, __g_last, __g_comp);
+ });
} else {
std::stable_sort(__first, __last, __comp);
+ return __empty{};
}
}
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/thread.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/thread.h
index 30eb0ae362..eb11a961b7 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/thread.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/thread.h
@@ -11,8 +11,10 @@
#include <__assert>
#include <__config>
+#include <__utility/empty.h>
#include <__utility/move.h>
#include <cstddef>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -32,20 +34,23 @@ namespace __par_backend {
inline namespace __thread_cpu_backend {
template <class _RandomAccessIterator, class _Fp>
-_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
+__parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
__f(__first, __last);
+ return __empty{};
}
template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
-_LIBCPP_HIDE_FROM_ABI _Tp
+_LIBCPP_HIDE_FROM_ABI optional<_Tp>
__parallel_transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {
return __reduce(std::move(__first), std::move(__last), std::move(__init));
}
template <class _RandomAccessIterator, class _Compare, class _LeafSort>
-_LIBCPP_HIDE_FROM_ABI void __parallel_stable_sort(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_stable_sort(
_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {
__leaf_sort(__first, __last, __comp);
+ return __empty{};
}
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
@@ -55,7 +60,7 @@ template <class _RandomAccessIterator1,
class _RandomAccessIterator3,
class _Compare,
class _LeafMerge>
-_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
+_LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_merge(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
@@ -64,6 +69,7 @@ _LIBCPP_HIDE_FROM_ABI void __parallel_merge(
_Compare __comp,
_LeafMerge __leaf_merge) {
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
+ return __empty{};
}
} // namespace __thread_cpu_backend
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform.h
index ef25ff0238..fdf1a2e78d 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform.h
@@ -12,11 +12,12 @@
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__algorithm/transform.h>
#include <__config>
+#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -24,11 +25,14 @@
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_PUSH_MACROS
+# include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Function>
_LIBCPP_HIDE_FROM_ABI _Iterator2
-__simd_walk_2(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Function __f) noexcept {
+__simd_walk(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Function __f) noexcept {
_PSTL_PRAGMA_SIMD
for (_DifferenceType __i = 0; __i < __n; ++__i)
__f(__first1[__i], __first2[__i]);
@@ -36,27 +40,27 @@ __simd_walk_2(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Fu
}
template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
-_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
+_LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> __pstl_transform(
__cpu_backend_tag,
_ForwardIterator __first,
_ForwardIterator __last,
_ForwardOutIterator __result,
_UnaryOperation __op) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value &&
- __has_random_access_iterator_category<_ForwardOutIterator>::value) {
- std::__terminate_on_exception([&] {
- std::__par_backend::__parallel_for(
- __first, __last, [__op, __first, __result](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
- return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{}, __brick_first, __brick_last, __result + (__brick_first - __first), __op);
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
+ std::__par_backend::__parallel_for(
+ __first, __last, [__op, __first, __result](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
+ auto __res = std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{}, __brick_first, __brick_last, __result + (__brick_first - __first), __op);
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ return *std::move(__res);
+ });
return __result + (__last - __first);
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value &&
- __has_random_access_iterator_category<_ForwardOutIterator>::value) {
- return std::__simd_walk_2(
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
+ return std::__simd_walk(
__first,
__last - __first,
__result,
@@ -69,7 +73,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
}
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Iterator3, class _Function>
-_LIBCPP_HIDE_FROM_ABI _Iterator3 __simd_walk_3(
+_LIBCPP_HIDE_FROM_ABI _Iterator3 __simd_walk(
_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Iterator3 __first3, _Function __f) noexcept {
_PSTL_PRAGMA_SIMD
for (_DifferenceType __i = 0; __i < __n; ++__i)
@@ -82,7 +86,7 @@ template <class _ExecutionPolicy,
class _ForwardOutIterator,
class _BinaryOperation,
enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
+_LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> __pstl_transform(
__cpu_backend_tag,
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
@@ -90,29 +94,29 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
_ForwardOutIterator __result,
_BinaryOperation __op) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator1>::value &&
- __has_random_access_iterator_category<_ForwardIterator2>::value &&
- __has_random_access_iterator_category<_ForwardOutIterator>::value) {
- std::__terminate_on_exception([&] {
- std::__par_backend::__parallel_for(
- __first1,
- __last1,
- [__op, __first1, __first2, __result](_ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last) {
- return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{},
- __brick_first,
- __brick_last,
- __first2 + (__brick_first - __first1),
- __result + (__brick_first - __first1),
- __op);
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
+ auto __res = std::__par_backend::__parallel_for(
+ __first1,
+ __last1,
+ [__op, __first1, __first2, __result](_ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last) {
+ return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{},
+ __brick_first,
+ __brick_last,
+ __first2 + (__brick_first - __first1),
+ __result + (__brick_first - __first1),
+ __op);
+ });
+ if (!__res)
+ return nullopt;
return __result + (__last1 - __first1);
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator1>::value &&
- __has_random_access_iterator_category<_ForwardIterator2>::value &&
- __has_random_access_iterator_category<_ForwardOutIterator>::value) {
- return std::__simd_walk_3(
+ __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
+ return std::__simd_walk(
__first1,
__last1 - __first1,
__first2,
@@ -127,6 +131,8 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
diff --git a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
index c51c312d93..14a0d76741 100644
--- a/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
+++ b/lib/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
@@ -11,29 +11,35 @@
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__config>
+#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__numeric/transform_reduce.h>
#include <__type_traits/is_arithmetic.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/operation_traits.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
#include <new>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
-template <
- typename _DifferenceType,
- typename _Tp,
- typename _BinaryOperation,
- typename _UnaryOperation,
- __enable_if_t<__is_trivial_plus_operation<_BinaryOperation, _Tp, _Tp>::value && is_arithmetic_v<_Tp>, int> = 0>
+template <typename _DifferenceType,
+ typename _Tp,
+ typename _BinaryOperation,
+ typename _UnaryOperation,
+ typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
+ __enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp> &&
+ is_arithmetic_v<_UnaryResult>,
+ int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
__simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _UnaryOperation __f) noexcept {
_PSTL_PRAGMA_SIMD_REDUCTION(+ : __init)
@@ -42,12 +48,14 @@ __simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _Unar
return __init;
}
-template <
- typename _Size,
- typename _Tp,
- typename _BinaryOperation,
- typename _UnaryOperation,
- __enable_if_t<!(__is_trivial_plus_operation<_BinaryOperation, _Tp, _Tp>::value && is_arithmetic_v<_Tp>), int> = 0>
+template <typename _Size,
+ typename _Tp,
+ typename _BinaryOperation,
+ typename _UnaryOperation,
+ typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
+ __enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value &&
+ is_arithmetic_v<_Tp> && is_arithmetic_v<_UnaryResult>),
+ int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
__simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept {
const _Size __block_size = __lane_size / sizeof(_Tp);
@@ -97,7 +105,7 @@ template <class _ExecutionPolicy,
class _Tp,
class _BinaryOperation1,
class _BinaryOperation2>
-_LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
+_LIBCPP_HIDE_FROM_ABI optional<_Tp> __pstl_transform_reduce(
__cpu_backend_tag,
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
@@ -106,32 +114,30 @@ _LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
_BinaryOperation1 __reduce,
_BinaryOperation2 __transform) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator1>::value &&
- __has_random_access_iterator_category<_ForwardIterator2>::value) {
- return std::__terminate_on_exception([&] {
- return __par_backend::__parallel_transform_reduce(
- __first1,
- std::move(__last1),
- [__first1, __first2, __transform](_ForwardIterator1 __iter) {
- return __transform(*__iter, *(__first2 + (__iter - __first1)));
- },
- std::move(__init),
- std::move(__reduce),
- [__first1, __first2, __reduce, __transform](
- _ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last, _Tp __brick_init) {
- return std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{},
- __brick_first,
- std::move(__brick_last),
- __first2 + (__brick_first - __first1),
- std::move(__brick_init),
- std::move(__reduce),
- std::move(__transform));
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value) {
+ return __par_backend::__parallel_transform_reduce(
+ __first1,
+ std::move(__last1),
+ [__first1, __first2, __transform](_ForwardIterator1 __iter) {
+ return __transform(*__iter, *(__first2 + (__iter - __first1)));
+ },
+ std::move(__init),
+ std::move(__reduce),
+ [__first1, __first2, __reduce, __transform](
+ _ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last, _Tp __brick_init) {
+ return *std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{},
+ __brick_first,
+ std::move(__brick_last),
+ __first2 + (__brick_first - __first1),
+ std::move(__brick_init),
+ std::move(__reduce),
+ std::move(__transform));
+ });
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator1>::value &&
- __has_random_access_iterator_category<_ForwardIterator2>::value) {
+ __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value) {
return std::__simd_transform_reduce(
__last1 - __first1, std::move(__init), std::move(__reduce), [&](__iter_diff_t<_ForwardIterator1> __i) {
return __transform(__first1[__i], __first2[__i]);
@@ -148,7 +154,7 @@ _LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
}
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
-_LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
+_LIBCPP_HIDE_FROM_ABI optional<_Tp> __pstl_transform_reduce(
__cpu_backend_tag,
_ForwardIterator __first,
_ForwardIterator __last,
@@ -156,26 +162,26 @@ _LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
_BinaryOperation __reduce,
_UnaryOperation __transform) {
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
- return std::__terminate_on_exception([&] {
- return __par_backend::__parallel_transform_reduce(
- std::move(__first),
- std::move(__last),
- [__transform](_ForwardIterator __iter) { return __transform(*__iter); },
- std::move(__init),
- __reduce,
- [__transform, __reduce](auto __brick_first, auto __brick_last, _Tp __brick_init) {
- return std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
- __cpu_backend_tag{},
- std::move(__brick_first),
- std::move(__brick_last),
- std::move(__brick_init),
- std::move(__reduce),
- std::move(__transform));
- });
- });
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
+ return __par_backend::__parallel_transform_reduce(
+ std::move(__first),
+ std::move(__last),
+ [__transform](_ForwardIterator __iter) { return __transform(*__iter); },
+ std::move(__init),
+ __reduce,
+ [__transform, __reduce](auto __brick_first, auto __brick_last, _Tp __brick_init) {
+ auto __res = std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
+ __cpu_backend_tag{},
+ std::move(__brick_first),
+ std::move(__brick_last),
+ std::move(__brick_init),
+ std::move(__reduce),
+ std::move(__transform));
+ _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
+ return *std::move(__res);
+ });
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
- __has_random_access_iterator_category<_ForwardIterator>::value) {
+ __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
return std::__simd_transform_reduce(
__last - __first,
std::move(__init),
@@ -191,4 +197,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_REDUCE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_copy.h b/lib/libcxx/include/__algorithm/pstl_copy.h
index 83c712c354..1069dcec0e 100644
--- a/lib/libcxx/include/__algorithm/pstl_copy.h
+++ b/lib/libcxx/include/__algorithm/pstl_copy.h
@@ -10,50 +10,112 @@
#define _LIBCPP___ALGORITHM_PSTL_COPY_H
#include <__algorithm/copy_n.h>
+#include <__algorithm/pstl_backend.h>
+#include <__algorithm/pstl_frontend_dispatch.h>
#include <__algorithm/pstl_transform.h>
#include <__config>
#include <__functional/identity.h>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/concepts.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/is_trivially_copyable.h>
#include <__type_traits/remove_cvref.h>
+#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
// TODO: Use the std::copy/move shenanigans to forward to std::memmove
+template <class>
+void __pstl_copy();
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
+__copy(_ExecutionPolicy&& __policy,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy, _RawPolicy),
+ [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) {
+ return std::__transform(__policy, __g_first, __g_last, __g_result, __identity());
+ },
+ std::move(__first),
+ std::move(__last),
+ std::move(__result));
+}
+
template <class _ExecutionPolicy,
class _ForwardIterator,
class _ForwardOutIterator,
- enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
- return std::transform(__policy, __first, __last, __result, __identity());
+ auto __res = std::__copy(__policy, std::move(__first), std::move(__last), std::move(__result));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
}
+template <class>
+void __pstl_copy_n();
+
template <class _ExecutionPolicy,
class _ForwardIterator,
class _ForwardOutIterator,
class _Size,
- enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> __copy_n(
+ _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _Size&& __n, _ForwardOutIterator&& __result) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy_n, _RawPolicy),
+ [&__policy](
+ _ForwardIterator __g_first, _Size __g_n, _ForwardOutIterator __g_result) -> optional<_ForwardIterator> {
+ if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
+ return std::__copy(__policy, std::move(__g_first), std::move(__g_first + __g_n), std::move(__g_result));
+ else
+ return std::copy_n(__g_first, __g_n, __g_result);
+ },
+ std::move(__first),
+ std::move(__n),
+ std::move(__result));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _Size,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) {
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value)
- return std::copy(__policy, __first, __first + __n, __result);
- else
- return std::copy_n(__first, __n, __result);
+ auto __res = std::__copy_n(__policy, std::move(__first), std::move(__n), std::move(__result));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
}
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_COPY_H
diff --git a/lib/libcxx/include/__algorithm/pstl_count.h b/lib/libcxx/include/__algorithm/pstl_count.h
index 15acb85de0..2781f6bfd3 100644
--- a/lib/libcxx/include/__algorithm/pstl_count.h
+++ b/lib/libcxx/include/__algorithm/pstl_count.h
@@ -23,12 +23,15 @@
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -41,13 +44,13 @@ template <class _ExecutionPolicy,
class _Predicate,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
-count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_diff_t<_ForwardIterator>> __count_if(
+ _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) noexcept {
using __diff_t = __iter_diff_t<_ForwardIterator>;
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count_if),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
- return std::transform_reduce(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count_if, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) -> optional<__diff_t> {
+ return std::__transform_reduce(
__policy,
std::move(__g_first),
std::move(__g_last),
@@ -60,6 +63,19 @@ count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Predicate,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
+count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ auto __res = std::__count_if(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
template <class>
void __pstl_count(); // declaration needed for the frontend dispatch below
@@ -68,11 +84,12 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
-count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_diff_t<_ForwardIterator>>
+__count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value)
+ -> optional<__iter_diff_t<_ForwardIterator>> {
return std::count_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __v) {
return __v == __g_value;
});
@@ -82,8 +99,23 @@ count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __
__value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
+count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ auto __res = std::__count(__policy, std::move(__first), std::move(__last), __value);
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *__res;
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_COUNT_H
diff --git a/lib/libcxx/include/__algorithm/pstl_equal.h b/lib/libcxx/include/__algorithm/pstl_equal.h
new file mode 100644
index 0000000000..d235c0f4f4
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/pstl_equal.h
@@ -0,0 +1,175 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_PSTL_EQUAL_H
+#define _LIBCPP___ALGORITHM_PSTL_EQUAL_H
+
+#include <__algorithm/equal.h>
+#include <__algorithm/pstl_frontend_dispatch.h>
+#include <__config>
+#include <__functional/operations.h>
+#include <__iterator/iterator_traits.h>
+#include <__numeric/pstl_transform_reduce.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class>
+void __pstl_equal();
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
+__equal(_ExecutionPolicy&& __policy,
+ _ForwardIterator1&& __first1,
+ _ForwardIterator1&& __last1,
+ _ForwardIterator2&& __first2,
+ _Pred&& __pred) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_equal, _RawPolicy),
+ [&__policy](
+ _ForwardIterator1 __g_first1, _ForwardIterator1 __g_last1, _ForwardIterator2 __g_first2, _Pred __g_pred) {
+ return std::__transform_reduce(
+ __policy,
+ std::move(__g_first1),
+ std::move(__g_last1),
+ std::move(__g_first2),
+ true,
+ std::logical_and{},
+ std::move(__g_pred));
+ },
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__pred));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI bool
+equal(_ExecutionPolicy&& __policy,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _Pred __pred) {
+ auto __res = std::__equal(__policy, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *__res;
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI bool
+equal(_ExecutionPolicy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
+ return std::equal(__policy, std::move(__first1), std::move(__last1), std::move(__first2), std::equal_to{});
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
+__equal(_ExecutionPolicy&& __policy,
+ _ForwardIterator1&& __first1,
+ _ForwardIterator1&& __last1,
+ _ForwardIterator2&& __first2,
+ _ForwardIterator2&& __last2,
+ _Pred&& __pred) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_equal, _RawPolicy),
+ [&__policy](_ForwardIterator1 __g_first1,
+ _ForwardIterator1 __g_last1,
+ _ForwardIterator2 __g_first2,
+ _ForwardIterator2 __g_last2,
+ _Pred __g_pred) -> optional<bool> {
+ if constexpr (__has_random_access_iterator_category<_ForwardIterator1>::value &&
+ __has_random_access_iterator_category<_ForwardIterator2>::value) {
+ if (__g_last1 - __g_first1 != __g_last2 - __g_first2)
+ return false;
+ return std::__equal(
+ __policy, std::move(__g_first1), std::move(__g_last1), std::move(__g_first2), std::move(__g_pred));
+ } else {
+ (void)__policy; // Avoid unused lambda capture warning
+ return std::equal(
+ std::move(__g_first1),
+ std::move(__g_last1),
+ std::move(__g_first2),
+ std::move(__g_last2),
+ std::move(__g_pred));
+ }
+ },
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ std::move(__pred));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _Pred,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI bool
+equal(_ExecutionPolicy&& __policy,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _Pred __pred) {
+ auto __res = std::__equal(
+ __policy, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *__res;
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI bool
+equal(_ExecutionPolicy&& __policy,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2) {
+ return std::equal(
+ __policy, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::equal_to{});
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_PSTL_EQUAL_H
diff --git a/lib/libcxx/include/__algorithm/pstl_fill.h b/lib/libcxx/include/__algorithm/pstl_fill.h
index d64c828d90..488b49a0fe 100644
--- a/lib/libcxx/include/__algorithm/pstl_fill.h
+++ b/lib/libcxx/include/__algorithm/pstl_fill.h
@@ -13,18 +13,22 @@
#include <__algorithm/pstl_for_each.h>
#include <__algorithm/pstl_frontend_dispatch.h>
#include <__config>
+#include <__iterator/concepts.h>
#include <__iterator/cpp17_iterator_concepts.h>
#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -37,13 +41,13 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+_LIBCPP_HIDE_FROM_ABI optional<__empty>
+__fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) noexcept {
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill),
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill, _RawPolicy),
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
- std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
+ return std::__for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
__element = __g_value;
});
},
@@ -52,6 +56,18 @@ fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __l
__value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ if (!std::__fill(__policy, std::move(__first), std::move(__last), __value))
+ std::__throw_bad_alloc();
+}
+
template <class>
void __pstl_fill_n(); // declaration needed for the frontend dispatch below
@@ -61,24 +77,40 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _SizeT __n, const _Tp& __value) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__fill_n(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _SizeT&& __n, const _Tp& __value) noexcept {
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n),
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n, _RawPolicy),
[&](_ForwardIterator __g_first, _SizeT __g_n, const _Tp& __g_value) {
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value)
+ if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
std::fill(__policy, __g_first, __g_first + __g_n, __g_value);
else
std::fill_n(__g_first, __g_n, __g_value);
+ return optional<__empty>{__empty{}};
},
std::move(__first),
- __n,
+ std::move(__n),
__value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _SizeT,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _SizeT __n, const _Tp& __value) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ if (!std::__fill_n(__policy, std::move(__first), std::move(__n), __value))
+ std::__throw_bad_alloc();
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_FILL_H
diff --git a/lib/libcxx/include/__algorithm/pstl_find.h b/lib/libcxx/include/__algorithm/pstl_find.h
index 8e8adfecfa..5b694db68a 100644
--- a/lib/libcxx/include/__algorithm/pstl_find.h
+++ b/lib/libcxx/include/__algorithm/pstl_find.h
@@ -15,17 +15,19 @@
#include <__algorithm/pstl_frontend_dispatch.h>
#include <__config>
#include <__iterator/cpp17_iterator_concepts.h>
-#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -35,13 +37,26 @@ template <class _ExecutionPolicy,
class _Predicate,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _ForwardIterator
-find_if(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_ForwardIterator>>
+__find_if(_ExecutionPolicy&&, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) noexcept {
using _Backend = typename __select_backend<_RawPolicy>::type;
return std::__pstl_find_if<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Predicate,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _ForwardIterator
+find_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__find_if(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
template <class>
void __pstl_find_if_not();
@@ -50,21 +65,36 @@ template <class _ExecutionPolicy,
class _Predicate,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _ForwardIterator
-find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_ForwardIterator>>
+__find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
- return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
- return !__g_pred(__value);
- });
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not, _RawPolicy),
+ [&](_ForwardIterator&& __g_first, _ForwardIterator&& __g_last, _Predicate&& __g_pred)
+ -> optional<__remove_cvref_t<_ForwardIterator>> {
+ return std::__find_if(
+ __policy, __g_first, __g_last, [&](__iter_reference<__remove_cvref_t<_ForwardIterator>> __value) {
+ return !__g_pred(__value);
+ });
},
std::move(__first),
std::move(__last),
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Predicate,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _ForwardIterator
+find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__find_if_not(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
template <class>
void __pstl_find();
@@ -73,23 +103,39 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _ForwardIterator
-find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_ForwardIterator>>
+__find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) noexcept {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find),
- [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
- return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
- return __element == __g_value;
- });
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find, _RawPolicy),
+ [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) -> optional<_ForwardIterator> {
+ return std::find_if(
+ __policy, __g_first, __g_last, [&](__iter_reference<__remove_cvref_t<_ForwardIterator>> __element) {
+ return __element == __g_value;
+ });
},
std::move(__first),
std::move(__last),
__value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _ForwardIterator
+find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__find(__policy, std::move(__first), std::move(__last), __value);
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_FIND_H
diff --git a/lib/libcxx/include/__algorithm/pstl_for_each.h b/lib/libcxx/include/__algorithm/pstl_for_each.h
index 09efc24950..bb7b5a61a6 100644
--- a/lib/libcxx/include/__algorithm/pstl_for_each.h
+++ b/lib/libcxx/include/__algorithm/pstl_for_each.h
@@ -14,19 +14,23 @@
#include <__algorithm/pstl_backend.h>
#include <__algorithm/pstl_frontend_dispatch.h>
#include <__config>
+#include <__iterator/concepts.h>
#include <__iterator/cpp17_iterator_concepts.h>
-#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__type_traits/void_t.h>
+#include <__utility/empty.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,11 +40,22 @@ template <class _ExecutionPolicy,
class _Function,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__for_each(_ExecutionPolicy&&, _ForwardIterator&& __first, _ForwardIterator&& __last, _Function&& __func) noexcept {
+ using _Backend = typename __select_backend<_RawPolicy>::type;
+ return std::__pstl_for_each<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__func));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Function,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI void
-for_each(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __func) {
+for_each(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Function __func) {
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
- using _Backend = typename __select_backend<_RawPolicy>::type;
- std::__pstl_for_each<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__func));
+ if (!std::__for_each(__policy, std::move(__first), std::move(__last), std::move(__func)))
+ std::__throw_bad_alloc();
}
template <class>
@@ -52,25 +67,42 @@ template <class _ExecutionPolicy,
class _Function,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _Size&& __size, _Function&& __func) noexcept {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_for_each_n),
- [&](_ForwardIterator __g_first, _Size __g_size, _Function __g_func) {
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_for_each_n, _RawPolicy),
+ [&](_ForwardIterator __g_first, _Size __g_size, _Function __g_func) -> optional<__empty> {
+ if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
std::for_each(__policy, std::move(__g_first), __g_first + __g_size, std::move(__g_func));
+ return __empty{};
} else {
std::for_each_n(std::move(__g_first), __g_size, std::move(__g_func));
+ return __empty{};
}
},
- __first,
- __size,
+ std::move(__first),
+ std::move(__size),
std::move(__func));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Size,
+ class _Function,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ auto __res = std::__for_each_n(__policy, std::move(__first), std::move(__size), std::move(__func));
+ if (!__res)
+ std::__throw_bad_alloc();
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_FOR_EACH_H
diff --git a/lib/libcxx/include/__algorithm/pstl_frontend_dispatch.h b/lib/libcxx/include/__algorithm/pstl_frontend_dispatch.h
index dc49f3e516..6fa1107491 100644
--- a/lib/libcxx/include/__algorithm/pstl_frontend_dispatch.h
+++ b/lib/libcxx/include/__algorithm/pstl_frontend_dispatch.h
@@ -21,11 +21,10 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-# define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name) \
- [](auto&&... __args) -> decltype(std::name<_RawPolicy>(typename __select_backend<_RawPolicy>::type{}, \
- std::forward<decltype(__args)>(__args)...)) { \
- return std::name<_RawPolicy>( \
- typename __select_backend<_RawPolicy>::type{}, std::forward<decltype(__args)>(__args)...); \
+# define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name, policy) \
+ [](auto&&... __args) -> decltype(std::name<policy>( \
+ typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...)) { \
+ return std::name<policy>(typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...); \
}
template <class _SpecializedImpl, class _GenericImpl, class... _Args>
diff --git a/lib/libcxx/include/__algorithm/pstl_generate.h b/lib/libcxx/include/__algorithm/pstl_generate.h
index e1ba0183dc..7133c6f4f4 100644
--- a/lib/libcxx/include/__algorithm/pstl_generate.h
+++ b/lib/libcxx/include/__algorithm/pstl_generate.h
@@ -14,15 +14,20 @@
#include <__algorithm/pstl_frontend_dispatch.h>
#include <__config>
#include <__iterator/cpp17_iterator_concepts.h>
+#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -35,13 +40,13 @@ template <class _ExecutionPolicy,
class _Generator,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__generate(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Generator&& __gen) {
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate),
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate, _RawPolicy),
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Generator __g_gen) {
- std::for_each(
+ return std::__for_each(
__policy, std::move(__g_first), std::move(__g_last), [&](__iter_reference<_ForwardIterator> __element) {
__element = __g_gen();
});
@@ -51,6 +56,18 @@ generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator
std::move(__gen));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Generator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ if (!std::__generate(__policy, std::move(__first), std::move(__last), std::move(__gen)))
+ std::__throw_bad_alloc();
+}
+
template <class>
void __pstl_generate_n();
@@ -60,23 +77,38 @@ template <class _ExecutionPolicy,
class _Generator,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) {
- _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate_n),
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__generate_n(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _Size&& __n, _Generator&& __gen) {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate_n, _RawPolicy),
[&__policy](_ForwardIterator __g_first, _Size __g_n, _Generator __g_gen) {
- std::for_each_n(__policy, std::move(__g_first), __g_n, [&](__iter_reference<_ForwardIterator> __element) {
- __element = __g_gen();
- });
+ return std::__for_each_n(
+ __policy, std::move(__g_first), std::move(__g_n), [&](__iter_reference<_ForwardIterator> __element) {
+ __element = __g_gen();
+ });
},
std::move(__first),
__n,
std::move(__gen));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Size,
+ class _Generator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) {
+ _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
+ if (!std::__generate_n(__policy, std::move(__first), std::move(__n), std::move(__gen)))
+ std::__throw_bad_alloc();
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_GENERATE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_is_partitioned.h b/lib/libcxx/include/__algorithm/pstl_is_partitioned.h
index 6f6e9b2f44..b654302122 100644
--- a/lib/libcxx/include/__algorithm/pstl_is_partitioned.h
+++ b/lib/libcxx/include/__algorithm/pstl_is_partitioned.h
@@ -18,11 +18,15 @@
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -35,10 +39,10 @@ template <class _ExecutionPolicy,
class _Predicate,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
-is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool> __is_partitioned(
+ _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) {
return std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned),
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned, _RawPolicy),
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
__g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
if (__g_first == __g_last)
@@ -51,8 +55,23 @@ is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIt
std::move(__pred));
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Predicate,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
+is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ auto __res = std::__is_partitioned(__policy, std::move(__first), std::move(__last), std::move(__pred));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_IS_PARITTIONED
diff --git a/lib/libcxx/include/__algorithm/pstl_merge.h b/lib/libcxx/include/__algorithm/pstl_merge.h
index f10ac76742..3d262db6bc 100644
--- a/lib/libcxx/include/__algorithm/pstl_merge.h
+++ b/lib/libcxx/include/__algorithm/pstl_merge.h
@@ -16,11 +16,15 @@
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -32,27 +36,57 @@ template <class _ExecutionPolicy,
class _Comp = std::less<>,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
+__merge(_ExecutionPolicy&&,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _ForwardOutIterator __result,
+ _Comp __comp = {}) noexcept {
+ using _Backend = typename __select_backend<_RawPolicy>::type;
+ return std::__pstl_merge<_RawPolicy>(
+ _Backend{},
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ std::move(__result),
+ std::move(__comp));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _ForwardOutIterator,
+ class _Comp = std::less<>,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
-merge(_ExecutionPolicy&&,
+merge(_ExecutionPolicy&& __policy,
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_ForwardOutIterator __result,
_Comp __comp = {}) {
- using _Backend = typename __select_backend<_RawPolicy>::type;
- return std::__pstl_merge<_RawPolicy>(
- _Backend{},
+ auto __res = std::__merge(
+ __policy,
std::move(__first1),
std::move(__last1),
std::move(__first2),
std::move(__last2),
std::move(__result),
std::move(__comp));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
}
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_MERGE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_move.h b/lib/libcxx/include/__algorithm/pstl_move.h
new file mode 100644
index 0000000000..d8441f1a6c
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/pstl_move.h
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_PSTL_MOVE_H
+#define _LIBCPP___ALGORITHM_PSTL_MOVE_H
+
+#include <__algorithm/copy_n.h>
+#include <__algorithm/pstl_backend.h>
+#include <__algorithm/pstl_frontend_dispatch.h>
+#include <__algorithm/pstl_transform.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__iterator/iterator_traits.h>
+#include <__type_traits/enable_if.h>
+#include <__type_traits/is_constant_evaluated.h>
+#include <__type_traits/is_execution_policy.h>
+#include <__type_traits/is_trivially_copyable.h>
+#include <__type_traits/remove_cvref.h>
+#include <optional>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// TODO: Use the std::copy/move shenanigans to forward to std::memmove
+// Investigate whether we want to still forward to std::transform(policy)
+// in that case for the execution::par part, or whether we actually want
+// to run everything serially in that case.
+
+template <class>
+void __pstl_move();
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
+__move(_ExecutionPolicy&& __policy,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_move, _RawPolicy),
+ [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) {
+ return std::__transform(__policy, __g_first, __g_last, __g_result, [](auto&& __v) { return std::move(__v); });
+ },
+ std::move(__first),
+ std::move(__last),
+ std::move(__result));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
+move(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
+ auto __res = std::__move(__policy, std::move(__first), std::move(__last), std::move(__result));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *__res;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_PSTL_MOVE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_replace.h b/lib/libcxx/include/__algorithm/pstl_replace.h
index 04ffaaba59..b1caf3fd4a 100644
--- a/lib/libcxx/include/__algorithm/pstl_replace.h
+++ b/lib/libcxx/include/__algorithm/pstl_replace.h
@@ -18,11 +18,15 @@
#include <__type_traits/enable_if.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,19 +40,21 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-replace_if(_ExecutionPolicy&& __policy,
- _ForwardIterator __first,
- _ForwardIterator __last,
- _Pred __pred,
- const _Tp& __new_value) {
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_if),
- [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred, const _Tp& __g_new_value) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__replace_if(_ExecutionPolicy&& __policy,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _Pred&& __pred,
+ const _Tp& __new_value) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_if, _RawPolicy),
+ [&__policy](
+ _ForwardIterator&& __g_first, _ForwardIterator&& __g_last, _Pred&& __g_pred, const _Tp& __g_new_value) {
std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
if (__g_pred(__element))
__element = __g_new_value;
});
+ return optional<__empty>{__empty{}};
},
std::move(__first),
std::move(__last),
@@ -56,6 +62,23 @@ replace_if(_ExecutionPolicy&& __policy,
__new_value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Pred,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+replace_if(_ExecutionPolicy&& __policy,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ _Pred __pred,
+ const _Tp& __new_value) {
+ auto __res = std::__replace_if(__policy, std::move(__first), std::move(__last), std::move(__pred), __new_value);
+ if (!__res)
+ std::__throw_bad_alloc();
+}
+
template <class>
void __pstl_replace();
@@ -64,17 +87,17 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-replace(_ExecutionPolicy&& __policy,
- _ForwardIterator __first,
- _ForwardIterator __last,
- const _Tp& __old_value,
- const _Tp& __new_value) {
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace),
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
+__replace(_ExecutionPolicy&& __policy,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ const _Tp& __old_value,
+ const _Tp& __new_value) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace, _RawPolicy),
[&__policy](
_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_old_value, const _Tp& __g_new_value) {
- std::replace_if(
+ return std::__replace_if(
__policy,
std::move(__g_first),
std::move(__g_last),
@@ -87,6 +110,21 @@ replace(_ExecutionPolicy&& __policy,
__new_value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+replace(_ExecutionPolicy&& __policy,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ const _Tp& __old_value,
+ const _Tp& __new_value) {
+ if (!std::__replace(__policy, std::move(__first), std::move(__last), __old_value, __new_value))
+ std::__throw_bad_alloc();
+}
+
template <class>
void __pstl_replace_copy_if();
@@ -97,23 +135,26 @@ template <class _ExecutionPolicy,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void replace_copy_if(
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __replace_copy_if(
_ExecutionPolicy&& __policy,
- _ForwardIterator __first,
- _ForwardIterator __last,
- _ForwardOutIterator __result,
- _Pred __pred,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result,
+ _Pred&& __pred,
const _Tp& __new_value) {
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy_if),
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy_if, _RawPolicy),
[&__policy](_ForwardIterator __g_first,
_ForwardIterator __g_last,
_ForwardOutIterator __g_result,
_Pred __g_pred,
- const _Tp& __g_new_value) {
- std::transform(__policy, __g_first, __g_last, __g_result, [&](__iter_reference<_ForwardIterator> __element) {
- return __g_pred(__element) ? __g_new_value : __element;
- });
+ const _Tp& __g_new_value) -> optional<__empty> {
+ if (!std::__transform(
+ __policy, __g_first, __g_last, __g_result, [&](__iter_reference<_ForwardIterator> __element) {
+ return __g_pred(__element) ? __g_new_value : __element;
+ }))
+ return nullopt;
+ return __empty{};
},
std::move(__first),
std::move(__last),
@@ -122,30 +163,49 @@ _LIBCPP_HIDE_FROM_ABI void replace_copy_if(
__new_value);
}
-template <class>
-void __pstl_replace_copy();
-
template <class _ExecutionPolicy,
class _ForwardIterator,
class _ForwardOutIterator,
+ class _Pred,
class _Tp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void replace_copy(
+_LIBCPP_HIDE_FROM_ABI void replace_copy_if(
_ExecutionPolicy&& __policy,
_ForwardIterator __first,
_ForwardIterator __last,
_ForwardOutIterator __result,
- const _Tp& __old_value,
+ _Pred __pred,
const _Tp& __new_value) {
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy),
+ if (!std::__replace_copy_if(
+ __policy, std::move(__first), std::move(__last), std::move(__result), std::move(__pred), __new_value))
+ std::__throw_bad_alloc();
+}
+
+template <class>
+void __pstl_replace_copy();
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __replace_copy(
+ _ExecutionPolicy&& __policy,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result,
+ const _Tp& __old_value,
+ const _Tp& __new_value) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy, _RawPolicy),
[&__policy](_ForwardIterator __g_first,
_ForwardIterator __g_last,
_ForwardOutIterator __g_result,
const _Tp& __g_old_value,
const _Tp& __g_new_value) {
- return std::replace_copy_if(
+ return std::__replace_copy_if(
__policy,
std::move(__g_first),
std::move(__g_last),
@@ -160,8 +220,28 @@ _LIBCPP_HIDE_FROM_ABI void replace_copy(
__new_value);
}
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _Tp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void replace_copy(
+ _ExecutionPolicy&& __policy,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ _ForwardOutIterator __result,
+ const _Tp& __old_value,
+ const _Tp& __new_value) {
+ if (!std::__replace_copy(
+ __policy, std::move(__first), std::move(__last), std::move(__result), __old_value, __new_value))
+ std::__throw_bad_alloc();
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_REPLACE_H
diff --git a/lib/libcxx/include/__algorithm/pstl_rotate_copy.h b/lib/libcxx/include/__algorithm/pstl_rotate_copy.h
new file mode 100644
index 0000000000..346aab1d4a
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/pstl_rotate_copy.h
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_PSTL_ROTATE_COPY_H
+#define _LIBCPP___ALGORITHM_PSTL_ROTATE_COPY_H
+
+#include <__algorithm/pstl_backend.h>
+#include <__algorithm/pstl_copy.h>
+#include <__algorithm/pstl_frontend_dispatch.h>
+#include <__type_traits/is_execution_policy.h>
+#include <optional>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class>
+void __pstl_rotate_copy();
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
+__rotate_copy(_ExecutionPolicy&& __policy,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __middle,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_rotate_copy, _RawPolicy),
+ [&__policy](_ForwardIterator __g_first,
+ _ForwardIterator __g_middle,
+ _ForwardIterator __g_last,
+ _ForwardOutIterator __g_result) -> optional<_ForwardOutIterator> {
+ auto __result_mid =
+ std::__copy(__policy, _ForwardIterator(__g_middle), std::move(__g_last), std::move(__g_result));
+ if (!__result_mid)
+ return nullopt;
+ return std::__copy(__policy, std::move(__g_first), std::move(__g_middle), *std::move(__result_mid));
+ },
+ std::move(__first),
+ std::move(__middle),
+ std::move(__last),
+ std::move(__result));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator rotate_copy(
+ _ExecutionPolicy&& __policy,
+ _ForwardIterator __first,
+ _ForwardIterator __middle,
+ _ForwardIterator __last,
+ _ForwardOutIterator __result) {
+ auto __res =
+ std::__rotate_copy(__policy, std::move(__first), std::move(__middle), std::move(__last), std::move(__result));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *__res;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_PSTL_ROTATE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/pstl_sort.h b/lib/libcxx/include/__algorithm/pstl_sort.h
index 75c77ed405..a931f76811 100644
--- a/lib/libcxx/include/__algorithm/pstl_sort.h
+++ b/lib/libcxx/include/__algorithm/pstl_sort.h
@@ -16,13 +16,18 @@
#include <__functional/operations.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
+#include <__utility/empty.h>
#include <__utility/forward.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -35,12 +40,13 @@ template <class _ExecutionPolicy,
class _Comp,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
- std::__pstl_frontend_dispatch(
- _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_sort),
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __sort(
+ _ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) noexcept {
+ return std::__pstl_frontend_dispatch(
+ _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_sort, _RawPolicy),
[&__policy](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
std::stable_sort(__policy, std::move(__g_first), std::move(__g_last), std::move(__g_comp));
+ return optional<__empty>{__empty{}};
},
std::move(__first),
std::move(__last),
@@ -49,6 +55,17 @@ sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIt
template <class _ExecutionPolicy,
class _RandomAccessIterator,
+ class _Comp,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void
+sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
+ if (!std::__sort(__policy, std::move(__first), std::move(__last), std::move(__comp)))
+ std::__throw_bad_alloc();
+}
+
+template <class _ExecutionPolicy,
+ class _RandomAccessIterator,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI void
@@ -60,4 +77,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_SORT_H
diff --git a/lib/libcxx/include/__algorithm/pstl_stable_sort.h b/lib/libcxx/include/__algorithm/pstl_stable_sort.h
index 510ffd8629..8ea0bb3f9a 100644
--- a/lib/libcxx/include/__algorithm/pstl_stable_sort.h
+++ b/lib/libcxx/include/__algorithm/pstl_stable_sort.h
@@ -15,12 +15,17 @@
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
+#include <__utility/empty.h>
#include <__utility/move.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -30,14 +35,27 @@ template <class _ExecutionPolicy,
class _Comp = less<>,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI void
-stable_sort(_ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp = {}) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __stable_sort(
+ _ExecutionPolicy&&, _RandomAccessIterator&& __first, _RandomAccessIterator&& __last, _Comp&& __comp = {}) noexcept {
using _Backend = typename __select_backend<_RawPolicy>::type;
- std::__pstl_stable_sort<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__comp));
+ return std::__pstl_stable_sort<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__comp));
+}
+
+template <class _ExecutionPolicy,
+ class _RandomAccessIterator,
+ class _Comp = less<>,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI void stable_sort(
+ _ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp = {}) {
+ if (!std::__stable_sort(__policy, std::move(__first), std::move(__last), std::move(__comp)))
+ std::__throw_bad_alloc();
}
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_STABLE_SORT_H
diff --git a/lib/libcxx/include/__algorithm/pstl_transform.h b/lib/libcxx/include/__algorithm/pstl_transform.h
index 27d95349fc..f95938782f 100644
--- a/lib/libcxx/include/__algorithm/pstl_transform.h
+++ b/lib/libcxx/include/__algorithm/pstl_transform.h
@@ -12,17 +12,19 @@
#include <__algorithm/pstl_backend.h>
#include <__config>
#include <__iterator/cpp17_iterator_concepts.h>
-#include <__iterator/iterator_traits.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/move.h>
-#include <__utility/terminate_on_exception.h>
+#include <optional>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -33,8 +35,25 @@ template <class _ExecutionPolicy,
class _UnaryOperation,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_ForwardOutIterator>>
+__transform(_ExecutionPolicy&&,
+ _ForwardIterator&& __first,
+ _ForwardIterator&& __last,
+ _ForwardOutIterator&& __result,
+ _UnaryOperation&& __op) noexcept {
+ using _Backend = typename __select_backend<_RawPolicy>::type;
+ return std::__pstl_transform<_RawPolicy>(
+ _Backend{}, std::move(__first), std::move(__last), std::move(__result), std::move(__op));
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator,
+ class _ForwardOutIterator,
+ class _UnaryOperation,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
- _ExecutionPolicy&&,
+ _ExecutionPolicy&& __policy,
_ForwardIterator __first,
_ForwardIterator __last,
_ForwardOutIterator __result,
@@ -42,9 +61,29 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator);
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(__op(*__first)));
+ auto __res = std::__transform(__policy, std::move(__first), std::move(__last), std::move(__result), std::move(__op));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
+}
+
+template <class _ExecutionPolicy,
+ class _ForwardIterator1,
+ class _ForwardIterator2,
+ class _ForwardOutIterator,
+ class _BinaryOperation,
+ class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
+ enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_ForwardOutIterator>>
+__transform(_ExecutionPolicy&&,
+ _ForwardIterator1&& __first1,
+ _ForwardIterator1&& __last1,
+ _ForwardIterator2&& __first2,
+ _ForwardOutIterator&& __result,
+ _BinaryOperation&& __op) noexcept {
using _Backend = typename __select_backend<_RawPolicy>::type;
return std::__pstl_transform<_RawPolicy>(
- _Backend{}, std::move(__first), std::move(__last), std::move(__result), std::move(__op));
+ _Backend{}, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__result), std::move(__op));
}
template <class _ExecutionPolicy,
@@ -55,7 +94,7 @@ template <class _ExecutionPolicy,
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
- _ExecutionPolicy&&,
+ _ExecutionPolicy&& __policy,
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
@@ -65,13 +104,17 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2);
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator);
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(__op(*__first1, *__first2)));
- using _Backend = typename __select_backend<_RawPolicy>::type;
- return std::__pstl_transform<_RawPolicy>(
- _Backend{}, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__result), std::move(__op));
+ auto __res = std::__transform(
+ __policy, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__result), std::move(__op));
+ if (!__res)
+ std::__throw_bad_alloc();
+ return *std::move(__res);
}
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
diff --git a/lib/libcxx/include/__algorithm/push_heap.h b/lib/libcxx/include/__algorithm/push_heap.h
index 82b571e44b..7d8720e3a9 100644
--- a/lib/libcxx/include/__algorithm/push_heap.h
+++ b/lib/libcxx/include/__algorithm/push_heap.h
@@ -28,20 +28,22 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__sift_up(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+ _Compare&& __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
if (__len > 1) {
- __len = (__len - 2) / 2;
+ __len = (__len - 2) / 2;
_RandomAccessIterator __ptr = __first + __len;
if (__comp(*__ptr, *--__last)) {
value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last));
do {
*__last = _IterOps<_AlgPolicy>::__iter_move(__ptr);
- __last = __ptr;
+ __last = __ptr;
if (__len == 0)
break;
__len = (__len - 1) / 2;
@@ -54,15 +56,15 @@ void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
}
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len);
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@@ -70,8 +72,8 @@ void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::push_heap(std::move(__first), std::move(__last), __less<>());
}
diff --git a/lib/libcxx/include/__algorithm/ranges_adjacent_find.h b/lib/libcxx/include/__algorithm/ranges_adjacent_find.h
index 5f33192666..a10b04167e 100644
--- a/lib/libcxx/include/__algorithm/ranges_adjacent_find.h
+++ b/lib/libcxx/include/__algorithm/ranges_adjacent_find.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -75,4 +78,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
diff --git a/lib/libcxx/include/__algorithm/ranges_all_of.h b/lib/libcxx/include/__algorithm/ranges_all_of.h
index 39a2ae4de0..8976541d59 100644
--- a/lib/libcxx/include/__algorithm/ranges_all_of.h
+++ b/lib/libcxx/include/__algorithm/ranges_all_of.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -66,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_any_of.h b/lib/libcxx/include/__algorithm/ranges_any_of.h
index 2ca8531102..7c775f5f64 100644
--- a/lib/libcxx/include/__algorithm/ranges_any_of.h
+++ b/lib/libcxx/include/__algorithm/ranges_any_of.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -66,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_binary_search.h b/lib/libcxx/include/__algorithm/ranges_binary_search.h
index 22008e0f1b..f3b7842d5c 100644
--- a/lib/libcxx/include/__algorithm/ranges_binary_search.h
+++ b/lib/libcxx/include/__algorithm/ranges_binary_search.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -65,4 +68,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
diff --git a/lib/libcxx/include/__algorithm/ranges_clamp.h b/lib/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f377..f5ef5fd7f2 100644
--- a/lib/libcxx/include/__algorithm/ranges_clamp.h
+++ b/lib/libcxx/include/__algorithm/ranges_clamp.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -34,12 +37,14 @@ struct __fn {
indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr const _Type& operator()(
const _Type& __value, const _Type& __low, const _Type& __high, _Comp __comp = {}, _Proj __proj = {}) const {
- _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
- "Bad bounds passed to std::ranges::clamp");
+ _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+ !bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
+ "Bad bounds passed to std::ranges::clamp");
- if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, __low)))
+ auto&& __projected = std::invoke(__proj, __value);
+ if (std::invoke(__comp, std::forward<decltype(__projected)>(__projected), std::invoke(__proj, __low)))
return __low;
- else if (std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __value)))
+ else if (std::invoke(__comp, std::invoke(__proj, __high), std::forward<decltype(__projected)>(__projected)))
return __high;
else
return __value;
@@ -56,4 +61,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_CLAMP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_contains.h b/lib/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 0000000000..00d0e54019
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+ template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
+ requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool static
+ operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) {
+ return ranges::find(std::move(__first), __last, __value, std::ref(__proj)) != __last;
+ }
+
+ template <input_range _Range, class _Type, class _Proj = identity>
+ requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool static
+ operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) {
+ return ranges::find(ranges::begin(__range), ranges::end(__range), __value, std::ref(__proj)) !=
+ ranges::end(__range);
+ }
+};
+} // namespace __contains
+
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/lib/libcxx/include/__algorithm/ranges_copy.h b/lib/libcxx/include/__algorithm/ranges_copy.h
index 1c87f074e7..e1d6d32f05 100644
--- a/lib/libcxx/include/__algorithm/ranges_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_copy.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -63,4 +66,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_copy_backward.h b/lib/libcxx/include/__algorithm/ranges_copy_backward.h
index 865e944d43..93e3260425 100644
--- a/lib/libcxx/include/__algorithm/ranges_copy_backward.h
+++ b/lib/libcxx/include/__algorithm/ranges_copy_backward.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -61,4 +64,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
diff --git a/lib/libcxx/include/__algorithm/ranges_copy_if.h b/lib/libcxx/include/__algorithm/ranges_copy_if.h
index b77dbd37fc..4b41d2154e 100644
--- a/lib/libcxx/include/__algorithm/ranges_copy_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_copy_if.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -79,4 +82,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_copy_n.h b/lib/libcxx/include/__algorithm/ranges_copy_n.h
index 99e8eee14d..4353fa9927 100644
--- a/lib/libcxx/include/__algorithm/ranges_copy_n.h
+++ b/lib/libcxx/include/__algorithm/ranges_copy_n.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -73,4 +76,6 @@ inline constexpr auto copy_n = __copy_n::__fn{};
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_N_H
diff --git a/lib/libcxx/include/__algorithm/ranges_count.h b/lib/libcxx/include/__algorithm/ranges_count.h
index 82f5456756..a8965c1b96 100644
--- a/lib/libcxx/include/__algorithm/ranges_count.h
+++ b/lib/libcxx/include/__algorithm/ranges_count.h
@@ -9,7 +9,8 @@
#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_H
#define _LIBCPP___ALGORITHM_RANGES_COUNT_H
-#include <__algorithm/ranges_count_if.h>
+#include <__algorithm/count.h>
+#include <__algorithm/iterator_operations.h>
#include <__config>
#include <__functional/identity.h>
#include <__functional/ranges_operations.h>
@@ -25,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,16 +40,14 @@ struct __fn {
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __e) { return __e == __value; };
- return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
+ return std::__count<_RangeAlgPolicy>(std::move(__first), std::move(__last), __value, __proj);
}
template <input_range _Range, class _Type, class _Proj = identity>
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range>
operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __e) { return __e == __value; };
- return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
+ return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj);
}
};
} // namespace __count
@@ -59,4 +61,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_count_if.h b/lib/libcxx/include/__algorithm/ranges_count_if.h
index 92f37d049e..71b942dd53 100644
--- a/lib/libcxx/include/__algorithm/ranges_count_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_count_if.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -71,4 +74,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_ends_with.h b/lib/libcxx/include/__algorithm/ranges_ends_with.h
new file mode 100644
index 0000000000..c2a3cae9f3
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/ranges_ends_with.h
@@ -0,0 +1,201 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_RANGES_ENDS_WITH_H
+#define _LIBCPP___ALGORITHM_RANGES_ENDS_WITH_H
+
+#include <__algorithm/ranges_equal.h>
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/advance.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/reverse_iterator.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __ends_with {
+struct __fn {
+ template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
+ static _LIBCPP_HIDE_FROM_ABI constexpr bool __ends_with_fn_impl_bidirectional(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2) {
+ auto __rbegin1 = std::make_reverse_iterator(__last1);
+ auto __rend1 = std::make_reverse_iterator(__first1);
+ auto __rbegin2 = std::make_reverse_iterator(__last2);
+ auto __rend2 = std::make_reverse_iterator(__first2);
+ return ranges::starts_with(
+ __rbegin1, __rend1, __rbegin2, __rend2, std::ref(__pred), std::ref(__proj1), std::ref(__proj2));
+ }
+
+ template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
+ static _LIBCPP_HIDE_FROM_ABI constexpr bool __ends_with_fn_impl(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2) {
+ if constexpr (std::bidirectional_iterator<_Sent1> && std::bidirectional_iterator<_Sent2> &&
+ (!std::random_access_iterator<_Sent1>)&&(!std::random_access_iterator<_Sent2>)) {
+ return __ends_with_fn_impl_bidirectional(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
+
+ } else {
+ auto __n1 = ranges::distance(__first1, __last1);
+ auto __n2 = ranges::distance(__first2, __last2);
+ if (__n2 == 0)
+ return true;
+ if (__n2 > __n1)
+ return false;
+
+ return __ends_with_fn_impl_with_offset(
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ __pred,
+ __proj1,
+ __proj2,
+ __n1 - __n2);
+ }
+ }
+
+ template <class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
+ class _Pred,
+ class _Proj1,
+ class _Proj2,
+ class _Offset>
+ static _LIBCPP_HIDE_FROM_ABI constexpr bool __ends_with_fn_impl_with_offset(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2,
+ _Offset __offset) {
+ if constexpr (std::bidirectional_iterator<_Sent1> && std::bidirectional_iterator<_Sent2> &&
+ !std::random_access_iterator<_Sent1> && !std::random_access_iterator<_Sent2>) {
+ return __ends_with_fn_impl_bidirectional(
+ std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
+
+ } else {
+ ranges::advance(__first1, __offset);
+ return ranges::equal(
+ std::move(__first1),
+ std::move(__last1),
+ std::move(__first2),
+ std::move(__last2),
+ std::ref(__pred),
+ std::ref(__proj1),
+ std::ref(__proj2));
+ }
+ }
+
+ template <input_iterator _Iter1,
+ sentinel_for<_Iter1> _Sent1,
+ input_iterator _Iter2,
+ sentinel_for<_Iter2> _Sent2,
+ class _Pred = ranges::equal_to,
+ class _Proj1 = identity,
+ class _Proj2 = identity>
+ requires(forward_iterator<_Iter1> || sized_sentinel_for<_Sent1, _Iter1>) &&
+ (forward_iterator<_Iter2> || sized_sentinel_for<_Sent2, _Iter2>) &&
+ indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred __pred = {},
+ _Proj1 __proj1 = {},
+ _Proj2 __proj2 = {}) const {
+ return __ends_with_fn_impl(
+ std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
+ }
+
+ template <input_range _Range1,
+ input_range _Range2,
+ class _Pred = ranges::equal_to,
+ class _Proj1 = identity,
+ class _Proj2 = identity>
+ requires(forward_range<_Range1> || sized_range<_Range1>) && (forward_range<_Range2> || sized_range<_Range2>) &&
+ indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+ _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
+ if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
+ auto __n1 = ranges::size(__range1);
+ auto __n2 = ranges::size(__range2);
+ if (__n2 == 0)
+ return true;
+ if (__n2 > __n1)
+ return false;
+ auto __offset = __n1 - __n2;
+
+ return __ends_with_fn_impl_with_offset(
+ ranges::begin(__range1),
+ ranges::end(__range1),
+ ranges::begin(__range2),
+ ranges::end(__range2),
+ __pred,
+ __proj1,
+ __proj2,
+ __offset);
+
+ } else {
+ return __ends_with_fn_impl(
+ ranges::begin(__range1),
+ ranges::end(__range1),
+ ranges::begin(__range2),
+ ranges::end(__range2),
+ __pred,
+ __proj1,
+ __proj2);
+ }
+ }
+};
+} // namespace __ends_with
+
+inline namespace __cpo {
+inline constexpr auto ends_with = __ends_with::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_RANGES_ENDS_WITH_H
diff --git a/lib/libcxx/include/__algorithm/ranges_equal.h b/lib/libcxx/include/__algorithm/ranges_equal.h
index 4cb1f7df19..31c7ee261d 100644
--- a/lib/libcxx/include/__algorithm/ranges_equal.h
+++ b/lib/libcxx/include/__algorithm/ranges_equal.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -101,4 +104,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H
diff --git a/lib/libcxx/include/__algorithm/ranges_equal_range.h b/lib/libcxx/include/__algorithm/ranges_equal_range.h
index ed78cf312c..4c1c3834ba 100644
--- a/lib/libcxx/include/__algorithm/ranges_equal_range.h
+++ b/lib/libcxx/include/__algorithm/ranges_equal_range.h
@@ -1,6 +1,6 @@
//===----------------------------------------------------------------------===//
//
-// Part of the LLVM __project, under the Apache License v2.0 with LLVM Exceptions.
+// 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
//
@@ -30,6 +30,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -72,4 +75,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_fill.h b/lib/libcxx/include/__algorithm/ranges_fill.h
index 88a892f5c2..7a177d85e9 100644
--- a/lib/libcxx/include/__algorithm/ranges_fill.h
+++ b/lib/libcxx/include/__algorithm/ranges_fill.h
@@ -20,6 +20,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -54,4 +57,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FILL_H
diff --git a/lib/libcxx/include/__algorithm/ranges_fill_n.h b/lib/libcxx/include/__algorithm/ranges_fill_n.h
index dbd8ec27ae..a6e988c008 100644
--- a/lib/libcxx/include/__algorithm/ranges_fill_n.h
+++ b/lib/libcxx/include/__algorithm/ranges_fill_n.h
@@ -17,6 +17,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -45,4 +48,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FILL_N_H
diff --git a/lib/libcxx/include/__algorithm/ranges_find.h b/lib/libcxx/include/__algorithm/ranges_find.h
index de870e3811..7459fad717 100644
--- a/lib/libcxx/include/__algorithm/ranges_find.h
+++ b/lib/libcxx/include/__algorithm/ranges_find.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -72,4 +75,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_H
diff --git a/lib/libcxx/include/__algorithm/ranges_find_end.h b/lib/libcxx/include/__algorithm/ranges_find_end.h
index 2c57ad424b..0bda4f3e1c 100644
--- a/lib/libcxx/include/__algorithm/ranges_find_end.h
+++ b/lib/libcxx/include/__algorithm/ranges_find_end.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -95,4 +98,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H
diff --git a/lib/libcxx/include/__algorithm/ranges_find_first_of.h b/lib/libcxx/include/__algorithm/ranges_find_first_of.h
index ec6d52c632..63a7b8335f 100644
--- a/lib/libcxx/include/__algorithm/ranges_find_first_of.h
+++ b/lib/libcxx/include/__algorithm/ranges_find_first_of.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -98,4 +101,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_find_if.h b/lib/libcxx/include/__algorithm/ranges_find_if.h
index af54a5007e..52ae55ce96 100644
--- a/lib/libcxx/include/__algorithm/ranges_find_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_find_if.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -67,4 +70,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_find_if_not.h b/lib/libcxx/include/__algorithm/ranges_find_if_not.h
index 6beade1462..60c6796cbb 100644
--- a/lib/libcxx/include/__algorithm/ranges_find_if_not.h
+++ b/lib/libcxx/include/__algorithm/ranges_find_if_not.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -39,14 +42,14 @@ struct __fn {
indirect_unary_predicate<projected<_Ip, _Proj>> _Pred>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip
operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const {
- auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
+ auto __pred2 = [&](auto&& __e) -> bool { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred2, __proj);
}
template <input_range _Rp, class _Proj = identity, indirect_unary_predicate<projected<iterator_t<_Rp>, _Proj>> _Pred>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp>
operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const {
- auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
+ auto __pred2 = [&](auto&& __e) -> bool { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj);
}
};
@@ -61,4 +64,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_for_each.h b/lib/libcxx/include/__algorithm/ranges_for_each.h
index 7878ed2670..225dc774c8 100644
--- a/lib/libcxx/include/__algorithm/ranges_for_each.h
+++ b/lib/libcxx/include/__algorithm/ranges_for_each.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
diff --git a/lib/libcxx/include/__algorithm/ranges_for_each_n.h b/lib/libcxx/include/__algorithm/ranges_for_each_n.h
index 53ccb9a603..d1fdca34cc 100644
--- a/lib/libcxx/include/__algorithm/ranges_for_each_n.h
+++ b/lib/libcxx/include/__algorithm/ranges_for_each_n.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -56,4 +59,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
diff --git a/lib/libcxx/include/__algorithm/ranges_generate.h b/lib/libcxx/include/__algorithm/ranges_generate.h
index 3ff1e13c42..e6467198e6 100644
--- a/lib/libcxx/include/__algorithm/ranges_generate.h
+++ b/lib/libcxx/include/__algorithm/ranges_generate.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -65,4 +68,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_generate_n.h b/lib/libcxx/include/__algorithm/ranges_generate_n.h
index c025c621a1..cd5fd7483a 100644
--- a/lib/libcxx/include/__algorithm/ranges_generate_n.h
+++ b/lib/libcxx/include/__algorithm/ranges_generate_n.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -57,4 +60,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
diff --git a/lib/libcxx/include/__algorithm/ranges_includes.h b/lib/libcxx/include/__algorithm/ranges_includes.h
index aa35080c8c..0bc4c043bd 100644
--- a/lib/libcxx/include/__algorithm/ranges_includes.h
+++ b/lib/libcxx/include/__algorithm/ranges_includes.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -90,4 +93,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
diff --git a/lib/libcxx/include/__algorithm/ranges_inplace_merge.h b/lib/libcxx/include/__algorithm/ranges_inplace_merge.h
index 86001b003d..d94c0ad465 100644
--- a/lib/libcxx/include/__algorithm/ranges_inplace_merge.h
+++ b/lib/libcxx/include/__algorithm/ranges_inplace_merge.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -76,4 +79,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_heap.h b/lib/libcxx/include/__algorithm/ranges_is_heap.h
index f298c347b7..122368c90d 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_heap.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_heap.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_heap_until.h b/lib/libcxx/include/__algorithm/ranges_is_heap_until.h
index 73f13fb504..b2705d37a6 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_heap_until.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_heap_until.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_partitioned.h b/lib/libcxx/include/__algorithm/ranges_is_partitioned.h
index 76db870efc..c6a585c9f5 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_partitioned.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_partitioned.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -78,4 +81,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_permutation.h b/lib/libcxx/include/__algorithm/ranges_is_permutation.h
index 2b99839bc6..e0423d722b 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_permutation.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_permutation.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -99,4 +102,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_sorted.h b/lib/libcxx/include/__algorithm/ranges_is_sorted.h
index 3eb2c768d6..d71035d5aa 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_sorted.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_sorted.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -59,4 +62,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
diff --git a/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h b/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h
index 19e9875d27..dcfb6a4e18 100644
--- a/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h
+++ b/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -74,4 +77,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
diff --git a/lib/libcxx/include/__algorithm/ranges_iterator_concept.h b/lib/libcxx/include/__algorithm/ranges_iterator_concept.h
index 9a92030403..2af891d3af 100644
--- a/lib/libcxx/include/__algorithm/ranges_iterator_concept.h
+++ b/lib/libcxx/include/__algorithm/ranges_iterator_concept.h
@@ -18,6 +18,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -48,4 +51,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h b/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h
index 5b843dfd7b..90e96b5465 100644
--- a/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h
+++ b/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -98,4 +101,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_lower_bound.h b/lib/libcxx/include/__algorithm/ranges_lower_bound.h
index 58b3f815b9..ab1f80e7ab 100644
--- a/lib/libcxx/include/__algorithm/ranges_lower_bound.h
+++ b/lib/libcxx/include/__algorithm/ranges_lower_bound.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -65,4 +68,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H
diff --git a/lib/libcxx/include/__algorithm/ranges_make_heap.h b/lib/libcxx/include/__algorithm/ranges_make_heap.h
index f17eabff43..fe9c024fbf 100644
--- a/lib/libcxx/include/__algorithm/ranges_make_heap.h
+++ b/lib/libcxx/include/__algorithm/ranges_make_heap.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -77,4 +80,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_max.h b/lib/libcxx/include/__algorithm/ranges_max.h
index 5cc418d339..0f89cb2ff5 100644
--- a/lib/libcxx/include/__algorithm/ranges_max.h
+++ b/lib/libcxx/include/__algorithm/ranges_max.h
@@ -54,9 +54,10 @@ struct __fn {
indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp
operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
- _LIBCPP_ASSERT_UNCATEGORIZED(__il.begin() != __il.end(), "initializer_list must contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __il.begin() != __il.end(), "initializer_list must contain at least one element");
- auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
+ auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp_lhs_rhs_swapped, __proj);
}
@@ -69,10 +70,12 @@ struct __fn {
auto __first = ranges::begin(__r);
auto __last = ranges::end(__r);
- _LIBCPP_ASSERT_UNCATEGORIZED(__first != __last, "range must contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element");
if constexpr (forward_range<_Rp> && !__is_cheap_to_copy<range_value_t<_Rp>>) {
- auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
+ auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool {
+ return std::invoke(__comp, __rhs, __lhs);
+ };
return *ranges::__min_element_impl(std::move(__first), std::move(__last), __comp_lhs_rhs_swapped, __proj);
} else {
range_value_t<_Rp> __result = *__first;
diff --git a/lib/libcxx/include/__algorithm/ranges_max_element.h b/lib/libcxx/include/__algorithm/ranges_max_element.h
index 2d92661c81..83adf49b61 100644
--- a/lib/libcxx/include/__algorithm/ranges_max_element.h
+++ b/lib/libcxx/include/__algorithm/ranges_max_element.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -37,7 +40,7 @@ struct __fn {
indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip
operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
- auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
+ auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
return ranges::__min_element_impl(__first, __last, __comp_lhs_rhs_swapped, __proj);
}
@@ -46,7 +49,7 @@ struct __fn {
indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp>
operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
- auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
+ auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj);
}
};
@@ -61,4 +64,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_merge.h b/lib/libcxx/include/__algorithm/ranges_merge.h
index 7f49154ec9..bdf9a62d90 100644
--- a/lib/libcxx/include/__algorithm/ranges_merge.h
+++ b/lib/libcxx/include/__algorithm/ranges_merge.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -130,4 +133,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MERGE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_min.h b/lib/libcxx/include/__algorithm/ranges_min.h
index be15b45367..8757358cdf 100644
--- a/lib/libcxx/include/__algorithm/ranges_min.h
+++ b/lib/libcxx/include/__algorithm/ranges_min.h
@@ -53,7 +53,8 @@ struct __fn {
indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp
operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
- _LIBCPP_ASSERT_UNCATEGORIZED(__il.begin() != __il.end(), "initializer_list must contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __il.begin() != __il.end(), "initializer_list must contain at least one element");
return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj);
}
@@ -65,7 +66,7 @@ struct __fn {
operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
auto __first = ranges::begin(__r);
auto __last = ranges::end(__r);
- _LIBCPP_ASSERT_UNCATEGORIZED(__first != __last, "range must contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element");
if constexpr (forward_range<_Rp> && !__is_cheap_to_copy<range_value_t<_Rp>>) {
return *ranges::__min_element_impl(__first, __last, __comp, __proj);
} else {
diff --git a/lib/libcxx/include/__algorithm/ranges_min_element.h b/lib/libcxx/include/__algorithm/ranges_min_element.h
index 07826a0e6b..4b9cb76da5 100644
--- a/lib/libcxx/include/__algorithm/ranges_min_element.h
+++ b/lib/libcxx/include/__algorithm/ranges_min_element.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_minmax.h b/lib/libcxx/include/__algorithm/ranges_minmax.h
index a5b5cf9bd0..22a62b620c 100644
--- a/lib/libcxx/include/__algorithm/ranges_minmax.h
+++ b/lib/libcxx/include/__algorithm/ranges_minmax.h
@@ -65,7 +65,8 @@ struct __fn {
indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<_Type>
operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const {
- _LIBCPP_ASSERT_UNCATEGORIZED(__il.begin() != __il.end(), "initializer_list has to contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __il.begin() != __il.end(), "initializer_list has to contain at least one element");
auto __iters = std::__minmax_element_impl(__il.begin(), __il.end(), __comp, __proj);
return ranges::minmax_result<_Type>{*__iters.first, *__iters.second};
}
@@ -80,7 +81,7 @@ struct __fn {
auto __last = ranges::end(__r);
using _ValueT = range_value_t<_Range>;
- _LIBCPP_ASSERT_UNCATEGORIZED(__first != __last, "range has to contain at least one element");
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range has to contain at least one element");
if constexpr (forward_range<_Range>) {
// Special-case the one element case. Avoid repeatedly initializing objects from the result of an iterator
diff --git a/lib/libcxx/include/__algorithm/ranges_minmax_element.h b/lib/libcxx/include/__algorithm/ranges_minmax_element.h
index a52319f6b5..5132856ebc 100644
--- a/lib/libcxx/include/__algorithm/ranges_minmax_element.h
+++ b/lib/libcxx/include/__algorithm/ranges_minmax_element.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -70,4 +73,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H
diff --git a/lib/libcxx/include/__algorithm/ranges_mismatch.h b/lib/libcxx/include/__algorithm/ranges_mismatch.h
index db9bfc8e87..037af39126 100644
--- a/lib/libcxx/include/__algorithm/ranges_mismatch.h
+++ b/lib/libcxx/include/__algorithm/ranges_mismatch.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
@@ -86,4 +89,6 @@ constexpr inline auto mismatch = __mismatch::__fn{};
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
diff --git a/lib/libcxx/include/__algorithm/ranges_move.h b/lib/libcxx/include/__algorithm/ranges_move.h
index 8bd2409f89..be869f36c9 100644
--- a/lib/libcxx/include/__algorithm/ranges_move.h
+++ b/lib/libcxx/include/__algorithm/ranges_move.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -66,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_move_backward.h b/lib/libcxx/include/__algorithm/ranges_move_backward.h
index ee390a40e4..6d4071a33b 100644
--- a/lib/libcxx/include/__algorithm/ranges_move_backward.h
+++ b/lib/libcxx/include/__algorithm/ranges_move_backward.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -68,4 +71,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
diff --git a/lib/libcxx/include/__algorithm/ranges_next_permutation.h b/lib/libcxx/include/__algorithm/ranges_next_permutation.h
index 9ebab3ea7c..18535e0a62 100644
--- a/lib/libcxx/include/__algorithm/ranges_next_permutation.h
+++ b/lib/libcxx/include/__algorithm/ranges_next_permutation.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -70,4 +73,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_none_of.h b/lib/libcxx/include/__algorithm/ranges_none_of.h
index b0d363895e..59bd87997d 100644
--- a/lib/libcxx/include/__algorithm/ranges_none_of.h
+++ b/lib/libcxx/include/__algorithm/ranges_none_of.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -67,4 +70,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_NONE_OF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_nth_element.h b/lib/libcxx/include/__algorithm/ranges_nth_element.h
index 7abdbd0889..90ade9efe1 100644
--- a/lib/libcxx/include/__algorithm/ranges_nth_element.h
+++ b/lib/libcxx/include/__algorithm/ranges_nth_element.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -76,4 +79,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_partial_sort.h b/lib/libcxx/include/__algorithm/ranges_partial_sort.h
index 9ec8882097..c67247d2e0 100644
--- a/lib/libcxx/include/__algorithm/ranges_partial_sort.h
+++ b/lib/libcxx/include/__algorithm/ranges_partial_sort.h
@@ -33,6 +33,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -74,4 +77,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h
index eba7d9ac41..b3bdeb78fb 100644
--- a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h
@@ -30,6 +30,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -106,4 +109,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_partition.h b/lib/libcxx/include/__algorithm/ranges_partition.h
index 89d192b51f..a67ac4c967 100644
--- a/lib/libcxx/include/__algorithm/ranges_partition.h
+++ b/lib/libcxx/include/__algorithm/ranges_partition.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -80,4 +83,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_partition_copy.h b/lib/libcxx/include/__algorithm/ranges_partition_copy.h
index 6a16b02db3..d60c865dd2 100644
--- a/lib/libcxx/include/__algorithm/ranges_partition_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_partition_copy.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -102,4 +105,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_partition_point.h b/lib/libcxx/include/__algorithm/ranges_partition_point.h
index 6fc20e7d00..c5b11b5fed 100644
--- a/lib/libcxx/include/__algorithm/ranges_partition_point.h
+++ b/lib/libcxx/include/__algorithm/ranges_partition_point.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -85,4 +88,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_pop_heap.h b/lib/libcxx/include/__algorithm/ranges_pop_heap.h
index 364cfe94b1..01f92c0f22 100644
--- a/lib/libcxx/include/__algorithm/ranges_pop_heap.h
+++ b/lib/libcxx/include/__algorithm/ranges_pop_heap.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -78,4 +81,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_prev_permutation.h b/lib/libcxx/include/__algorithm/ranges_prev_permutation.h
index ae7a68cce5..225cee9b75 100644
--- a/lib/libcxx/include/__algorithm/ranges_prev_permutation.h
+++ b/lib/libcxx/include/__algorithm/ranges_prev_permutation.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -70,4 +73,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_push_heap.h b/lib/libcxx/include/__algorithm/ranges_push_heap.h
index 1ed9c953f5..9d187af38c 100644
--- a/lib/libcxx/include/__algorithm/ranges_push_heap.h
+++ b/lib/libcxx/include/__algorithm/ranges_push_heap.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -77,4 +80,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_remove.h b/lib/libcxx/include/__algorithm/ranges_remove.h
index bf0928df59..315bed8fba 100644
--- a/lib/libcxx/include/__algorithm/ranges_remove.h
+++ b/lib/libcxx/include/__algorithm/ranges_remove.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,7 +39,7 @@ struct __fn {
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __other) { return __value == __other; };
+ auto __pred = [&](auto&& __other) -> bool { return __value == __other; };
return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj);
}
@@ -45,7 +48,7 @@ struct __fn {
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __other) { return __value == __other; };
+ auto __pred = [&](auto&& __other) -> bool { return __value == __other; };
return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
}
};
@@ -60,4 +63,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_remove_copy.h b/lib/libcxx/include/__algorithm/ranges_remove_copy.h
index 457d593957..84529eceac 100644
--- a/lib/libcxx/include/__algorithm/ranges_remove_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_remove_copy.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -47,7 +50,7 @@ struct __fn {
indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type*>
_LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result<_InIter, _OutIter>
operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __val) { return __value == __val; };
+ auto __pred = [&](auto&& __val) -> bool { return __value == __val; };
return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
}
@@ -56,7 +59,7 @@ struct __fn {
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
_LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result<borrowed_iterator_t<_Range>, _OutIter>
operator()(_Range&& __range, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __val) { return __value == __val; };
+ auto __pred = [&](auto&& __val) -> bool { return __value == __val; };
return ranges::__remove_copy_if_impl(
ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj);
}
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h b/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h
index c07b4813d7..56fe017533 100644
--- a/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h
@@ -29,6 +29,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -87,4 +90,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_remove_if.h b/lib/libcxx/include/__algorithm/ranges_remove_if.h
index 4b7aa2d2be..943dbdd738 100644
--- a/lib/libcxx/include/__algorithm/ranges_remove_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_remove_if.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -81,4 +84,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_replace.h b/lib/libcxx/include/__algorithm/ranges_replace.h
index 714fd5c7b0..2b88dc0329 100644
--- a/lib/libcxx/include/__algorithm/ranges_replace.h
+++ b/lib/libcxx/include/__algorithm/ranges_replace.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -36,7 +39,7 @@ struct __fn {
indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type1*>
_LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(
_Iter __first, _Sent __last, const _Type1& __old_value, const _Type2& __new_value, _Proj __proj = {}) const {
- auto __pred = [&](const auto& __val) { return __val == __old_value; };
+ auto __pred = [&](const auto& __val) -> bool { return __val == __old_value; };
return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj);
}
@@ -45,7 +48,7 @@ struct __fn {
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type1*>
_LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
operator()(_Range&& __range, const _Type1& __old_value, const _Type2& __new_value, _Proj __proj = {}) const {
- auto __pred = [&](auto&& __val) { return __val == __old_value; };
+ auto __pred = [&](auto&& __val) -> bool { return __val == __old_value; };
return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
}
};
@@ -60,4 +63,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_replace_copy.h b/lib/libcxx/include/__algorithm/ranges_replace_copy.h
index 124ff8f2c5..633f993e5c 100644
--- a/lib/libcxx/include/__algorithm/ranges_replace_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_replace_copy.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -53,7 +56,7 @@ struct __fn {
const _OldType& __old_value,
const _NewType& __new_value,
_Proj __proj = {}) const {
- auto __pred = [&](const auto& __value) { return __value == __old_value; };
+ auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; };
return ranges::__replace_copy_if_impl(
std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj);
}
@@ -68,7 +71,7 @@ struct __fn {
_LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<borrowed_iterator_t<_Range>, _OutIter> operator()(
_Range&& __range, _OutIter __result, const _OldType& __old_value, const _NewType& __new_value, _Proj __proj = {})
const {
- auto __pred = [&](const auto& __value) { return __value == __old_value; };
+ auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; };
return ranges::__replace_copy_if_impl(
ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj);
}
@@ -85,4 +88,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h b/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h
index 10ed1fda6c..e065c3ac0a 100644
--- a/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -90,4 +93,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_replace_if.h b/lib/libcxx/include/__algorithm/ranges_replace_if.h
index 519fa32029..6445f42aea 100644
--- a/lib/libcxx/include/__algorithm/ranges_replace_if.h
+++ b/lib/libcxx/include/__algorithm/ranges_replace_if.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -73,4 +76,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H
diff --git a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h
index 35b9edba0b..60043787a7 100644
--- a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -62,4 +65,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_rotate.h b/lib/libcxx/include/__algorithm/ranges_rotate.h
index ebed9bbd54..8d33a6f079 100644
--- a/lib/libcxx/include/__algorithm/ranges_rotate.h
+++ b/lib/libcxx/include/__algorithm/ranges_rotate.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -63,4 +66,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_rotate_copy.h b/lib/libcxx/include/__algorithm/ranges_rotate_copy.h
index 301672707f..26fe110b53 100644
--- a/lib/libcxx/include/__algorithm/ranges_rotate_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_rotate_copy.h
@@ -13,7 +13,6 @@
#include <__algorithm/ranges_copy.h>
#include <__config>
#include <__iterator/concepts.h>
-#include <__iterator/reverse_iterator.h>
#include <__ranges/access.h>
#include <__ranges/concepts.h>
#include <__ranges/dangling.h>
@@ -23,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -34,7 +36,7 @@ using rotate_copy_result = in_out_result<_InIter, _OutIter>;
namespace __rotate_copy {
struct __fn {
- template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
+ template <forward_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
requires indirectly_copyable<_InIter, _OutIter>
_LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<_InIter, _OutIter>
operator()(_InIter __first, _InIter __middle, _Sent __last, _OutIter __result) const {
@@ -43,7 +45,7 @@ struct __fn {
return {std::move(__res1.in), std::move(__res2.out)};
}
- template <bidirectional_range _Range, weakly_incrementable _OutIter>
+ template <forward_range _Range, weakly_incrementable _OutIter>
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
_LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<borrowed_iterator_t<_Range>, _OutIter>
operator()(_Range&& __range, iterator_t<_Range> __middle, _OutIter __result) const {
@@ -61,4 +63,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_sample.h b/lib/libcxx/include/__algorithm/ranges_sample.h
index d347d82205..e4f60a7b66 100644
--- a/lib/libcxx/include/__algorithm/ranges_sample.h
+++ b/lib/libcxx/include/__algorithm/ranges_sample.h
@@ -27,6 +27,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -66,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_search_n.h b/lib/libcxx/include/__algorithm/ranges_search_n.h
index 4e53f30f71..4c1d73d8e6 100644
--- a/lib/libcxx/include/__algorithm/ranges_search_n.h
+++ b/lib/libcxx/include/__algorithm/ranges_search_n.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -108,4 +111,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H
diff --git a/lib/libcxx/include/__algorithm/ranges_set_difference.h b/lib/libcxx/include/__algorithm/ranges_set_difference.h
index a9453ed336..0841fb4ffd 100644
--- a/lib/libcxx/include/__algorithm/ranges_set_difference.h
+++ b/lib/libcxx/include/__algorithm/ranges_set_difference.h
@@ -30,6 +30,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -100,4 +103,7 @@ inline constexpr auto set_difference = __set_difference::__fn{};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_set_intersection.h b/lib/libcxx/include/__algorithm/ranges_set_intersection.h
index 4cdcbb7505..9427379745 100644
--- a/lib/libcxx/include/__algorithm/ranges_set_intersection.h
+++ b/lib/libcxx/include/__algorithm/ranges_set_intersection.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -105,4 +108,7 @@ inline constexpr auto set_intersection = __set_intersection::__fn{};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h b/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h
index d8710a1c47..995eb0999d 100644
--- a/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h
+++ b/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h
@@ -28,6 +28,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -105,4 +108,7 @@ inline constexpr auto set_symmetric_difference = __set_symmetric_difference::__f
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_set_union.h b/lib/libcxx/include/__algorithm/ranges_set_union.h
index c627166fff..e870e390cc 100644
--- a/lib/libcxx/include/__algorithm/ranges_set_union.h
+++ b/lib/libcxx/include/__algorithm/ranges_set_union.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -107,4 +110,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_shuffle.h b/lib/libcxx/include/__algorithm/ranges_shuffle.h
index fca420058d..ab98ea22ca 100644
--- a/lib/libcxx/include/__algorithm/ranges_shuffle.h
+++ b/lib/libcxx/include/__algorithm/ranges_shuffle.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -64,4 +67,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_sort.h b/lib/libcxx/include/__algorithm/ranges_sort.h
index 2ad0e0c233..0296c146b3 100644
--- a/lib/libcxx/include/__algorithm/ranges_sort.h
+++ b/lib/libcxx/include/__algorithm/ranges_sort.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -76,4 +79,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SORT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_sort_heap.h b/lib/libcxx/include/__algorithm/ranges_sort_heap.h
index 365c7dba61..bab30df170 100644
--- a/lib/libcxx/include/__algorithm/ranges_sort_heap.h
+++ b/lib/libcxx/include/__algorithm/ranges_sort_heap.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -77,4 +80,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/ranges_stable_partition.h b/lib/libcxx/include/__algorithm/ranges_stable_partition.h
index 44937fa589..f34027ff77 100644
--- a/lib/libcxx/include/__algorithm/ranges_stable_partition.h
+++ b/lib/libcxx/include/__algorithm/ranges_stable_partition.h
@@ -34,6 +34,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -84,4 +87,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H
diff --git a/lib/libcxx/include/__algorithm/ranges_stable_sort.h b/lib/libcxx/include/__algorithm/ranges_stable_sort.h
index a4eed38363..93909e253c 100644
--- a/lib/libcxx/include/__algorithm/ranges_stable_sort.h
+++ b/lib/libcxx/include/__algorithm/ranges_stable_sort.h
@@ -31,6 +31,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -74,4 +77,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H
diff --git a/lib/libcxx/include/__algorithm/ranges_starts_with.h b/lib/libcxx/include/__algorithm/ranges_starts_with.h
index 7da78001d8..90e184aa9b 100644
--- a/lib/libcxx/include/__algorithm/ranges_starts_with.h
+++ b/lib/libcxx/include/__algorithm/ranges_starts_with.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 23
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -87,4 +90,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 23
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H
diff --git a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h
index 1d0ebc0d52..b6d9f61839 100644
--- a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h
+++ b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h
@@ -24,6 +24,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -62,4 +65,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H
diff --git a/lib/libcxx/include/__algorithm/ranges_transform.h b/lib/libcxx/include/__algorithm/ranges_transform.h
index f66a07ac02..7850ec4f84 100644
--- a/lib/libcxx/include/__algorithm/ranges_transform.h
+++ b/lib/libcxx/include/__algorithm/ranges_transform.h
@@ -26,6 +26,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -169,4 +172,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
diff --git a/lib/libcxx/include/__algorithm/ranges_unique.h b/lib/libcxx/include/__algorithm/ranges_unique.h
index b17e01fc50..7340310eb3 100644
--- a/lib/libcxx/include/__algorithm/ranges_unique.h
+++ b/lib/libcxx/include/__algorithm/ranges_unique.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -74,4 +77,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
diff --git a/lib/libcxx/include/__algorithm/ranges_unique_copy.h b/lib/libcxx/include/__algorithm/ranges_unique_copy.h
index 7e89f9d97a..61133885ae 100644
--- a/lib/libcxx/include/__algorithm/ranges_unique_copy.h
+++ b/lib/libcxx/include/__algorithm/ranges_unique_copy.h
@@ -32,6 +32,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -112,4 +115,6 @@ _LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/ranges_upper_bound.h b/lib/libcxx/include/__algorithm/ranges_upper_bound.h
index a12a0e39b0..7b571fb344 100644
--- a/lib/libcxx/include/__algorithm/ranges_upper_bound.h
+++ b/lib/libcxx/include/__algorithm/ranges_upper_bound.h
@@ -39,7 +39,7 @@ struct __fn {
indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter
operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
- auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) {
+ auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) -> bool {
return !std::invoke(__comp, __rhs, __lhs);
};
@@ -52,7 +52,7 @@ struct __fn {
indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
- auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) {
+ auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) -> bool {
return !std::invoke(__comp, __rhs, __lhs);
};
diff --git a/lib/libcxx/include/__algorithm/remove.h b/lib/libcxx/include/__algorithm/remove.h
index 533e41b54f..1498852c43 100644
--- a/lib/libcxx/include/__algorithm/remove.h
+++ b/lib/libcxx/include/__algorithm/remove.h
@@ -18,28 +18,29 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
-{
- __first = _VSTD::find(__first, __last, __value);
- if (__first != __last)
- {
- _ForwardIterator __i = __first;
- while (++__i != __last)
- {
- if (!(*__i == __value))
- {
- *__first = _VSTD::move(*__i);
- ++__first;
- }
- }
+remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
+ __first = std::find(__first, __last, __value);
+ if (__first != __last) {
+ _ForwardIterator __i = __first;
+ while (++__i != __last) {
+ if (!(*__i == __value)) {
+ *__first = std::move(*__i);
+ ++__first;
+ }
}
- return __first;
+ }
+ return __first;
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_REMOVE_H
diff --git a/lib/libcxx/include/__algorithm/remove_copy.h b/lib/libcxx/include/__algorithm/remove_copy.h
index ecba08a053..7be4c166ce 100644
--- a/lib/libcxx/include/__algorithm/remove_copy.h
+++ b/lib/libcxx/include/__algorithm/remove_copy.h
@@ -18,19 +18,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value)
-{
- for (; __first != __last; ++__first)
- {
- if (!(*__first == __value))
- {
- *__result = *__first;
- ++__result;
- }
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) {
+ for (; __first != __last; ++__first) {
+ if (!(*__first == __value)) {
+ *__result = *__first;
+ ++__result;
}
- return __result;
+ }
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/remove_copy_if.h b/lib/libcxx/include/__algorithm/remove_copy_if.h
index 2f235fd32f..dcafed1691 100644
--- a/lib/libcxx/include/__algorithm/remove_copy_if.h
+++ b/lib/libcxx/include/__algorithm/remove_copy_if.h
@@ -18,19 +18,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
-{
- for (; __first != __last; ++__first)
- {
- if (!__pred(*__first))
- {
- *__result = *__first;
- ++__result;
- }
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
+ for (; __first != __last; ++__first) {
+ if (!__pred(*__first)) {
+ *__result = *__first;
+ ++__result;
}
- return __result;
+ }
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/remove_if.h b/lib/libcxx/include/__algorithm/remove_if.h
index 27350728d2..c77b78023f 100644
--- a/lib/libcxx/include/__algorithm/remove_if.h
+++ b/lib/libcxx/include/__algorithm/remove_if.h
@@ -17,28 +17,29 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
-{
- __first = _VSTD::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
- if (__first != __last)
- {
- _ForwardIterator __i = __first;
- while (++__i != __last)
- {
- if (!__pred(*__i))
- {
- *__first = _VSTD::move(*__i);
- ++__first;
- }
- }
+remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
+ __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
+ if (__first != __last) {
+ _ForwardIterator __i = __first;
+ while (++__i != __last) {
+ if (!__pred(*__i)) {
+ *__first = std::move(*__i);
+ ++__first;
+ }
}
- return __first;
+ }
+ return __first;
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_REMOVE_IF_H
diff --git a/lib/libcxx/include/__algorithm/replace.h b/lib/libcxx/include/__algorithm/replace.h
index ce6215066f..8057c78686 100644
--- a/lib/libcxx/include/__algorithm/replace.h
+++ b/lib/libcxx/include/__algorithm/replace.h
@@ -18,13 +18,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value)
-{
- for (; __first != __last; ++__first)
- if (*__first == __old_value)
- *__first = __new_value;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) {
+ for (; __first != __last; ++__first)
+ if (*__first == __old_value)
+ *__first = __new_value;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/replace_copy.h b/lib/libcxx/include/__algorithm/replace_copy.h
index bebb14cbe2..9a2258d9f5 100644
--- a/lib/libcxx/include/__algorithm/replace_copy.h
+++ b/lib/libcxx/include/__algorithm/replace_copy.h
@@ -18,17 +18,18 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
- const _Tp& __old_value, const _Tp& __new_value)
-{
- for (; __first != __last; ++__first, (void) ++__result)
- if (*__first == __old_value)
- *__result = __new_value;
- else
- *__result = *__first;
- return __result;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _OutputIterator __result,
+ const _Tp& __old_value,
+ const _Tp& __new_value) {
+ for (; __first != __last; ++__first, (void)++__result)
+ if (*__first == __old_value)
+ *__result = __new_value;
+ else
+ *__result = *__first;
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/replace_copy_if.h b/lib/libcxx/include/__algorithm/replace_copy_if.h
index e1ddb527be..c2ed30f08d 100644
--- a/lib/libcxx/include/__algorithm/replace_copy_if.h
+++ b/lib/libcxx/include/__algorithm/replace_copy_if.h
@@ -18,17 +18,18 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
- _Predicate __pred, const _Tp& __new_value)
-{
- for (; __first != __last; ++__first, (void) ++__result)
- if (__pred(*__first))
- *__result = __new_value;
- else
- *__result = *__first;
- return __result;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy_if(
+ _InputIterator __first,
+ _InputIterator __last,
+ _OutputIterator __result,
+ _Predicate __pred,
+ const _Tp& __new_value) {
+ for (; __first != __last; ++__first, (void)++__result)
+ if (__pred(*__first))
+ *__result = __new_value;
+ else
+ *__result = *__first;
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/replace_if.h b/lib/libcxx/include/__algorithm/replace_if.h
index b3a3367d22..78487e3dee 100644
--- a/lib/libcxx/include/__algorithm/replace_if.h
+++ b/lib/libcxx/include/__algorithm/replace_if.h
@@ -18,13 +18,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Predicate, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value)
-{
- for (; __first != __last; ++__first)
- if (__pred(*__first))
- *__first = __new_value;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) {
+ for (; __first != __last; ++__first)
+ if (__pred(*__first))
+ *__first = __new_value;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/reverse.h b/lib/libcxx/include/__algorithm/reverse.h
index aa76951707..4167c9116d 100644
--- a/lib/libcxx/include/__algorithm/reverse.h
+++ b/lib/libcxx/include/__algorithm/reverse.h
@@ -19,47 +19,44 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _BidirectionalIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
-{
- while (__first != __last)
- {
- if (__first == --__last)
- break;
- _IterOps<_AlgPolicy>::iter_swap(__first, __last);
- ++__first;
- }
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) {
+ while (__first != __last) {
+ if (__first == --__last)
+ break;
+ _IterOps<_AlgPolicy>::iter_swap(__first, __last);
+ ++__first;
+ }
}
template <class _AlgPolicy, class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
-{
- if (__first != __last)
- for (; __first < --__last; ++__first)
- _IterOps<_AlgPolicy>::iter_swap(__first, __last);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) {
+ if (__first != __last)
+ for (; __first < --__last; ++__first)
+ _IterOps<_AlgPolicy>::iter_swap(__first, __last);
}
template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>;
std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory());
}
template <class _BidirectionalIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-void
-reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
-{
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) {
std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last));
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_REVERSE_H
diff --git a/lib/libcxx/include/__algorithm/reverse_copy.h b/lib/libcxx/include/__algorithm/reverse_copy.h
index f4a0e9713d..0fcecc3923 100644
--- a/lib/libcxx/include/__algorithm/reverse_copy.h
+++ b/lib/libcxx/include/__algorithm/reverse_copy.h
@@ -18,13 +18,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _BidirectionalIterator, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
-{
- for (; __first != __last; ++__result)
- *__result = *--__last;
- return __result;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) {
+ for (; __first != __last; ++__result)
+ *__result = *--__last;
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/rotate.h b/lib/libcxx/include/__algorithm/rotate.h
index 7ed6f18628..9a4d07883e 100644
--- a/lib/libcxx/include/__algorithm/rotate.h
+++ b/lib/libcxx/include/__algorithm/rotate.h
@@ -23,199 +23,176 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-__rotate_left(_ForwardIterator __first, _ForwardIterator __last)
-{
- typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- using _Ops = _IterOps<_AlgPolicy>;
-
- value_type __tmp = _Ops::__iter_move(__first);
- _ForwardIterator __lm1 = std::__move<_AlgPolicy>(
- _Ops::next(__first), __last, __first).second;
- *__lm1 = _VSTD::move(__tmp);
- return __lm1;
+__rotate_left(_ForwardIterator __first, _ForwardIterator __last) {
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ using _Ops = _IterOps<_AlgPolicy>;
+
+ value_type __tmp = _Ops::__iter_move(__first);
+ _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second;
+ *__lm1 = std::move(__tmp);
+ return __lm1;
}
template <class _AlgPolicy, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator
-__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
-{
- typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- using _Ops = _IterOps<_AlgPolicy>;
-
- _BidirectionalIterator __lm1 = _Ops::prev(__last);
- value_type __tmp = _Ops::__iter_move(__lm1);
- _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second;
- *__first = _VSTD::move(__tmp);
- return __fp1;
+__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) {
+ typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+ using _Ops = _IterOps<_AlgPolicy>;
+
+ _BidirectionalIterator __lm1 = _Ops::prev(__last);
+ value_type __tmp = _Ops::__iter_move(__lm1);
+ _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second;
+ *__first = std::move(__tmp);
+ return __fp1;
}
template <class _AlgPolicy, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _ForwardIterator
-__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
-{
- _ForwardIterator __i = __middle;
- while (true)
- {
- _IterOps<_AlgPolicy>::iter_swap(__first, __i);
- ++__first;
- if (++__i == __last)
- break;
+__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) {
+ _ForwardIterator __i = __middle;
+ while (true) {
+ _IterOps<_AlgPolicy>::iter_swap(__first, __i);
+ ++__first;
+ if (++__i == __last)
+ break;
+ if (__first == __middle)
+ __middle = __i;
+ }
+ _ForwardIterator __r = __first;
+ if (__first != __middle) {
+ __i = __middle;
+ while (true) {
+ _IterOps<_AlgPolicy>::iter_swap(__first, __i);
+ ++__first;
+ if (++__i == __last) {
if (__first == __middle)
- __middle = __i;
- }
- _ForwardIterator __r = __first;
- if (__first != __middle)
- {
+ break;
__i = __middle;
- while (true)
- {
- _IterOps<_AlgPolicy>::iter_swap(__first, __i);
- ++__first;
- if (++__i == __last)
- {
- if (__first == __middle)
- break;
- __i = __middle;
- }
- else if (__first == __middle)
- __middle = __i;
- }
+ } else if (__first == __middle)
+ __middle = __i;
}
- return __r;
+ }
+ return __r;
}
-template<typename _Integral>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_SINCE_CXX17 _Integral
-__algo_gcd(_Integral __x, _Integral __y)
-{
- do
- {
- _Integral __t = __x % __y;
- __x = __y;
- __y = __t;
- } while (__y);
- return __x;
+template <typename _Integral>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Integral __algo_gcd(_Integral __x, _Integral __y) {
+ do {
+ _Integral __t = __x % __y;
+ __x = __y;
+ __y = __t;
+ } while (__y);
+ return __x;
}
template <class _AlgPolicy, typename _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _RandomAccessIterator
-__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
-{
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
- using _Ops = _IterOps<_AlgPolicy>;
-
- const difference_type __m1 = __middle - __first;
- const difference_type __m2 = _Ops::distance(__middle, __last);
- if (__m1 == __m2)
- {
- std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last);
- return __middle;
- }
- const difference_type __g = _VSTD::__algo_gcd(__m1, __m2);
- for (_RandomAccessIterator __p = __first + __g; __p != __first;)
- {
- value_type __t(_Ops::__iter_move(--__p));
- _RandomAccessIterator __p1 = __p;
- _RandomAccessIterator __p2 = __p1 + __m1;
- do
- {
- *__p1 = _Ops::__iter_move(__p2);
- __p1 = __p2;
- const difference_type __d = _Ops::distance(__p2, __last);
- if (__m1 < __d)
- __p2 += __m1;
- else
- __p2 = __first + (__m1 - __d);
- } while (__p2 != __p);
- *__p1 = _VSTD::move(__t);
- }
- return __first + __m2;
+__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) {
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+ using _Ops = _IterOps<_AlgPolicy>;
+
+ const difference_type __m1 = __middle - __first;
+ const difference_type __m2 = _Ops::distance(__middle, __last);
+ if (__m1 == __m2) {
+ std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last);
+ return __middle;
+ }
+ const difference_type __g = std::__algo_gcd(__m1, __m2);
+ for (_RandomAccessIterator __p = __first + __g; __p != __first;) {
+ value_type __t(_Ops::__iter_move(--__p));
+ _RandomAccessIterator __p1 = __p;
+ _RandomAccessIterator __p2 = __p1 + __m1;
+ do {
+ *__p1 = _Ops::__iter_move(__p2);
+ __p1 = __p2;
+ const difference_type __d = _Ops::distance(__p2, __last);
+ if (__m1 < __d)
+ __p2 += __m1;
+ else
+ __p2 = __first + (__m1 - __d);
+ } while (__p2 != __p);
+ *__p1 = std::move(__t);
+ }
+ return __first + __m2;
}
template <class _AlgPolicy, class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
- _VSTD::forward_iterator_tag)
-{
- typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- if (is_trivially_move_assignable<value_type>::value)
- {
- if (_IterOps<_AlgPolicy>::next(__first) == __middle)
- return std::__rotate_left<_AlgPolicy>(__first, __last);
- }
- return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
+__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, std::forward_iterator_tag) {
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ if (is_trivially_move_assignable<value_type>::value) {
+ if (_IterOps<_AlgPolicy>::next(__first) == __middle)
+ return std::__rotate_left<_AlgPolicy>(__first, __last);
+ }
+ return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
template <class _AlgPolicy, class _BidirectionalIterator>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator
-__rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
- bidirectional_iterator_tag)
-{
- typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- if (is_trivially_move_assignable<value_type>::value)
- {
- if (_IterOps<_AlgPolicy>::next(__first) == __middle)
- return std::__rotate_left<_AlgPolicy>(__first, __last);
- if (_IterOps<_AlgPolicy>::next(__middle) == __last)
- return std::__rotate_right<_AlgPolicy>(__first, __last);
- }
- return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator __rotate_impl(
+ _BidirectionalIterator __first,
+ _BidirectionalIterator __middle,
+ _BidirectionalIterator __last,
+ bidirectional_iterator_tag) {
+ typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+ if (is_trivially_move_assignable<value_type>::value) {
+ if (_IterOps<_AlgPolicy>::next(__first) == __middle)
+ return std::__rotate_left<_AlgPolicy>(__first, __last);
+ if (_IterOps<_AlgPolicy>::next(__middle) == __last)
+ return std::__rotate_right<_AlgPolicy>(__first, __last);
+ }
+ return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
template <class _AlgPolicy, class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator
-__rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
- random_access_iterator_tag)
-{
- typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
- if (is_trivially_move_assignable<value_type>::value)
- {
- if (_IterOps<_AlgPolicy>::next(__first) == __middle)
- return std::__rotate_left<_AlgPolicy>(__first, __last);
- if (_IterOps<_AlgPolicy>::next(__middle) == __last)
- return std::__rotate_right<_AlgPolicy>(__first, __last);
- return std::__rotate_gcd<_AlgPolicy>(__first, __middle, __last);
- }
- return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __rotate_impl(
+ _RandomAccessIterator __first,
+ _RandomAccessIterator __middle,
+ _RandomAccessIterator __last,
+ random_access_iterator_tag) {
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+ if (is_trivially_move_assignable<value_type>::value) {
+ if (_IterOps<_AlgPolicy>::next(__first) == __middle)
+ return std::__rotate_left<_AlgPolicy>(__first, __last);
+ if (_IterOps<_AlgPolicy>::next(__middle) == __last)
+ return std::__rotate_right<_AlgPolicy>(__first, __last);
+ return std::__rotate_gcd<_AlgPolicy>(__first, __middle, __last);
+ }
+ return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
template <class _AlgPolicy, class _Iterator, class _Sentinel>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iterator, _Iterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iterator, _Iterator>
__rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) {
- using _Ret = pair<_Iterator, _Iterator>;
+ using _Ret = pair<_Iterator, _Iterator>;
_Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last);
if (__first == __middle)
- return _Ret(__last_iter, __last_iter);
+ return _Ret(__last_iter, __last_iter);
if (__middle == __last)
- return _Ret(std::move(__first), std::move(__last_iter));
+ return _Ret(std::move(__first), std::move(__last_iter));
using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>;
- auto __result = std::__rotate_impl<_AlgPolicy>(
- std::move(__first), std::move(__middle), __last_iter, _IterCategory());
+ auto __result = std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), __last_iter, _IterCategory());
return _Ret(std::move(__result), std::move(__last_iter));
}
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
-rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
-{
- return std::__rotate<_ClassicAlgPolicy>(
- std::move(__first), std::move(__middle), std::move(__last)).first;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) {
+ return std::__rotate<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)).first;
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_ROTATE_H
diff --git a/lib/libcxx/include/__algorithm/rotate_copy.h b/lib/libcxx/include/__algorithm/rotate_copy.h
index c154649ab9..cddcadd237 100644
--- a/lib/libcxx/include/__algorithm/rotate_copy.h
+++ b/lib/libcxx/include/__algorithm/rotate_copy.h
@@ -19,11 +19,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result)
-{
- return _VSTD::copy(__first, __middle, _VSTD::copy(__middle, __last, __result));
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) {
+ return std::copy(__first, __middle, std::copy(__middle, __last, __result));
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/sample.h b/lib/libcxx/include/__algorithm/sample.h
index c7a1898e53..ebe5180b7e 100644
--- a/lib/libcxx/include/__algorithm/sample.h
+++ b/lib/libcxx/include/__algorithm/sample.h
@@ -29,38 +29,45 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy,
- class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
+ class _PopulationIterator,
+ class _PopulationSentinel,
+ class _SampleIterator,
+ class _Distance,
class _UniformRandomNumberGenerator>
-_LIBCPP_INLINE_VISIBILITY
-_SampleIterator __sample(_PopulationIterator __first,
- _PopulationSentinel __last, _SampleIterator __output_iter,
- _Distance __n,
- _UniformRandomNumberGenerator& __g,
- input_iterator_tag) {
-
+_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
+ _PopulationIterator __first,
+ _PopulationSentinel __last,
+ _SampleIterator __output_iter,
+ _Distance __n,
+ _UniformRandomNumberGenerator& __g,
+ input_iterator_tag) {
_Distance __k = 0;
- for (; __first != __last && __k < __n; ++__first, (void) ++__k)
+ for (; __first != __last && __k < __n; ++__first, (void)++__k)
__output_iter[__k] = *__first;
_Distance __sz = __k;
- for (; __first != __last; ++__first, (void) ++__k) {
+ for (; __first != __last; ++__first, (void)++__k) {
_Distance __r = uniform_int_distribution<_Distance>(0, __k)(__g);
if (__r < __sz)
__output_iter[__r] = *__first;
}
- return __output_iter + _VSTD::min(__n, __k);
+ return __output_iter + std::min(__n, __k);
}
template <class _AlgPolicy,
- class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
+ class _PopulationIterator,
+ class _PopulationSentinel,
+ class _SampleIterator,
+ class _Distance,
class _UniformRandomNumberGenerator>
-_LIBCPP_INLINE_VISIBILITY
-_SampleIterator __sample(_PopulationIterator __first,
- _PopulationSentinel __last, _SampleIterator __output_iter,
- _Distance __n,
- _UniformRandomNumberGenerator& __g,
- forward_iterator_tag) {
+_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
+ _PopulationIterator __first,
+ _PopulationSentinel __last,
+ _SampleIterator __output_iter,
+ _Distance __n,
+ _UniformRandomNumberGenerator& __g,
+ forward_iterator_tag) {
_Distance __unsampled_sz = _IterOps<_AlgPolicy>::distance(__first, __last);
- for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) {
+ for (__n = std::min(__n, __unsampled_sz); __n != 0; ++__first) {
_Distance __r = uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g);
if (__r < __n) {
*__output_iter++ = *__first;
@@ -71,36 +78,40 @@ _SampleIterator __sample(_PopulationIterator __first,
}
template <class _AlgPolicy,
- class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
+ class _PopulationIterator,
+ class _PopulationSentinel,
+ class _SampleIterator,
+ class _Distance,
class _UniformRandomNumberGenerator>
-_LIBCPP_INLINE_VISIBILITY
-_SampleIterator __sample(_PopulationIterator __first,
- _PopulationSentinel __last, _SampleIterator __output_iter,
- _Distance __n, _UniformRandomNumberGenerator& __g) {
- _LIBCPP_ASSERT_UNCATEGORIZED(__n >= 0, "N must be a positive number.");
+_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
+ _PopulationIterator __first,
+ _PopulationSentinel __last,
+ _SampleIterator __output_iter,
+ _Distance __n,
+ _UniformRandomNumberGenerator& __g) {
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "N must be a positive number.");
using _PopIterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_PopulationIterator>;
- using _Difference = typename _IterOps<_AlgPolicy>::template __difference_type<_PopulationIterator>;
- using _CommonType = typename common_type<_Distance, _Difference>::type;
+ using _Difference = typename _IterOps<_AlgPolicy>::template __difference_type<_PopulationIterator>;
+ using _CommonType = typename common_type<_Distance, _Difference>::type;
return std::__sample<_AlgPolicy>(
- std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n),
- __g, _PopIterCategory());
+ std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n), __g, _PopIterCategory());
}
#if _LIBCPP_STD_VER >= 17
-template <class _PopulationIterator, class _SampleIterator, class _Distance,
- class _UniformRandomNumberGenerator>
-inline _LIBCPP_INLINE_VISIBILITY
-_SampleIterator sample(_PopulationIterator __first,
- _PopulationIterator __last, _SampleIterator __output_iter,
- _Distance __n, _UniformRandomNumberGenerator&& __g) {
+template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
+inline _LIBCPP_HIDE_FROM_ABI _SampleIterator
+sample(_PopulationIterator __first,
+ _PopulationIterator __last,
+ _SampleIterator __output_iter,
+ _Distance __n,
+ _UniformRandomNumberGenerator&& __g) {
static_assert(__has_forward_iterator_category<_PopulationIterator>::value ||
- __has_random_access_iterator_category<_SampleIterator>::value,
+ __has_random_access_iterator_category<_SampleIterator>::value,
"SampleIterator must meet the requirements of RandomAccessIterator");
- return std::__sample<_ClassicAlgPolicy>(
- std::move(__first), std::move(__last), std::move(__output_iter), __n, __g);
+ return std::__sample<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__output_iter), __n, __g);
}
#endif // _LIBCPP_STD_VER >= 17
diff --git a/lib/libcxx/include/__algorithm/search.h b/lib/libcxx/include/__algorithm/search.h
index 5882a04808..75f936d0f2 100644
--- a/lib/libcxx/include/__algorithm/search.h
+++ b/lib/libcxx/include/__algorithm/search.h
@@ -29,17 +29,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy,
- class _Iter1, class _Sent1,
- class _Iter2, class _Sent2,
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
class _Pred,
class _Proj1,
class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
- _Iter2 __first2, _Sent2 __last2,
- _Pred& __pred,
- _Proj1& __proj1,
- _Proj2& __proj2) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_forward_impl(
+ _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
if (__first2 == __last2)
return std::make_pair(__first1, __first1); // Everything matches an empty sequence
while (true) {
@@ -64,8 +62,7 @@ pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
}
// if there is a mismatch, restart with a new __first1
- if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2)))
- {
+ if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
++__first1;
break;
} // else there is a match, check next elements
@@ -74,21 +71,25 @@ pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
}
template <class _AlgPolicy,
- class _Iter1, class _Sent1,
- class _Iter2, class _Sent2,
+ class _Iter1,
+ class _Sent1,
+ class _Iter2,
+ class _Sent2,
class _Pred,
class _Proj1,
class _Proj2,
class _DiffT1,
class _DiffT2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1,
- _Iter2 __first2, _Sent2 __last2,
- _Pred& __pred,
- _Proj1& __proj1,
- _Proj2& __proj2,
- _DiffT1 __size1,
- _DiffT2 __size2) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_random_access_impl(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2,
+ _DiffT1 __size1,
+ _DiffT2 __size2) {
const _Iter1 __s = __first1 + __size1 - _DiffT1(__size2 - 1); // Start of pattern match can't go beyond here
while (true) {
@@ -116,20 +117,17 @@ pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1
}
}
-template <class _Iter1, class _Sent1,
- class _Iter2, class _Sent2,
- class _Pred,
- class _Proj1,
- class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
- _Iter2 __first2, _Sent2 __last2,
- _Pred& __pred,
- _Proj1& __proj1,
- _Proj2& __proj2,
- __enable_if_t<__has_random_access_iterator_category<_Iter1>::value
- && __has_random_access_iterator_category<_Iter2>::value>* = nullptr) {
-
+template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2,
+ __enable_if_t<__has_random_access_iterator_category<_Iter1>::value &&
+ __has_random_access_iterator_category<_Iter2>::value>* = nullptr) {
auto __size2 = __last2 - __first2;
if (__size2 == 0)
return std::make_pair(__first1, __first1);
@@ -139,42 +137,32 @@ pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
return std::make_pair(__last1, __last1);
}
- return std::__search_random_access_impl<_ClassicAlgPolicy>(__first1, __last1,
- __first2, __last2,
- __pred,
- __proj1,
- __proj2,
- __size1,
- __size2);
+ return std::__search_random_access_impl<_ClassicAlgPolicy>(
+ __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2);
}
-template <class _Iter1, class _Sent1,
- class _Iter2, class _Sent2,
- class _Pred,
- class _Proj1,
- class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
- _Iter2 __first2, _Sent2 __last2,
- _Pred& __pred,
- _Proj1& __proj1,
- _Proj2& __proj2,
- __enable_if_t<__has_forward_iterator_category<_Iter1>::value
- && __has_forward_iterator_category<_Iter2>::value
- && !(__has_random_access_iterator_category<_Iter1>::value
- && __has_random_access_iterator_category<_Iter2>::value)>* = nullptr) {
- return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1,
- __first2, __last2,
- __pred,
- __proj1,
- __proj2);
+template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred& __pred,
+ _Proj1& __proj1,
+ _Proj2& __proj2,
+ __enable_if_t<__has_forward_iterator_category<_Iter1>::value && __has_forward_iterator_category<_Iter2>::value &&
+ !(__has_random_access_iterator_category<_Iter1>::value &&
+ __has_random_access_iterator_category<_Iter2>::value)>* = nullptr) {
+ return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2,
- _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
+search(_ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be callable");
auto __proj = __identity();
@@ -182,15 +170,14 @@ _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
}
template <class _ForwardIterator1, class _ForwardIterator2>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
+search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
return std::search(__first1, __last1, __first2, __last2, __equal_to());
}
#if _LIBCPP_STD_VER >= 17
template <class _ForwardIterator, class _Searcher>
-_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s) {
return __s(__f, __l).first;
}
diff --git a/lib/libcxx/include/__algorithm/search_n.h b/lib/libcxx/include/__algorithm/search_n.h
index 7e3ddf48a2..c3c01e700b 100644
--- a/lib/libcxx/include/__algorithm/search_n.h
+++ b/lib/libcxx/include/__algorithm/search_n.h
@@ -31,12 +31,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
- _SizeT __count,
- const _Type& __value,
- _Pred& __pred,
- _Proj& __proj) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_forward_impl(
+ _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) {
if (__count <= 0)
return std::make_pair(__first, __first);
while (true) {
@@ -62,8 +58,7 @@ pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
}
// if there is a mismatch, restart with a new __first
- if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value))
- {
+ if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) {
__first = __m;
++__first;
break;
@@ -73,13 +68,8 @@ pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
}
template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj, class _DiffT>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __last,
- _SizeT __count,
- const _Type& __value,
- _Pred& __pred,
- _Proj& __proj,
- _DiffT __size1) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __search_n_random_access_impl(
+ _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj, _DiffT __size1) {
using difference_type = typename iterator_traits<_Iter>::difference_type;
if (__count == 0)
return std::make_pair(__first, __first);
@@ -109,8 +99,7 @@ std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __las
++__m; // no need to check range on __m because __s guarantees we have enough source
// if there is a mismatch, restart with a new __first
- if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value))
- {
+ if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) {
__first = __m;
++__first;
break;
@@ -119,61 +108,44 @@ std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __las
}
}
-template <class _Iter, class _Sent,
- class _DiffT,
- class _Type,
- class _Pred,
- class _Proj>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter, _Iter> __search_n_impl(_Iter __first, _Sent __last,
- _DiffT __count,
- const _Type& __value,
- _Pred& __pred,
- _Proj& __proj,
- __enable_if_t<__has_random_access_iterator_category<_Iter>::value>* = nullptr) {
- return std::__search_n_random_access_impl<_ClassicAlgPolicy>(__first, __last,
- __count,
- __value,
- __pred,
- __proj,
- __last - __first);
+template <class _Iter, class _Sent, class _DiffT, class _Type, class _Pred, class _Proj>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_impl(
+ _Iter __first,
+ _Sent __last,
+ _DiffT __count,
+ const _Type& __value,
+ _Pred& __pred,
+ _Proj& __proj,
+ __enable_if_t<__has_random_access_iterator_category<_Iter>::value>* = nullptr) {
+ return std::__search_n_random_access_impl<_ClassicAlgPolicy>(
+ __first, __last, __count, __value, __pred, __proj, __last - __first);
}
-template <class _Iter1, class _Sent1,
- class _DiffT,
- class _Type,
- class _Pred,
- class _Proj>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter1, _Iter1> __search_n_impl(_Iter1 __first, _Sent1 __last,
- _DiffT __count,
- const _Type& __value,
- _Pred& __pred,
- _Proj& __proj,
- __enable_if_t<__has_forward_iterator_category<_Iter1>::value
- && !__has_random_access_iterator_category<_Iter1>::value>* = nullptr) {
- return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last,
- __count,
- __value,
- __pred,
- __proj);
+template <class _Iter1, class _Sent1, class _DiffT, class _Type, class _Pred, class _Proj>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_n_impl(
+ _Iter1 __first,
+ _Sent1 __last,
+ _DiffT __count,
+ const _Type& __value,
+ _Pred& __pred,
+ _Proj& __proj,
+ __enable_if_t<__has_forward_iterator_category<_Iter1>::value &&
+ !__has_random_access_iterator_category<_Iter1>::value>* = nullptr) {
+ return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last, __count, __value, __pred, __proj);
}
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last,
- _Size __count,
- const _Tp& __value,
- _BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
- "BinaryPredicate has to be callable");
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(
+ _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) {
+ static_assert(
+ __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable");
auto __proj = __identity();
return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
}
template <class _ForwardIterator, class _Size, class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) {
return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to());
}
diff --git a/lib/libcxx/include/__algorithm/set_difference.h b/lib/libcxx/include/__algorithm/set_difference.h
index 26a300092c..f414bcecb5 100644
--- a/lib/libcxx/include/__algorithm/set_difference.h
+++ b/lib/libcxx/include/__algorithm/set_difference.h
@@ -25,6 +25,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
@@ -55,7 +58,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d
_OutputIterator __result,
_Compare __comp) {
return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
- __first1, __last1, __first2, __last2, __result, __comp)
+ __first1, __last1, __first2, __last2, __result, __comp)
.second;
}
@@ -71,4 +74,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
diff --git a/lib/libcxx/include/__algorithm/set_intersection.h b/lib/libcxx/include/__algorithm/set_intersection.h
index f2603fe136..73d888d1b0 100644
--- a/lib/libcxx/include/__algorithm/set_intersection.h
+++ b/lib/libcxx/include/__algorithm/set_intersection.h
@@ -21,6 +21,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InIter1, class _InIter2, class _OutIter>
@@ -95,4 +98,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_i
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SET_INTERSECTION_H
diff --git a/lib/libcxx/include/__algorithm/set_symmetric_difference.h b/lib/libcxx/include/__algorithm/set_symmetric_difference.h
index 832c3979bf..db36665a61 100644
--- a/lib/libcxx/include/__algorithm/set_symmetric_difference.h
+++ b/lib/libcxx/include/__algorithm/set_symmetric_difference.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InIter1, class _InIter2, class _OutIter>
@@ -101,4 +104,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetri
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
diff --git a/lib/libcxx/include/__algorithm/set_union.h b/lib/libcxx/include/__algorithm/set_union.h
index cf48adae03..a79c50fd3c 100644
--- a/lib/libcxx/include/__algorithm/set_union.h
+++ b/lib/libcxx/include/__algorithm/set_union.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InIter1, class _InIter2, class _OutIter>
@@ -97,4 +100,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SET_UNION_H
diff --git a/lib/libcxx/include/__algorithm/shift_left.h b/lib/libcxx/include/__algorithm/shift_left.h
index 023b56dcfc..06cd7c5f87 100644
--- a/lib/libcxx/include/__algorithm/shift_left.h
+++ b/lib/libcxx/include/__algorithm/shift_left.h
@@ -17,39 +17,43 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY constexpr
-_ForwardIterator
-shift_left(_ForwardIterator __first, _ForwardIterator __last,
- typename iterator_traits<_ForwardIterator>::difference_type __n)
-{
- if (__n == 0) {
- return __last;
+inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
+shift_left(_ForwardIterator __first,
+ _ForwardIterator __last,
+ typename iterator_traits<_ForwardIterator>::difference_type __n) {
+ if (__n == 0) {
+ return __last;
+ }
+
+ _ForwardIterator __m = __first;
+ if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
+ if (__n >= __last - __first) {
+ return __first;
}
-
- _ForwardIterator __m = __first;
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
- if (__n >= __last - __first) {
- return __first;
- }
- __m += __n;
- } else {
- for (; __n > 0; --__n) {
- if (__m == __last) {
- return __first;
- }
- ++__m;
- }
+ __m += __n;
+ } else {
+ for (; __n > 0; --__n) {
+ if (__m == __last) {
+ return __first;
+ }
+ ++__m;
}
- return _VSTD::move(__m, __last, __first);
+ }
+ return std::move(__m, __last, __first);
}
#endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H
diff --git a/lib/libcxx/include/__algorithm/shift_right.h b/lib/libcxx/include/__algorithm/shift_right.h
index 70aff45fe5..01853057fc 100644
--- a/lib/libcxx/include/__algorithm/shift_right.h
+++ b/lib/libcxx/include/__algorithm/shift_right.h
@@ -20,82 +20,86 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY constexpr
-_ForwardIterator
-shift_right(_ForwardIterator __first, _ForwardIterator __last,
- typename iterator_traits<_ForwardIterator>::difference_type __n)
-{
- if (__n == 0) {
- return __first;
- }
+inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
+shift_right(_ForwardIterator __first,
+ _ForwardIterator __last,
+ typename iterator_traits<_ForwardIterator>::difference_type __n) {
+ if (__n == 0) {
+ return __first;
+ }
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
- decltype(__n) __d = __last - __first;
- if (__n >= __d) {
- return __last;
- }
- _ForwardIterator __m = __first + (__d - __n);
- return _VSTD::move_backward(__first, __m, __last);
- } else if constexpr (__has_bidirectional_iterator_category<_ForwardIterator>::value) {
- _ForwardIterator __m = __last;
- for (; __n > 0; --__n) {
- if (__m == __first) {
- return __last;
- }
- --__m;
- }
- return _VSTD::move_backward(__first, __m, __last);
- } else {
- _ForwardIterator __ret = __first;
- for (; __n > 0; --__n) {
- if (__ret == __last) {
- return __last;
- }
- ++__ret;
- }
+ if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
+ decltype(__n) __d = __last - __first;
+ if (__n >= __d) {
+ return __last;
+ }
+ _ForwardIterator __m = __first + (__d - __n);
+ return std::move_backward(__first, __m, __last);
+ } else if constexpr (__has_bidirectional_iterator_category<_ForwardIterator>::value) {
+ _ForwardIterator __m = __last;
+ for (; __n > 0; --__n) {
+ if (__m == __first) {
+ return __last;
+ }
+ --__m;
+ }
+ return std::move_backward(__first, __m, __last);
+ } else {
+ _ForwardIterator __ret = __first;
+ for (; __n > 0; --__n) {
+ if (__ret == __last) {
+ return __last;
+ }
+ ++__ret;
+ }
- // We have an __n-element scratch space from __first to __ret.
- // Slide an __n-element window [__trail, __lead) from left to right.
- // We're essentially doing swap_ranges(__first, __ret, __trail, __lead)
- // over and over; but once __lead reaches __last we needn't bother
- // to save the values of elements [__trail, __last).
+ // We have an __n-element scratch space from __first to __ret.
+ // Slide an __n-element window [__trail, __lead) from left to right.
+ // We're essentially doing swap_ranges(__first, __ret, __trail, __lead)
+ // over and over; but once __lead reaches __last we needn't bother
+ // to save the values of elements [__trail, __last).
- auto __trail = __first;
- auto __lead = __ret;
- while (__trail != __ret) {
- if (__lead == __last) {
- _VSTD::move(__first, __trail, __ret);
- return __ret;
- }
- ++__trail;
- ++__lead;
- }
+ auto __trail = __first;
+ auto __lead = __ret;
+ while (__trail != __ret) {
+ if (__lead == __last) {
+ std::move(__first, __trail, __ret);
+ return __ret;
+ }
+ ++__trail;
+ ++__lead;
+ }
- _ForwardIterator __mid = __first;
- while (true) {
- if (__lead == __last) {
- __trail = _VSTD::move(__mid, __ret, __trail);
- _VSTD::move(__first, __mid, __trail);
- return __ret;
- }
- swap(*__mid, *__trail);
- ++__mid;
- ++__trail;
- ++__lead;
- if (__mid == __ret) {
- __mid = __first;
- }
- }
+ _ForwardIterator __mid = __first;
+ while (true) {
+ if (__lead == __last) {
+ __trail = std::move(__mid, __ret, __trail);
+ std::move(__first, __mid, __trail);
+ return __ret;
+ }
+ swap(*__mid, *__trail);
+ ++__mid;
+ ++__trail;
+ ++__lead;
+ if (__mid == __ret) {
+ __mid = __first;
+ }
}
+ }
}
#endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
diff --git a/lib/libcxx/include/__algorithm/shuffle.h b/lib/libcxx/include/__algorithm/shuffle.h
index 6fee88ca6f..c9c56ce8c2 100644
--- a/lib/libcxx/include/__algorithm/shuffle.h
+++ b/lib/libcxx/include/__algorithm/shuffle.h
@@ -32,8 +32,8 @@ class _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_randomizer {
public:
_LIBCPP_HIDE_FROM_ABI __libcpp_debug_randomizer() {
__state_ = __seed();
- __inc_ = __state_ + 0xda3e39cb94b95bdbULL;
- __inc_ = (__inc_ << 1) | 1;
+ __inc_ = __state_ + 0xda3e39cb94b95bdbULL;
+ __inc_ = (__inc_ << 1) | 1;
}
typedef uint_fast32_t result_type;
@@ -42,7 +42,7 @@ public:
_LIBCPP_HIDE_FROM_ABI result_type operator()() {
uint_fast64_t __oldstate = __state_;
- __state_ = __oldstate * 6364136223846793005ULL + __inc_;
+ __state_ = __oldstate * 6364136223846793005ULL + __inc_;
return __oldstate >> 32;
}
@@ -62,102 +62,95 @@ private:
}
};
-#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
- || defined(_LIBCPP_BUILDING_LIBRARY)
+#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) || defined(_LIBCPP_BUILDING_LIBRARY)
class _LIBCPP_EXPORTED_FROM_ABI __rs_default;
_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
-class _LIBCPP_EXPORTED_FROM_ABI __rs_default
-{
- static unsigned __c_;
+class _LIBCPP_EXPORTED_FROM_ABI __rs_default {
+ static unsigned __c_;
+
+ __rs_default();
- __rs_default();
public:
- typedef uint_fast32_t result_type;
+ typedef uint_fast32_t result_type;
- static const result_type _Min = 0;
- static const result_type _Max = 0xFFFFFFFF;
+ static const result_type _Min = 0;
+ static const result_type _Max = 0xFFFFFFFF;
- __rs_default(const __rs_default&);
- ~__rs_default();
+ __rs_default(const __rs_default&);
+ ~__rs_default();
- result_type operator()();
+ result_type operator()();
- static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() {return _Min;}
- static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() {return _Max;}
+ static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+ static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; }
- friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
+ friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
};
_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
template <class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
-random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
-{
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- typedef uniform_int_distribution<ptrdiff_t> _Dp;
- typedef typename _Dp::param_type _Pp;
- difference_type __d = __last - __first;
- if (__d > 1)
- {
- _Dp __uid;
- __rs_default __g = __rs_get();
- for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
- {
- difference_type __i = __uid(__g, _Pp(0, __d));
- if (__i != difference_type(0))
- swap(*__first, *(__first + __i));
- }
+random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ typedef uniform_int_distribution<ptrdiff_t> _Dp;
+ typedef typename _Dp::param_type _Pp;
+ difference_type __d = __last - __first;
+ if (__d > 1) {
+ _Dp __uid;
+ __rs_default __g = __rs_get();
+ for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) {
+ difference_type __i = __uid(__g, _Pp(0, __d));
+ if (__i != difference_type(0))
+ swap(*__first, *(__first + __i));
}
+ }
}
template <class _RandomAccessIterator, class _RandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
-random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
-#ifndef _LIBCPP_CXX03_LANG
+random_shuffle(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+# ifndef _LIBCPP_CXX03_LANG
_RandomNumberGenerator&& __rand)
-#else
+# else
_RandomNumberGenerator& __rand)
-#endif
+# endif
{
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- difference_type __d = __last - __first;
- if (__d > 1)
- {
- for (--__last; __first < __last; ++__first, (void) --__d)
- {
- difference_type __i = __rand(__d);
- if (__i != difference_type(0))
- swap(*__first, *(__first + __i));
- }
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ difference_type __d = __last - __first;
+ if (__d > 1) {
+ for (--__last; __first < __last; ++__first, (void)--__d) {
+ difference_type __i = __rand(__d);
+ if (__i != difference_type(0))
+ swap(*__first, *(__first + __i));
}
+ }
}
#endif
template <class _AlgPolicy, class _RandomAccessIterator, class _Sentinel, class _UniformRandomNumberGenerator>
-_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __shuffle(
- _RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) {
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- typedef uniform_int_distribution<ptrdiff_t> _Dp;
- typedef typename _Dp::param_type _Pp;
-
- auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel);
- auto __last = __original_last;
- difference_type __d = __last - __first;
- if (__d > 1)
- {
- _Dp __uid;
- for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
- {
- difference_type __i = __uid(__g, _Pp(0, __d));
- if (__i != difference_type(0))
- _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i);
- }
+_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator
+__shuffle(_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) {
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ typedef uniform_int_distribution<ptrdiff_t> _Dp;
+ typedef typename _Dp::param_type _Pp;
+
+ auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel);
+ auto __last = __original_last;
+ difference_type __d = __last - __first;
+ if (__d > 1) {
+ _Dp __uid;
+ for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) {
+ difference_type __i = __uid(__g, _Pp(0, __d));
+ if (__i != difference_type(0))
+ _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i);
}
+ }
- return __original_last;
+ return __original_last;
}
template <class _RandomAccessIterator, class _UniformRandomNumberGenerator>
diff --git a/lib/libcxx/include/__algorithm/sift_down.h b/lib/libcxx/include/__algorithm/sift_down.h
index 20f0b0275d..42803e3063 100644
--- a/lib/libcxx/include/__algorithm/sift_down.h
+++ b/lib/libcxx/include/__algorithm/sift_down.h
@@ -26,90 +26,89 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
-__sift_down(_RandomAccessIterator __first, _Compare&& __comp,
+__sift_down(_RandomAccessIterator __first,
+ _Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
- _RandomAccessIterator __start)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+ _RandomAccessIterator __start) {
+ using _Ops = _IterOps<_AlgPolicy>;
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
- // left-child of __start is at 2 * __start + 1
- // right-child of __start is at 2 * __start + 2
- difference_type __child = __start - __first;
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+ // left-child of __start is at 2 * __start + 1
+ // right-child of __start is at 2 * __start + 2
+ difference_type __child = __start - __first;
- if (__len < 2 || (__len - 2) / 2 < __child)
- return;
+ if (__len < 2 || (__len - 2) / 2 < __child)
+ return;
- __child = 2 * __child + 1;
- _RandomAccessIterator __child_i = __first + __child;
+ __child = 2 * __child + 1;
+ _RandomAccessIterator __child_i = __first + __child;
+
+ if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
+ // right-child exists and is greater than left-child
+ ++__child_i;
+ ++__child;
+ }
+
+ // check if we are in heap-order
+ if (__comp(*__child_i, *__start))
+ // we are, __start is larger than its largest child
+ return;
+
+ value_type __top(_Ops::__iter_move(__start));
+ do {
+ // we are not in heap-order, swap the parent with its largest child
+ *__start = _Ops::__iter_move(__child_i);
+ __start = __child_i;
+
+ if ((__len - 2) / 2 < __child)
+ break;
+
+ // recompute the child based off of the updated parent
+ __child = 2 * __child + 1;
+ __child_i = __first + __child;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
- // right-child exists and is greater than left-child
- ++__child_i;
- ++__child;
+ // right-child exists and is greater than left-child
+ ++__child_i;
+ ++__child;
}
// check if we are in heap-order
- if (__comp(*__child_i, *__start))
- // we are, __start is larger than its largest child
- return;
-
- value_type __top(_Ops::__iter_move(__start));
- do
- {
- // we are not in heap-order, swap the parent with its largest child
- *__start = _Ops::__iter_move(__child_i);
- __start = __child_i;
-
- if ((__len - 2) / 2 < __child)
- break;
-
- // recompute the child based off of the updated parent
- __child = 2 * __child + 1;
- __child_i = __first + __child;
-
- if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
- // right-child exists and is greater than left-child
- ++__child_i;
- ++__child;
- }
-
- // check if we are in heap-order
- } while (!__comp(*__child_i, __top));
- *__start = _VSTD::move(__top);
+ } while (!__comp(*__child_i, __top));
+ *__start = std::move(__top);
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator
-__floyd_sift_down(_RandomAccessIterator __first, _Compare&& __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len)
-{
- using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
- _LIBCPP_ASSERT_UNCATEGORIZED(__len >= 2, "shouldn't be called unless __len >= 2");
-
- _RandomAccessIterator __hole = __first;
- _RandomAccessIterator __child_i = __first;
- difference_type __child = 0;
-
- while (true) {
- __child_i += difference_type(__child + 1);
- __child = 2 * __child + 1;
-
- if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
- // right-child exists and is greater than left-child
- ++__child_i;
- ++__child;
- }
-
- // swap __hole with its largest child
- *__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i);
- __hole = __child_i;
-
- // if __hole is now a leaf, we're done
- if (__child > (__len - 2) / 2)
- return __hole;
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __floyd_sift_down(
+ _RandomAccessIterator __first,
+ _Compare&& __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
+ using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
+ _LIBCPP_ASSERT_INTERNAL(__len >= 2, "shouldn't be called unless __len >= 2");
+
+ _RandomAccessIterator __hole = __first;
+ _RandomAccessIterator __child_i = __first;
+ difference_type __child = 0;
+
+ while (true) {
+ __child_i += difference_type(__child + 1);
+ __child = 2 * __child + 1;
+
+ if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
+ // right-child exists and is greater than left-child
+ ++__child_i;
+ ++__child;
}
+
+ // swap __hole with its largest child
+ *__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i);
+ __hole = __child_i;
+
+ // if __hole is now a leaf, we're done
+ if (__child > (__len - 2) / 2)
+ return __hole;
+ }
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/sort.h b/lib/libcxx/include/__algorithm/sort.h
index 3b594fa4d2..8a5e0211cd 100644
--- a/lib/libcxx/include/__algorithm/sort.h
+++ b/lib/libcxx/include/__algorithm/sort.h
@@ -39,54 +39,55 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// stable, 2-3 compares, 0-2 swaps
template <class _AlgPolicy, class _Compare, class _ForwardIterator>
-_LIBCPP_HIDE_FROM_ABI
-_LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z,
- _Compare __c) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned
+__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) {
using _Ops = _IterOps<_AlgPolicy>;
unsigned __r = 0;
- if (!__c(*__y, *__x)) // if x <= y
+ if (!__c(*__y, *__x)) // if x <= y
{
- if (!__c(*__z, *__y)) // if y <= z
- return __r; // x <= y && y <= z
- // x <= y && y > z
- _Ops::iter_swap(__y, __z); // x <= z && y < z
+ if (!__c(*__z, *__y)) // if y <= z
+ return __r; // x <= y && y <= z
+ // x <= y && y > z
+ _Ops::iter_swap(__y, __z); // x <= z && y < z
__r = 1;
- if (__c(*__y, *__x)) // if x > y
+ if (__c(*__y, *__x)) // if x > y
{
- _Ops::iter_swap(__x, __y); // x < y && y <= z
+ _Ops::iter_swap(__x, __y); // x < y && y <= z
__r = 2;
}
- return __r; // x <= y && y < z
+ return __r; // x <= y && y < z
}
- if (__c(*__z, *__y)) // x > y, if y > z
+ if (__c(*__z, *__y)) // x > y, if y > z
{
- _Ops::iter_swap(__x, __z); // x < y && y < z
+ _Ops::iter_swap(__x, __z); // x < y && y < z
__r = 1;
return __r;
}
- _Ops::iter_swap(__x, __y); // x > y && y <= z
- __r = 1; // x < y && x <= z
- if (__c(*__z, *__y)) // if y > z
+ _Ops::iter_swap(__x, __y); // x > y && y <= z
+ __r = 1; // x < y && x <= z
+ if (__c(*__z, *__y)) // if y > z
{
- _Ops::iter_swap(__y, __z); // x <= y && y < z
+ _Ops::iter_swap(__y, __z); // x <= y && y < z
__r = 2;
}
return __r;
-} // x <= y && y <= z
+} // x <= y && y <= z
// stable, 3-6 compares, 0-5 swaps
template <class _AlgPolicy, class _Compare, class _ForwardIterator>
-_LIBCPP_HIDE_FROM_ABI
-void __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4,
- _Compare __c) {
- using _Ops = _IterOps<_AlgPolicy>;
+_LIBCPP_HIDE_FROM_ABI void
+__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) {
+ using _Ops = _IterOps<_AlgPolicy>;
std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
if (__c(*__x4, *__x3)) {
_Ops::iter_swap(__x3, __x4);
@@ -102,8 +103,13 @@ void __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3
// stable, 4-10 compares, 0-9 swaps
template <class _AlgPolicy, class _Comp, class _ForwardIterator>
-_LIBCPP_HIDE_FROM_ABI void __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
- _ForwardIterator __x4, _ForwardIterator __x5, _Comp __comp) {
+_LIBCPP_HIDE_FROM_ABI void
+__sort5(_ForwardIterator __x1,
+ _ForwardIterator __x2,
+ _ForwardIterator __x3,
+ _ForwardIterator __x4,
+ _ForwardIterator __x5,
+ _Comp __comp) {
using _Ops = _IterOps<_AlgPolicy>;
std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp);
@@ -139,8 +145,9 @@ struct __is_simple_comparator<ranges::greater&> : true_type {};
template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
using __use_branchless_sort =
- integral_constant<bool, __libcpp_is_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) &&
- is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>;
+ integral_constant<bool,
+ __libcpp_is_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) &&
+ is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>;
namespace __detail {
@@ -154,46 +161,56 @@ template <class _Compare, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) {
// Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
- bool __r = __c(*__x, *__y);
+ bool __r = __c(*__x, *__y);
value_type __tmp = __r ? *__x : *__y;
- *__y = __r ? *__y : *__x;
- *__x = __tmp;
+ *__y = __r ? *__y : *__x;
+ *__x = __tmp;
}
// Ensures that *__x, *__y and *__z are ordered according to the comparator __c,
// under the assumption that *__y and *__z are already ordered.
template <class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI void __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y,
- _RandomAccessIterator __z, _Compare __c) {
+inline _LIBCPP_HIDE_FROM_ABI void
+__partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) {
// Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
- bool __r = __c(*__z, *__x);
+ bool __r = __c(*__z, *__x);
value_type __tmp = __r ? *__z : *__x;
- *__z = __r ? *__x : *__z;
- __r = __c(__tmp, *__y);
- *__x = __r ? *__x : *__y;
- *__y = __r ? *__y : __tmp;
+ *__z = __r ? *__x : *__z;
+ __r = __c(__tmp, *__y);
+ *__x = __r ? *__x : *__y;
+ *__y = __r ? *__y : __tmp;
}
-template <class, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
- _Compare __c) {
+template <class,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
+ _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
std::__cond_swap<_Compare>(__x2, __x3, __c);
std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c);
}
-template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
- _Compare __c) {
+template <class _AlgPolicy,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
+ _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
}
-template <class, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
- _RandomAccessIterator __x4, _Compare __c) {
+template <class,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
+ _RandomAccessIterator __x1,
+ _RandomAccessIterator __x2,
+ _RandomAccessIterator __x3,
+ _RandomAccessIterator __x4,
+ _Compare __c) {
std::__cond_swap<_Compare>(__x1, __x3, __c);
std::__cond_swap<_Compare>(__x2, __x4, __c);
std::__cond_swap<_Compare>(__x1, __x2, __c);
@@ -201,16 +218,24 @@ __sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2,
std::__cond_swap<_Compare>(__x2, __x3, __c);
}
-template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
- _RandomAccessIterator __x4, _Compare __c) {
+template <class _AlgPolicy,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
+ _RandomAccessIterator __x1,
+ _RandomAccessIterator __x2,
+ _RandomAccessIterator __x3,
+ _RandomAccessIterator __x4,
+ _Compare __c) {
std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c);
}
-template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort5_maybe_branchless(
+template <class _AlgPolicy,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
_RandomAccessIterator __x1,
_RandomAccessIterator __x2,
_RandomAccessIterator __x3,
@@ -225,19 +250,25 @@ __sort5_maybe_branchless(
std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c);
}
-template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
-__sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
- _RandomAccessIterator __x4, _RandomAccessIterator __x5, _Compare __c) {
+template <class _AlgPolicy,
+ class _Compare,
+ class _RandomAccessIterator,
+ __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
+ _RandomAccessIterator __x1,
+ _RandomAccessIterator __x2,
+ _RandomAccessIterator __x3,
+ _RandomAccessIterator __x4,
+ _RandomAccessIterator __x5,
+ _Compare __c) {
std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>(
std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c);
}
// Assumes size > 0
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
-_LIBCPP_HIDE_FROM_ABI
-_LIBCPP_CONSTEXPR_SINCE_CXX14 void __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
- _Compare __comp) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
_BidirectionalIterator __lm1 = __last;
for (--__lm1; __first != __lm1; ++__first) {
_BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp);
@@ -249,8 +280,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 void __selection_sort(_BidirectionalIterator __fir
// Sort the iterator range [__first, __last) using the comparator __comp using
// the insertion sort algorithm.
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
-_LIBCPP_HIDE_FROM_ABI
-void __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
+_LIBCPP_HIDE_FROM_ABI void
+__insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
@@ -286,17 +317,18 @@ __insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIte
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
if (__first == __last)
return;
- const _RandomAccessIterator __leftmost = __first - difference_type(1); (void)__leftmost; // can be unused when assertions are disabled
+ const _RandomAccessIterator __leftmost = __first - difference_type(1);
+ (void)__leftmost; // can be unused when assertions are disabled
for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) {
_RandomAccessIterator __j = __i - difference_type(1);
if (__comp(*__i, *__j)) {
value_type __t(_Ops::__iter_move(__i));
_RandomAccessIterator __k = __j;
- __j = __i;
+ __j = __i;
do {
*__j = _Ops::__iter_move(__k);
- __j = __k;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ __j = __k;
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__k != __leftmost,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (__comp(__t, *--__k)); // No need for bounds check due to the assumption stated above.
@@ -306,8 +338,8 @@ __insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIte
}
template <class _AlgPolicy, class _Comp, class _RandomAccessIterator>
-_LIBCPP_HIDE_FROM_ABI bool __insertion_sort_incomplete(
- _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
+_LIBCPP_HIDE_FROM_ABI bool
+__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
@@ -328,23 +360,27 @@ _LIBCPP_HIDE_FROM_ABI bool __insertion_sort_incomplete(
return true;
case 5:
std::__sort5_maybe_branchless<_AlgPolicy, _Comp>(
- __first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3),
- --__last, __comp);
+ __first,
+ __first + difference_type(1),
+ __first + difference_type(2),
+ __first + difference_type(3),
+ --__last,
+ __comp);
return true;
}
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
_RandomAccessIterator __j = __first + difference_type(2);
std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp);
const unsigned __limit = 8;
- unsigned __count = 0;
+ unsigned __count = 0;
for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) {
if (__comp(*__i, *__j)) {
value_type __t(_Ops::__iter_move(__i));
_RandomAccessIterator __k = __j;
- __j = __i;
+ __j = __i;
do {
*__j = _Ops::__iter_move(__k);
- __j = __k;
+ __j = __k;
} while (__j != __first && __comp(__t, *--__k));
*__j = std::move(__t);
if (++__count == __limit)
@@ -500,9 +536,10 @@ __bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last,
using _Ops = _IterOps<_AlgPolicy>;
typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type;
typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- _LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), "");
- const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
- const _RandomAccessIterator __end = __last; (void)__end; //
+ _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), "");
+ const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
+ const _RandomAccessIterator __end = __last;
+ (void)__end; //
value_type __pivot(_Ops::__iter_move(__first));
// Find the first element greater than the pivot.
@@ -510,7 +547,7 @@ __bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last,
// Not guarded since we know the last element is greater than the pivot.
do {
++__first;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__first != __end,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (!__comp(__pivot, *__first));
@@ -523,7 +560,7 @@ __bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last,
// It will be always guarded because __introsort will do the median-of-three
// before calling this.
do {
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__last != __begin,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__last;
@@ -591,16 +628,17 @@ __partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIte
using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type;
- _LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), "");
- const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
- const _RandomAccessIterator __end = __last; (void)__end; //
+ _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), "");
+ const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
+ const _RandomAccessIterator __end = __last;
+ (void)__end; //
value_type __pivot(_Ops::__iter_move(__first));
// Find the first element greater or equal to the pivot. It will be always
// guarded because __introsort will do the median-of-three before calling
// this.
do {
++__first;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__first != __end,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (__comp(*__first, __pivot));
@@ -612,7 +650,7 @@ __partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIte
} else {
// Guarded.
do {
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__last != __begin,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__last;
@@ -630,12 +668,12 @@ __partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIte
_Ops::iter_swap(__first, __last);
do {
++__first;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__first != __end,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (__comp(*__first, __pivot));
do {
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__last != __begin,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__last;
@@ -659,14 +697,15 @@ __partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIter
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type;
// TODO(LLVM18): Make __begin const, see https://reviews.llvm.org/D147089#4349748
- _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
- const _RandomAccessIterator __end = __last; (void)__end; //
+ _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
+ const _RandomAccessIterator __end = __last;
+ (void)__end; //
value_type __pivot(_Ops::__iter_move(__first));
if (__comp(__pivot, *(__last - difference_type(1)))) {
// Guarded.
do {
++__first;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__first != __end,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (!__comp(__pivot, *__first));
@@ -679,7 +718,7 @@ __partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIter
// It will be always guarded because __introsort will do the
// median-of-three before calling this.
do {
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__last != __begin,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__last;
@@ -689,12 +728,12 @@ __partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIter
_Ops::iter_swap(__first, __last);
do {
++__first;
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__first != __end,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
} while (!__comp(__pivot, *__first));
do {
- _LIBCPP_ASSERT_UNCATEGORIZED(
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__last != __begin,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__last;
@@ -747,8 +786,12 @@ void __introsort(_RandomAccessIterator __first,
return;
case 5:
std::__sort5_maybe_branchless<_AlgPolicy, _Compare>(
- __first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3),
- --__last, __comp);
+ __first,
+ __first + difference_type(1),
+ __first + difference_type(2),
+ __first + difference_type(3),
+ --__last,
+ __comp);
return;
}
// Use insertion sort if the length of the range is below the specified limit.
@@ -797,10 +840,10 @@ void __introsort(_RandomAccessIterator __first,
continue;
}
// Use bitset partition only if asked for.
- auto __ret =
- _UseBitSetPartition
- ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp)
- : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp);
+ auto __ret = _UseBitSetPartition
+ ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp)
+ : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>(
+ __first, __last, __comp);
_RandomAccessIterator __i = __ret.first;
// [__first, __i) < *__i and *__i <= [__i+1, __last)
// If we were given a perfect partition, see if insertion sort is quick...
@@ -852,19 +895,27 @@ extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<char>&, char*>(char
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
#endif
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long long>&, unsigned long long*>(
+ unsigned long long*, unsigned long long*, __less<unsigned long long>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
-extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+extern template _LIBCPP_EXPORTED_FROM_ABI void
+__sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
@@ -878,8 +929,7 @@ __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
std::__introsort<_AlgPolicy,
_Comp&,
_RandomAccessIterator,
- __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(
- __first, __last, __comp, __depth_limit);
+ __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(__first, __last, __comp, __depth_limit);
}
template <class _Type, class... _Options>
@@ -935,8 +985,8 @@ _LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, ranges
#endif
template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+__sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
std::__debug_randomize_range<_AlgPolicy>(__first, __last);
if (__libcpp_is_constant_evaluated()) {
@@ -949,17 +999,19 @@ void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _C
}
template <class _RandomAccessIterator, class _Comp>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::sort(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SORT_H
diff --git a/lib/libcxx/include/__algorithm/sort_heap.h b/lib/libcxx/include/__algorithm/sort_heap.h
index a82926ed1c..060fc33c3c 100644
--- a/lib/libcxx/include/__algorithm/sort_heap.h
+++ b/lib/libcxx/include/__algorithm/sort_heap.h
@@ -24,23 +24,26 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
- _RandomAccessIterator __saved_last = __last;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
+__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
+ _RandomAccessIterator __saved_last = __last;
__comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
- for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
+ for (difference_type __n = __last - __first; __n > 1; --__last, (void)--__n)
std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n);
std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref);
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@@ -48,11 +51,13 @@ void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
+sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::sort_heap(std::move(__first), std::move(__last), __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SORT_HEAP_H
diff --git a/lib/libcxx/include/__algorithm/stable_partition.h b/lib/libcxx/include/__algorithm/stable_partition.h
index 38fa9ce37d..8bb1eaf2d2 100644
--- a/lib/libcxx/include/__algorithm/stable_partition.h
+++ b/lib/libcxx/include/__algorithm/stable_partition.h
@@ -26,299 +26,275 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
-_LIBCPP_HIDE_FROM_ABI _ForwardIterator
-__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
- _Distance __len, _Pair __p, forward_iterator_tag __fit)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ _Predicate __pred,
+ _Distance __len,
+ _Pair __p,
+ forward_iterator_tag __fit) {
+ using _Ops = _IterOps<_AlgPolicy>;
- // *__first is known to be false
- // __len >= 1
- if (__len == 1)
- return __first;
- if (__len == 2)
- {
- _ForwardIterator __m = __first;
- if (__pred(*++__m))
- {
- _Ops::iter_swap(__first, __m);
- return __m;
- }
- return __first;
+ // *__first is known to be false
+ // __len >= 1
+ if (__len == 1)
+ return __first;
+ if (__len == 2) {
+ _ForwardIterator __m = __first;
+ if (__pred(*++__m)) {
+ _Ops::iter_swap(__first, __m);
+ return __m;
}
- if (__len <= __p.second)
- { // The buffer is big enough to use
- typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
- // Move the falses into the temporary buffer, and the trues to the front of the line
- // Update __first to always point to the end of the trues
- value_type* __t = __p.first;
- ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
+ return __first;
+ }
+ if (__len <= __p.second) { // The buffer is big enough to use
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
+ // Move the falses into the temporary buffer, and the trues to the front of the line
+ // Update __first to always point to the end of the trues
+ value_type* __t = __p.first;
+ ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
+ __d.template __incr<value_type>();
+ ++__t;
+ _ForwardIterator __i = __first;
+ while (++__i != __last) {
+ if (__pred(*__i)) {
+ *__first = _Ops::__iter_move(__i);
+ ++__first;
+ } else {
+ ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>();
++__t;
- _ForwardIterator __i = __first;
- while (++__i != __last)
- {
- if (__pred(*__i))
- {
- *__first = _Ops::__iter_move(__i);
- ++__first;
- }
- else
- {
- ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
- __d.template __incr<value_type>();
- ++__t;
- }
- }
- // All trues now at start of range, all falses in buffer
- // Move falses back into range, but don't mess up __first which points to first false
- __i = __first;
- for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
- *__i = _Ops::__iter_move(__t2);
- // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
- return __first;
+ }
}
- // Else not enough buffer, do in place
- // __len >= 3
- _ForwardIterator __m = __first;
- _Distance __len2 = __len / 2; // __len2 >= 2
- _Ops::advance(__m, __len2);
- // recurse on [__first, __m), *__first know to be false
- // F?????????????????
- // f m l
- _ForwardIterator __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- __first, __m, __pred, __len2, __p, __fit);
- // TTTFFFFF??????????
- // f ff m l
- // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
- _ForwardIterator __m1 = __m;
- _ForwardIterator __second_false = __last;
- _Distance __len_half = __len - __len2;
- while (__pred(*__m1))
- {
- if (++__m1 == __last)
- goto __second_half_done;
- --__len_half;
- }
- // TTTFFFFFTTTF??????
- // f ff m m1 l
- __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- __m1, __last, __pred, __len_half, __p, __fit);
+ // All trues now at start of range, all falses in buffer
+ // Move falses back into range, but don't mess up __first which points to first false
+ __i = __first;
+ for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i)
+ *__i = _Ops::__iter_move(__t2);
+ // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
+ return __first;
+ }
+ // Else not enough buffer, do in place
+ // __len >= 3
+ _ForwardIterator __m = __first;
+ _Distance __len2 = __len / 2; // __len2 >= 2
+ _Ops::advance(__m, __len2);
+ // recurse on [__first, __m), *__first know to be false
+ // F?????????????????
+ // f m l
+ _ForwardIterator __first_false =
+ std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m, __pred, __len2, __p, __fit);
+ // TTTFFFFF??????????
+ // f ff m l
+ // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
+ _ForwardIterator __m1 = __m;
+ _ForwardIterator __second_false = __last;
+ _Distance __len_half = __len - __len2;
+ while (__pred(*__m1)) {
+ if (++__m1 == __last)
+ goto __second_half_done;
+ --__len_half;
+ }
+ // TTTFFFFFTTTF??????
+ // f ff m m1 l
+ __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
__second_half_done:
- // TTTFFFFFTTTTTFFFFF
- // f ff m sf l
- return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
- // TTTTTTTTFFFFFFFFFF
- // |
+ // TTTFFFFFTTTTTFFFFF
+ // f ff m sf l
+ return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
+ // TTTTTTTTFFFFFFFFFF
+ // |
}
template <class _AlgPolicy, class _Predicate, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
-__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
- forward_iterator_tag)
-{
- typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
- typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) {
+ typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment
- // Either prove all true and return __first or point to first false
- while (true)
- {
- if (__first == __last)
- return __first;
- if (!__pred(*__first))
- break;
- ++__first;
- }
- // We now have a reduced range [__first, __last)
- // *__first is known to be false
- difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
- pair<value_type*, ptrdiff_t> __p(0, 0);
- unique_ptr<value_type, __return_temporary_buffer> __h;
- if (__len >= __alloc_limit)
- {
-// TODO: Remove the use of std::get_temporary_buffer
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- __p = _VSTD::get_temporary_buffer<value_type>(__len);
-_LIBCPP_SUPPRESS_DEPRECATED_POP
- __h.reset(__p.first);
- }
- return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag());
+ const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment
+ // Either prove all true and return __first or point to first false
+ while (true) {
+ if (__first == __last)
+ return __first;
+ if (!__pred(*__first))
+ break;
+ ++__first;
+ }
+ // We now have a reduced range [__first, __last)
+ // *__first is known to be false
+ difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
+ pair<value_type*, ptrdiff_t> __p(0, 0);
+ unique_ptr<value_type, __return_temporary_buffer> __h;
+ if (__len >= __alloc_limit) {
+ // TODO: Remove the use of std::get_temporary_buffer
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ __p = std::get_temporary_buffer<value_type>(__len);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ __h.reset(__p.first);
+ }
+ return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
+ std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag());
}
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
-_BidirectionalIterator
-__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
- _Distance __len, _Pair __p, bidirectional_iterator_tag __bit)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+_BidirectionalIterator __stable_partition_impl(
+ _BidirectionalIterator __first,
+ _BidirectionalIterator __last,
+ _Predicate __pred,
+ _Distance __len,
+ _Pair __p,
+ bidirectional_iterator_tag __bit) {
+ using _Ops = _IterOps<_AlgPolicy>;
- // *__first is known to be false
- // *__last is known to be true
- // __len >= 2
- if (__len == 2)
- {
- _Ops::iter_swap(__first, __last);
- return __last;
- }
- if (__len == 3)
- {
- _BidirectionalIterator __m = __first;
- if (__pred(*++__m))
- {
- _Ops::iter_swap(__first, __m);
- _Ops::iter_swap(__m, __last);
- return __last;
- }
- _Ops::iter_swap(__m, __last);
- _Ops::iter_swap(__first, __m);
- return __m;
+ // *__first is known to be false
+ // *__last is known to be true
+ // __len >= 2
+ if (__len == 2) {
+ _Ops::iter_swap(__first, __last);
+ return __last;
+ }
+ if (__len == 3) {
+ _BidirectionalIterator __m = __first;
+ if (__pred(*++__m)) {
+ _Ops::iter_swap(__first, __m);
+ _Ops::iter_swap(__m, __last);
+ return __last;
}
- if (__len <= __p.second)
- { // The buffer is big enough to use
- typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
- // Move the falses into the temporary buffer, and the trues to the front of the line
- // Update __first to always point to the end of the trues
- value_type* __t = __p.first;
- ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
+ _Ops::iter_swap(__m, __last);
+ _Ops::iter_swap(__first, __m);
+ return __m;
+ }
+ if (__len <= __p.second) { // The buffer is big enough to use
+ typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
+ // Move the falses into the temporary buffer, and the trues to the front of the line
+ // Update __first to always point to the end of the trues
+ value_type* __t = __p.first;
+ ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
+ __d.template __incr<value_type>();
+ ++__t;
+ _BidirectionalIterator __i = __first;
+ while (++__i != __last) {
+ if (__pred(*__i)) {
+ *__first = _Ops::__iter_move(__i);
+ ++__first;
+ } else {
+ ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>();
++__t;
- _BidirectionalIterator __i = __first;
- while (++__i != __last)
- {
- if (__pred(*__i))
- {
- *__first = _Ops::__iter_move(__i);
- ++__first;
- }
- else
- {
- ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
- __d.template __incr<value_type>();
- ++__t;
- }
- }
- // move *__last, known to be true
- *__first = _Ops::__iter_move(__i);
- __i = ++__first;
- // All trues now at start of range, all falses in buffer
- // Move falses back into range, but don't mess up __first which points to first false
- for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
- *__i = _Ops::__iter_move(__t2);
- // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
- return __first;
- }
- // Else not enough buffer, do in place
- // __len >= 4
- _BidirectionalIterator __m = __first;
- _Distance __len2 = __len / 2; // __len2 >= 2
- _Ops::advance(__m, __len2);
- // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
- // F????????????????T
- // f m l
- _BidirectionalIterator __m1 = __m;
- _BidirectionalIterator __first_false = __first;
- _Distance __len_half = __len2;
- while (!__pred(*--__m1))
- {
- if (__m1 == __first)
- goto __first_half_done;
- --__len_half;
+ }
}
- // F???TFFF?????????T
- // f m1 m l
- __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- __first, __m1, __pred, __len_half, __p, __bit);
+ // move *__last, known to be true
+ *__first = _Ops::__iter_move(__i);
+ __i = ++__first;
+ // All trues now at start of range, all falses in buffer
+ // Move falses back into range, but don't mess up __first which points to first false
+ for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i)
+ *__i = _Ops::__iter_move(__t2);
+ // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
+ return __first;
+ }
+ // Else not enough buffer, do in place
+ // __len >= 4
+ _BidirectionalIterator __m = __first;
+ _Distance __len2 = __len / 2; // __len2 >= 2
+ _Ops::advance(__m, __len2);
+ // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
+ // F????????????????T
+ // f m l
+ _BidirectionalIterator __m1 = __m;
+ _BidirectionalIterator __first_false = __first;
+ _Distance __len_half = __len2;
+ while (!__pred(*--__m1)) {
+ if (__m1 == __first)
+ goto __first_half_done;
+ --__len_half;
+ }
+ // F???TFFF?????????T
+ // f m1 m l
+ __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
__first_half_done:
- // TTTFFFFF?????????T
- // f ff m l
- // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
- __m1 = __m;
- _BidirectionalIterator __second_false = __last;
- ++__second_false;
- __len_half = __len - __len2;
- while (__pred(*__m1))
- {
- if (++__m1 == __last)
- goto __second_half_done;
- --__len_half;
- }
- // TTTFFFFFTTTF?????T
- // f ff m m1 l
- __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- __m1, __last, __pred, __len_half, __p, __bit);
+ // TTTFFFFF?????????T
+ // f ff m l
+ // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
+ __m1 = __m;
+ _BidirectionalIterator __second_false = __last;
+ ++__second_false;
+ __len_half = __len - __len2;
+ while (__pred(*__m1)) {
+ if (++__m1 == __last)
+ goto __second_half_done;
+ --__len_half;
+ }
+ // TTTFFFFFTTTF?????T
+ // f ff m m1 l
+ __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
__second_half_done:
- // TTTFFFFFTTTTTFFFFF
- // f ff m sf l
- return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
- // TTTTTTTTFFFFFFFFFF
- // |
+ // TTTFFFFFTTTTTFFFFF
+ // f ff m sf l
+ return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
+ // TTTTTTTTFFFFFFFFFF
+ // |
}
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator>
-_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator
-__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
- bidirectional_iterator_tag)
-{
- typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
- typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
- const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment
- // Either prove all true and return __first or point to first false
- while (true)
- {
- if (__first == __last)
- return __first;
- if (!__pred(*__first))
- break;
- ++__first;
- }
- // __first points to first false, everything prior to __first is already set.
- // Either prove [__first, __last) is all false and return __first, or point __last to last true
- do
- {
- if (__first == --__last)
- return __first;
- } while (!__pred(*__last));
- // We now have a reduced range [__first, __last]
- // *__first is known to be false
- // *__last is known to be true
- // __len >= 2
- difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
- pair<value_type*, ptrdiff_t> __p(0, 0);
- unique_ptr<value_type, __return_temporary_buffer> __h;
- if (__len >= __alloc_limit)
- {
-// TODO: Remove the use of std::get_temporary_buffer
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- __p = _VSTD::get_temporary_buffer<value_type>(__len);
-_LIBCPP_SUPPRESS_DEPRECATED_POP
- __h.reset(__p.first);
- }
- return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
- std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag());
+_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
+ _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) {
+ typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+ typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+ const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment
+ // Either prove all true and return __first or point to first false
+ while (true) {
+ if (__first == __last)
+ return __first;
+ if (!__pred(*__first))
+ break;
+ ++__first;
+ }
+ // __first points to first false, everything prior to __first is already set.
+ // Either prove [__first, __last) is all false and return __first, or point __last to last true
+ do {
+ if (__first == --__last)
+ return __first;
+ } while (!__pred(*__last));
+ // We now have a reduced range [__first, __last]
+ // *__first is known to be false
+ // *__last is known to be true
+ // __len >= 2
+ difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
+ pair<value_type*, ptrdiff_t> __p(0, 0);
+ unique_ptr<value_type, __return_temporary_buffer> __h;
+ if (__len >= __alloc_limit) {
+ // TODO: Remove the use of std::get_temporary_buffer
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ __p = std::get_temporary_buffer<value_type>(__len);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ __h.reset(__p.first);
+ }
+ return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
+ std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag());
}
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory>
-_LIBCPP_HIDE_FROM_ABI
-_ForwardIterator __stable_partition(
+_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition(
_ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) {
return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>(
std::move(__first), std::move(__last), __pred, __iter_category);
}
template <class _ForwardIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY
-_ForwardIterator
-stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
-{
+inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
+stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>(
std::move(__first), std::move(__last), __pred, _IterCategory());
@@ -326,4 +302,6 @@ stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate _
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_STABLE_PARTITION_H
diff --git a/lib/libcxx/include/__algorithm/stable_sort.h b/lib/libcxx/include/__algorithm/stable_sort.h
index dc24218b74..9be192bd65 100644
--- a/lib/libcxx/include/__algorithm/stable_sort.h
+++ b/lib/libcxx/include/__algorithm/stable_sort.h
@@ -29,12 +29,17 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
-_LIBCPP_HIDE_FROM_ABI
-void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __last1,
- typename iterator_traits<_BidirectionalIterator>::value_type* __first2, _Compare __comp) {
+_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
+ _BidirectionalIterator __first1,
+ _BidirectionalIterator __last1,
+ typename iterator_traits<_BidirectionalIterator>::value_type* __first2,
+ _Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
@@ -63,200 +68,187 @@ void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterat
}
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2>
-_LIBCPP_HIDE_FROM_ABI void
-__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+_LIBCPP_HIDE_FROM_ABI void __merge_move_construct(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ typename iterator_traits<_InputIterator1>::value_type* __result,
+ _Compare __comp) {
+ using _Ops = _IterOps<_AlgPolicy>;
- typedef typename iterator_traits<_InputIterator1>::value_type value_type;
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h(__result, __d);
- for (; true; ++__result)
- {
- if (__first1 == __last1)
- {
- for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
- ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
- __h.release();
- return;
- }
- if (__first2 == __last2)
- {
- for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
- ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
- __h.release();
- return;
- }
- if (__comp(*__first2, *__first1))
- {
- ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
- __d.template __incr<value_type>();
- ++__first2;
- }
- else
- {
- ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
- __d.template __incr<value_type>();
- ++__first1;
- }
+ typedef typename iterator_traits<_InputIterator1>::value_type value_type;
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h(__result, __d);
+ for (; true; ++__result) {
+ if (__first1 == __last1) {
+ for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr<value_type>())
+ ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
+ __h.release();
+ return;
+ }
+ if (__first2 == __last2) {
+ for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr<value_type>())
+ ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
+ __h.release();
+ return;
}
+ if (__comp(*__first2, *__first1)) {
+ ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
+ __d.template __incr<value_type>();
+ ++__first2;
+ } else {
+ ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
+ __d.template __incr<value_type>();
+ ++__first1;
+ }
+ }
}
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
-_LIBCPP_HIDE_FROM_ABI void
-__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result, _Compare __comp)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+_LIBCPP_HIDE_FROM_ABI void __merge_move_assign(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _OutputIterator __result,
+ _Compare __comp) {
+ using _Ops = _IterOps<_AlgPolicy>;
- for (; __first1 != __last1; ++__result)
- {
- if (__first2 == __last2)
- {
- for (; __first1 != __last1; ++__first1, (void) ++__result)
- *__result = _Ops::__iter_move(__first1);
- return;
- }
- if (__comp(*__first2, *__first1))
- {
- *__result = _Ops::__iter_move(__first2);
- ++__first2;
- }
- else
- {
- *__result = _Ops::__iter_move(__first1);
- ++__first1;
- }
+ for (; __first1 != __last1; ++__result) {
+ if (__first2 == __last2) {
+ for (; __first1 != __last1; ++__first1, (void)++__result)
+ *__result = _Ops::__iter_move(__first1);
+ return;
}
- for (; __first2 != __last2; ++__first2, (void) ++__result)
- *__result = _Ops::__iter_move(__first2);
+ if (__comp(*__first2, *__first1)) {
+ *__result = _Ops::__iter_move(__first2);
+ ++__first2;
+ } else {
+ *__result = _Ops::__iter_move(__first1);
+ ++__first1;
+ }
+ }
+ for (; __first2 != __last2; ++__first2, (void)++__result)
+ *__result = _Ops::__iter_move(__first2);
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-void
-__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len,
- typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size);
+void __stable_sort(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+ _Compare __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+ typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
+ ptrdiff_t __buff_size);
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-void
-__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len,
- typename iterator_traits<_RandomAccessIterator>::value_type* __first2)
-{
- using _Ops = _IterOps<_AlgPolicy>;
+void __stable_sort_move(_RandomAccessIterator __first1,
+ _RandomAccessIterator __last1,
+ _Compare __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+ typename iterator_traits<_RandomAccessIterator>::value_type* __first2) {
+ using _Ops = _IterOps<_AlgPolicy>;
- typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
- switch (__len)
- {
- case 0:
- return;
- case 1:
- ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
- return;
- case 2:
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
- if (__comp(*--__last1, *__first1))
- {
- ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
- __d.template __incr<value_type>();
- ++__first2;
- ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
- }
- else
- {
- ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
- __d.template __incr<value_type>();
- ++__first2;
- ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
- }
- __h2.release();
- return;
- }
- if (__len <= 8)
- {
- std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp);
- return;
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+ switch (__len) {
+ case 0:
+ return;
+ case 1:
+ ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
+ return;
+ case 2:
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
+ if (__comp(*--__last1, *__first1)) {
+ ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
+ __d.template __incr<value_type>();
+ ++__first2;
+ ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
+ } else {
+ ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
+ __d.template __incr<value_type>();
+ ++__first2;
+ ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
}
- typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
- _RandomAccessIterator __m = __first1 + __l2;
- std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2);
- std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
- std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp);
+ __h2.release();
+ return;
+ }
+ if (__len <= 8) {
+ std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp);
+ return;
+ }
+ typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
+ _RandomAccessIterator __m = __first1 + __l2;
+ std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2);
+ std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
+ std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp);
}
template <class _Tp>
-struct __stable_sort_switch
-{
- static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value;
+struct __stable_sort_switch {
+ static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value;
};
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
-void
-__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
- typename iterator_traits<_RandomAccessIterator>::difference_type __len,
- typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size)
-{
- typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
- switch (__len)
- {
- case 0:
- case 1:
- return;
- case 2:
- if (__comp(*--__last, *__first))
- _IterOps<_AlgPolicy>::iter_swap(__first, __last);
- return;
- }
- if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value))
- {
- std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
- return;
- }
- typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
- _RandomAccessIterator __m = __first + __l2;
- if (__len <= __buff_size)
- {
- __destruct_n __d(0);
- unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
- std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff);
- __d.__set(__l2, (value_type*)nullptr);
- std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
- __d.__set(__len, (value_type*)nullptr);
- std::__merge_move_assign<_AlgPolicy, _Compare>(
- __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
-// _VSTD::__merge<_Compare>(move_iterator<value_type*>(__buff),
-// move_iterator<value_type*>(__buff + __l2),
-// move_iterator<_RandomAccessIterator>(__buff + __l2),
-// move_iterator<_RandomAccessIterator>(__buff + __len),
-// __first, __comp);
- return;
- }
- std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
- std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
- std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
+void __stable_sort(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+ _Compare __comp,
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+ typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
+ ptrdiff_t __buff_size) {
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+ switch (__len) {
+ case 0:
+ case 1:
+ return;
+ case 2:
+ if (__comp(*--__last, *__first))
+ _IterOps<_AlgPolicy>::iter_swap(__first, __last);
+ return;
+ }
+ if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
+ std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
+ return;
+ }
+ typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
+ _RandomAccessIterator __m = __first + __l2;
+ if (__len <= __buff_size) {
+ __destruct_n __d(0);
+ unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
+ std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff);
+ __d.__set(__l2, (value_type*)nullptr);
+ std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
+ __d.__set(__len, (value_type*)nullptr);
+ std::__merge_move_assign<_AlgPolicy, _Compare>(
+ __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
+ // std::__merge<_Compare>(move_iterator<value_type*>(__buff),
+ // move_iterator<value_type*>(__buff + __l2),
+ // move_iterator<_RandomAccessIterator>(__buff + __l2),
+ // move_iterator<_RandomAccessIterator>(__buff + __len),
+ // __first, __comp);
+ return;
+ }
+ std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
+ std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
+ std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
}
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI
-void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
- using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
+inline _LIBCPP_HIDE_FROM_ABI void
+__stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
+ using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
difference_type __len = __last - __first;
pair<value_type*, ptrdiff_t> __buf(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
-// TODO: Remove the use of std::get_temporary_buffer
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- __buf = std::get_temporary_buffer<value_type>(__len);
-_LIBCPP_SUPPRESS_DEPRECATED_POP
- __h.reset(__buf.first);
+ // TODO: Remove the use of std::get_temporary_buffer
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ __buf = std::get_temporary_buffer<value_type>(__len);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ __h.reset(__buf.first);
}
std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __last, __comp, __len, __buf.first, __buf.second);
@@ -264,17 +256,18 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
}
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI
-void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+inline _LIBCPP_HIDE_FROM_ABI void
+stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
}
template <class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI
-void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+inline _LIBCPP_HIDE_FROM_ABI void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::stable_sort(__first, __last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_STABLE_SORT_H
diff --git a/lib/libcxx/include/__algorithm/swap_ranges.h b/lib/libcxx/include/__algorithm/swap_ranges.h
index 5ce5ed8c88..54b453b723 100644
--- a/lib/libcxx/include/__algorithm/swap_ranges.h
+++ b/lib/libcxx/include/__algorithm/swap_ranges.h
@@ -18,12 +18,14 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// 2+2 iterators: the shorter size will be used.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-pair<_ForwardIterator1, _ForwardIterator2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) {
while (__first1 != __last1 && __first2 != __last2) {
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
@@ -36,8 +38,7 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2
// 2+1 iterators: size2 >= size1.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-pair<_ForwardIterator1, _ForwardIterator2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) {
while (__first1 != __last1) {
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
@@ -49,12 +50,13 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2
}
template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
- return std::__swap_ranges<_ClassicAlgPolicy>(
- std::move(__first1), std::move(__last1), std::move(__first2)).second;
+ return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second;
}
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H
diff --git a/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h b/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h
index 19c102f4c9..70c5818976 100644
--- a/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h
+++ b/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h
@@ -50,15 +50,15 @@ struct __debug_three_way_comp {
__expected = _Order::greater;
if (__o == _Order::greater)
__expected = _Order::less;
- _LIBCPP_ASSERT(__comp_(__l, __r) == __expected, "Comparator does not induce a strict weak ordering");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __comp_(__l, __r) == __expected, "Comparator does not induce a strict weak ordering");
(void)__l;
(void)__r;
}
};
-// Pass the comparator by lvalue reference. Or in debug mode, using a
-// debugging wrapper that stores a reference.
-# if _LIBCPP_ENABLE_DEBUG_MODE
+// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
+# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
template <class _Comp>
using __three_way_comp_ref_type = __debug_three_way_comp<_Comp>;
# else
diff --git a/lib/libcxx/include/__algorithm/transform.h b/lib/libcxx/include/__algorithm/transform.h
index 4722c154cf..1b42440959 100644
--- a/lib/libcxx/include/__algorithm/transform.h
+++ b/lib/libcxx/include/__algorithm/transform.h
@@ -18,24 +18,23 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
-{
- for (; __first != __last; ++__first, (void) ++__result)
- *__result = __op(*__first);
- return __result;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
+transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) {
+ for (; __first != __last; ++__first, (void)++__result)
+ *__result = __op(*__first);
+ return __result;
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_OutputIterator
-transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
- _OutputIterator __result, _BinaryOperation __binary_op)
-{
- for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result)
- *__result = __binary_op(*__first1, *__first2);
- return __result;
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator transform(
+ _InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _OutputIterator __result,
+ _BinaryOperation __binary_op) {
+ for (; __first1 != __last1; ++__first1, (void)++__first2, ++__result)
+ *__result = __binary_op(*__first1, *__first2);
+ return __result;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h b/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h
index 1f2039949d..aef0fbfb7c 100644
--- a/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h
+++ b/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h
@@ -20,7 +20,7 @@
#if _LIBCPP_STD_VER >= 20
_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
+# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -41,16 +41,12 @@ private:
public:
using result_type = invoke_result_t<_Gen&>;
- _LIBCPP_HIDE_FROM_ABI
- static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); }
- _LIBCPP_HIDE_FROM_ABI
- static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); }
+ _LIBCPP_HIDE_FROM_ABI static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); }
+ _LIBCPP_HIDE_FROM_ABI static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); }
- _LIBCPP_HIDE_FROM_ABI
- constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {}
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {}
- _LIBCPP_HIDE_FROM_ABI
- constexpr auto operator()() const { return __gen_(); }
+ _LIBCPP_HIDE_FROM_ABI constexpr auto operator()() const { return __gen_(); }
};
_LIBCPP_END_NAMESPACE_STD
diff --git a/lib/libcxx/include/__algorithm/unique.h b/lib/libcxx/include/__algorithm/unique.h
index 1717a00c8a..056373d06f 100644
--- a/lib/libcxx/include/__algorithm/unique.h
+++ b/lib/libcxx/include/__algorithm/unique.h
@@ -21,6 +21,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// unique
@@ -56,4 +59,6 @@ unique(_ForwardIterator __first, _ForwardIterator __last) {
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_UNIQUE_H
diff --git a/lib/libcxx/include/__algorithm/unique_copy.h b/lib/libcxx/include/__algorithm/unique_copy.h
index 81fcd50f01..16ce80cab3 100644
--- a/lib/libcxx/include/__algorithm/unique_copy.h
+++ b/lib/libcxx/include/__algorithm/unique_copy.h
@@ -23,6 +23,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __unique_copy_tags {
@@ -119,4 +122,6 @@ unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_UNIQUE_COPY_H
diff --git a/lib/libcxx/include/__algorithm/unwrap_iter.h b/lib/libcxx/include/__algorithm/unwrap_iter.h
index 91346e3c1b..50d815c970 100644
--- a/lib/libcxx/include/__algorithm/unwrap_iter.h
+++ b/lib/libcxx/include/__algorithm/unwrap_iter.h
@@ -57,11 +57,11 @@ struct __unwrap_iter_impl<_Iter, true> {
}
};
-template<class _Iter,
- class _Impl = __unwrap_iter_impl<_Iter>,
- __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT {
+template <class _Iter,
+ class _Impl = __unwrap_iter_impl<_Iter>,
+ __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>()))
+__unwrap_iter(_Iter __i) _NOEXCEPT {
return _Impl::__unwrap(__i);
}
@@ -80,6 +80,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig
_LIBCPP_END_NAMESPACE_STD
-_LIBCPP_PUSH_MACROS
+_LIBCPP_POP_MACROS
#endif // _LIBCPP___ALGORITHM_UNWRAP_ITER_H
diff --git a/lib/libcxx/include/__algorithm/unwrap_range.h b/lib/libcxx/include/__algorithm/unwrap_range.h
index 2c75c8f49d..2d4b9bb554 100644
--- a/lib/libcxx/include/__algorithm/unwrap_range.h
+++ b/lib/libcxx/include/__algorithm/unwrap_range.h
@@ -22,6 +22,9 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// __unwrap_range and __rewrap_range are used to unwrap ranges which may have different iterator and sentinel types.
@@ -50,7 +53,7 @@ struct __unwrap_range_impl {
}
_LIBCPP_HIDE_FROM_ABI static constexpr auto __rewrap(const _Iter&, _Iter __iter)
- requires (!(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>))
+ requires(!(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>))
{
return __iter;
}
@@ -73,10 +76,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __unwrap_range(_Iter __first, _Sent __last)
return __unwrap_range_impl<_Iter, _Sent>::__unwrap(std::move(__first), std::move(__last));
}
-template <
- class _Sent,
- class _Iter,
- class _Unwrapped = decltype(std::__unwrap_range(std::declval<_Iter>(), std::declval<_Sent>()))>
+template < class _Sent, class _Iter, class _Unwrapped>
_LIBCPP_HIDE_FROM_ABI constexpr _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) {
return __unwrap_range_impl<_Iter, _Sent>::__rewrap(std::move(__orig_iter), std::move(__iter));
}
@@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair<_Unwrapped, _Unwrapped> __unwrap_ra
return std::make_pair(std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last)));
}
-template <class _Iter, class _Unwrapped = decltype(std::__unwrap_iter(std::declval<_Iter>()))>
+template <class _Iter, class _Unwrapped>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) {
return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter));
}
@@ -94,4 +94,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap_range(_Iter __orig_iter,
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___ALGORITHM_UNWRAP_RANGE_H