From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- libcxx/include/algorithm | 246 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 232 insertions(+), 14 deletions(-) (limited to 'libcxx/include/algorithm') diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index 197b3b1043bb..cb2d27cbc80c 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -446,6 +446,25 @@ namespace ranges { indirect_unary_predicate, Proj>> Pred> constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20 + template S1, + random_access_iterator I2, sentinel_for S2, + class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity> + requires indirectly_copyable && sortable && + indirect_strict_weak_order, projected> + constexpr partial_sort_copy_result + partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last, + Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 + + template + requires indirectly_copyable, iterator_t> && + sortable, Comp, Proj2> && + indirect_strict_weak_order, Proj1>, + projected, Proj2>> + constexpr partial_sort_copy_result, borrowed_iterator_t> + partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {}, + Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 + template S, class Proj = identity, indirect_strict_weak_order> Comp = ranges::less> constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20 @@ -574,6 +593,11 @@ namespace ranges { constexpr borrowed_iterator_t ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20 + template> Comp = ranges::less> + constexpr const T& + ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {}); // since C++20 + template S1, input_iterator I2, sentinel_for S2, class Proj1 = identity, class Proj2 = identity, indirect_strict_weak_order, @@ -726,6 +750,13 @@ namespace ranges { constexpr ranges::reverse_copy_result, O> ranges::reverse_copy(R&& r, O result); // since C++20 + template S> + constexpr subrange rotate(I first, I middle, S last); // since C++20 + + template + requires permutable> + constexpr borrowed_subrange_t rotate(R&& r, iterator_t middle); // Since C++20 + template using rotate_copy_result = in_out_result<_InIter, _OutIter>; // since C++20 @@ -739,6 +770,18 @@ namespace ranges { constexpr ranges::rotate_copy_result, O> ranges::rotate_copy(R&& r, iterator_t middle, O result); // since C++20 + template S, weakly_incrementable O, class Gen> + requires (forward_iterator || random_access_iterator) && + indirectly_copyable && + uniform_random_bit_generator> + O sample(I first, S last, O out, iter_difference_t n, Gen&& g); // Since C++20 + + template + requires (forward_range || random_access_iterator) && + indirectly_copyable, O> && + uniform_random_bit_generator> + O sample(R&& r, O out, range_difference_t n, Gen&& g); // Since C++20 + template S, class Gen> requires permutable && uniform_random_bit_generator> @@ -749,6 +792,21 @@ namespace ranges { uniform_random_bit_generator> borrowed_iterator_t shuffle(R&& r, Gen&& g); // Since C++20 + template S1, forward_iterator I2, + sentinel_for S2, class Proj1 = identity, class Proj2 = identity, + indirect_equivalence_relation, + projected> Pred = ranges::equal_to> + constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2, + Pred pred = {}, + Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 + + template, Proj1>, + projected, Proj2>> Pred = ranges::equal_to> + constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {}, + Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 + template S1, forward_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> @@ -803,7 +861,7 @@ namespace ranges { set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20 - + template requires mergeable, iterator_t, O, Comp, Proj1, Proj2> @@ -816,13 +874,13 @@ namespace ranges { indirect_strict_weak_order> Comp = ranges::less> constexpr subrange equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20 - + template, Proj>> Comp = ranges::less> constexpr borrowed_subrange_t equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20 - + template using set_union_result = in_in_out_result; // since C++20 @@ -847,15 +905,154 @@ namespace ranges { ranges::less> constexpr bool includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 - + template, Proj1>, projected, Proj2>> Comp = ranges::less> constexpr bool includes(R1&& r1, R2&& r2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 + + template S, class Comp = ranges::less, + class Proj = identity> + requires sortable + I inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // Since C++20 + + template + requires sortable, Comp, Proj> + borrowed_iterator_t + inplace_merge(R&& r, iterator_t middle, Comp comp = {}, + Proj proj = {}); // Since C++20 + + template S, class Proj = identity, + indirect_equivalence_relation> C = ranges::equal_to> + constexpr subrange unique(I first, S last, C comp = {}, Proj proj = {}); // Since C++20 + + template, Proj>> C = ranges::equal_to> + requires permutable> + constexpr borrowed_subrange_t + unique(R&& r, C comp = {}, Proj proj = {}); // Since C++20 + + template S, weakly_incrementable O, class Proj = identity, + indirect_equivalence_relation> C = ranges::equal_to> + requires indirectly_copyable && + (forward_iterator || + (input_iterator && same_as, iter_value_t>) || + indirectly_copyable_storable) + constexpr unique_copy_result + unique_copy(I first, S last, O result, C comp = {}, Proj proj = {}); // Since C++20 + + template, Proj>> C = ranges::equal_to> + requires indirectly_copyable, O> && + (forward_iterator> || + (input_iterator && same_as, iter_value_t>) || + indirectly_copyable_storable, O>) + constexpr unique_copy_result, O> + unique_copy(R&& r, O result, C comp = {}, Proj proj = {}); // Since C++20 + + template + using remove_copy_result = in_out_result; // Since C++20 + + template S, weakly_incrementable O, class T, + class Proj = identity> + indirect_binary_predicate, const T*> + constexpr remove_copy_result + remove_copy(I first, S last, O result, const T& value, Proj proj = {}); // Since C++20 + + template + requires indirectly_copyable, O> && + indirect_binary_predicate, Proj>, const T*> + constexpr remove_copy_result, O> + remove_copy(R&& r, O result, const T& value, Proj proj = {}); // Since C++20 + + template + using remove_copy_if_result = in_out_result; // Since C++20 + + template S, weakly_incrementable O, + class Proj = identity, indirect_unary_predicate> Pred> + requires indirectly_copyable + constexpr remove_copy_if_result + remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // Since C++20 + + template, Proj>> Pred> + requires indirectly_copyable, O> + constexpr remove_copy_if_result, O> + remove_copy_if(R&& r, O result, Pred pred, Proj proj = {}); // Since C++20 + + template + using replace_copy_result = in_out_result; // Since C++20 + + template S, class T1, class T2, + output_iterator O, class Proj = identity> + requires indirectly_copyable && + indirect_binary_predicate, const T1*> + constexpr replace_copy_result + replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value, + Proj proj = {}); // Since C++20 + + template O, + class Proj = identity> + requires indirectly_copyable, O> && + indirect_binary_predicate, Proj>, const T1*> + constexpr replace_copy_result, O> + replace_copy(R&& r, O result, const T1& old_value, const T2& new_value, + Proj proj = {}); // Since C++20 + + template + using replace_copy_if_result = in_out_result; // Since C++20 + + template S, class T, output_iterator O, + class Proj = identity, indirect_unary_predicate> Pred> + requires indirectly_copyable + constexpr replace_copy_if_result + replace_copy_if(I first, S last, O result, Pred pred, const T& new_value, + Proj proj = {}); // Since C++20 + + template O, class Proj = identity, + indirect_unary_predicate, Proj>> Pred> + requires indirectly_copyable, O> + constexpr replace_copy_if_result, O> + replace_copy_if(R&& r, O result, Pred pred, const T& new_value, + Proj proj = {}); // Since C++20 + + template + using prev_permutation_result = in_found_result; // Since C++20 + + template S, class Comp = ranges::less, + class Proj = identity> + requires sortable + constexpr ranges::prev_permutation_result + ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20 + + template + requires sortable, Comp, Proj> + constexpr ranges::prev_permutation_result> + ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20 + + template + using next_permutation_result = in_found_result; // Since C++20 + + template S, class Comp = ranges::less, + class Proj = identity> + requires sortable + constexpr ranges::next_permutation_result + ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20 + + template + requires sortable, Comp, Proj> + constexpr ranges::next_permutation_result> + ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20 + } +template constexpr bool // constexpr in C++20 all_of(InputIterator first, InputIterator last, Predicate pred); @@ -1507,12 +1704,9 @@ template */ #include <__assert> // all public C++ headers provide the assertion handler -#include <__bits> #include <__config> #include <__debug> #include -#include -#include #include #include @@ -1587,6 +1781,7 @@ template #include <__algorithm/ranges_all_of.h> #include <__algorithm/ranges_any_of.h> #include <__algorithm/ranges_binary_search.h> +#include <__algorithm/ranges_clamp.h> #include <__algorithm/ranges_copy.h> #include <__algorithm/ranges_copy_backward.h> #include <__algorithm/ranges_copy_if.h> @@ -1607,9 +1802,11 @@ template #include <__algorithm/ranges_generate.h> #include <__algorithm/ranges_generate_n.h> #include <__algorithm/ranges_includes.h> +#include <__algorithm/ranges_inplace_merge.h> #include <__algorithm/ranges_is_heap.h> #include <__algorithm/ranges_is_heap_until.h> #include <__algorithm/ranges_is_partitioned.h> +#include <__algorithm/ranges_is_permutation.h> #include <__algorithm/ranges_is_sorted.h> #include <__algorithm/ranges_is_sorted_until.h> #include <__algorithm/ranges_lexicographical_compare.h> @@ -1625,21 +1822,30 @@ template #include <__algorithm/ranges_mismatch.h> #include <__algorithm/ranges_move.h> #include <__algorithm/ranges_move_backward.h> +#include <__algorithm/ranges_next_permutation.h> #include <__algorithm/ranges_none_of.h> #include <__algorithm/ranges_nth_element.h> #include <__algorithm/ranges_partial_sort.h> +#include <__algorithm/ranges_partial_sort_copy.h> #include <__algorithm/ranges_partition.h> #include <__algorithm/ranges_partition_copy.h> #include <__algorithm/ranges_partition_point.h> #include <__algorithm/ranges_pop_heap.h> +#include <__algorithm/ranges_prev_permutation.h> #include <__algorithm/ranges_push_heap.h> #include <__algorithm/ranges_remove.h> +#include <__algorithm/ranges_remove_copy.h> +#include <__algorithm/ranges_remove_copy_if.h> #include <__algorithm/ranges_remove_if.h> #include <__algorithm/ranges_replace.h> +#include <__algorithm/ranges_replace_copy.h> +#include <__algorithm/ranges_replace_copy_if.h> #include <__algorithm/ranges_replace_if.h> #include <__algorithm/ranges_reverse.h> #include <__algorithm/ranges_reverse_copy.h> +#include <__algorithm/ranges_rotate.h> #include <__algorithm/ranges_rotate_copy.h> +#include <__algorithm/ranges_sample.h> #include <__algorithm/ranges_search.h> #include <__algorithm/ranges_search_n.h> #include <__algorithm/ranges_set_difference.h> @@ -1653,6 +1859,8 @@ template #include <__algorithm/ranges_stable_sort.h> #include <__algorithm/ranges_swap_ranges.h> #include <__algorithm/ranges_transform.h> +#include <__algorithm/ranges_unique.h> +#include <__algorithm/ranges_unique_copy.h> #include <__algorithm/ranges_upper_bound.h> #include <__algorithm/remove.h> #include <__algorithm/remove_copy.h> @@ -1688,13 +1896,9 @@ template #include <__algorithm/unwrap_iter.h> #include <__algorithm/upper_bound.h> -#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# include -# include -# include -#endif - // standard-mandated includes + +// [algorithm.syn] #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -1702,7 +1906,21 @@ template #endif #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 -# include <__pstl_algorithm> +# include <__pstl_algorithm> +#endif + +#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17 +# include +#endif + +#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 +# include +# include +# include +# include +# include +# include +# include #endif #endif // _LIBCPP_ALGORITHM -- cgit v1.2.3