aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/algorithm
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/algorithm')
-rw-r--r--libcxx/include/algorithm246
1 files changed, 232 insertions, 14 deletions
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<projected<iterator_t<R>, Proj>> Pred>
constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20
+ template<input_iterator I1, sentinel_for<I1> S1,
+ random_access_iterator I2, sentinel_for<I2> S2,
+ class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
+ requires indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
+ indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
+ constexpr partial_sort_copy_result<I1, I2>
+ partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
+ Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
+
+ template<input_range R1, random_access_range R2, class Comp = ranges::less,
+ class Proj1 = identity, class Proj2 = identity>
+ requires indirectly_copyable<iterator_t<R1>, iterator_t<R2>> &&
+ sortable<iterator_t<R2>, Comp, Proj2> &&
+ indirect_strict_weak_order<Comp, projected<iterator_t<R1>, Proj1>,
+ projected<iterator_t<R2>, Proj2>>
+ constexpr partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
+ partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
+ Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
indirect_strict_weak_order<projected<I, Proj>> 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<R>
ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
+ template<class T, class Proj = identity,
+ indirect_strict_weak_order<projected<const T*, Proj>> 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<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
class Proj1 = identity, class Proj2 = identity,
indirect_strict_weak_order<projected<I1, Proj1>,
@@ -726,6 +750,13 @@ namespace ranges {
constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
ranges::reverse_copy(R&& r, O result); // since C++20
+ template<permutable I, sentinel_for<I> S>
+ constexpr subrange<I> rotate(I first, I middle, S last); // since C++20
+
+ template<forward_range R>
+ requires permutable<iterator_t<R>>
+ constexpr borrowed_subrange_t<R> rotate(R&& r, iterator_t<R> middle); // Since C++20
+
template <class _InIter, class _OutIter>
using rotate_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
@@ -739,6 +770,18 @@ namespace ranges {
constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
ranges::rotate_copy(R&& r, iterator_t<R> middle, O result); // since C++20
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Gen>
+ requires (forward_iterator<I> || random_access_iterator<O>) &&
+ indirectly_copyable<I, O> &&
+ uniform_random_bit_generator<remove_reference_t<Gen>>
+ O sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g); // Since C++20
+
+ template<input_range R, weakly_incrementable O, class Gen>
+ requires (forward_range<R> || random_access_iterator<O>) &&
+ indirectly_copyable<iterator_t<R>, O> &&
+ uniform_random_bit_generator<remove_reference_t<Gen>>
+ O sample(R&& r, O out, range_difference_t<R> n, Gen&& g); // Since C++20
+
template<random_access_iterator I, sentinel_for<I> S, class Gen>
requires permutable<I> &&
uniform_random_bit_generator<remove_reference_t<Gen>>
@@ -750,6 +793,21 @@ namespace ranges {
borrowed_iterator_t<R> shuffle(R&& r, Gen&& g); // Since C++20
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
+ sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
+ indirect_equivalence_relation<projected<I1, Proj1>,
+ projected<I2, Proj2>> 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<forward_range R1, forward_range R2,
+ class Proj1 = identity, class Proj2 = identity,
+ indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
+ projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
+ constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
+ Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
+
+ template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
sentinel_for<I2> S2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
@@ -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<input_range R1, input_range R2, weakly_incrementable O,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
@@ -816,13 +874,13 @@ namespace ranges {
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
constexpr subrange<I>
equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
-
+
template<forward_range R, class T, class Proj = identity,
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
ranges::less>
constexpr borrowed_subrange_t<R>
equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
-
+
template<class I1, class I2, class O>
using set_union_result = in_in_out_result<I1, I2, O>; // 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<input_range R1, input_range R2, class Proj1 = identity,
class Proj2 = identity,
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
constexpr bool includes(R1&& r1, R2&& r2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
+
+ template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
+ class Proj = identity>
+ requires sortable<I, Comp, Proj>
+ I inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // Since C++20
+
+ template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
+ requires sortable<iterator_t<R>, Comp, Proj>
+ borrowed_iterator_t<R>
+ inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {},
+ Proj proj = {}); // Since C++20
+
+ template<permutable I, sentinel_for<I> S, class Proj = identity,
+ indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
+ constexpr subrange<I> unique(I first, S last, C comp = {}, Proj proj = {}); // Since C++20
+
+ template<forward_range R, class Proj = identity,
+ indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
+ requires permutable<iterator_t<R>>
+ constexpr borrowed_subrange_t<R>
+ unique(R&& r, C comp = {}, Proj proj = {}); // Since C++20
+
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
+ indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
+ requires indirectly_copyable<I, O> &&
+ (forward_iterator<I> ||
+ (input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
+ indirectly_copyable_storable<I, O>)
+ constexpr unique_copy_result<I, O>
+ unique_copy(I first, S last, O result, C comp = {}, Proj proj = {}); // Since C++20
+
+ template<input_range R, weakly_incrementable O, class Proj = identity,
+ indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
+ requires indirectly_copyable<iterator_t<R>, O> &&
+ (forward_iterator<iterator_t<R>> ||
+ (input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
+ indirectly_copyable_storable<iterator_t<R>, O>)
+ constexpr unique_copy_result<borrowed_iterator_t<R>, O>
+ unique_copy(R&& r, O result, C comp = {}, Proj proj = {}); // Since C++20
+
+ template<class I, class O>
+ using remove_copy_result = in_out_result<I, O>; // Since C++20
+
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
+ class Proj = identity>
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
+ constexpr remove_copy_result<I, O>
+ remove_copy(I first, S last, O result, const T& value, Proj proj = {}); // Since C++20
+
+ template<input_range R, weakly_incrementable O, class T, class Proj = identity>
+ requires indirectly_copyable<iterator_t<R>, O> &&
+ indirect_binary_predicate<ranges::equal_to,
+ projected<iterator_t<R>, Proj>, const T*>
+ constexpr remove_copy_result<borrowed_iterator_t<R>, O>
+ remove_copy(R&& r, O result, const T& value, Proj proj = {}); // Since C++20
+
+ template<class I, class O>
+ using remove_copy_if_result = in_out_result<I, O>; // Since C++20
+
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
+ class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
+ requires indirectly_copyable<I, O>
+ constexpr remove_copy_if_result<I, O>
+ remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // Since C++20
+
+ template<input_range R, weakly_incrementable O, class Proj = identity,
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
+ requires indirectly_copyable<iterator_t<R>, O>
+ constexpr remove_copy_if_result<borrowed_iterator_t<R>, O>
+ remove_copy_if(R&& r, O result, Pred pred, Proj proj = {}); // Since C++20
+
+ template<class I, class O>
+ using replace_copy_result = in_out_result<I, O>; // Since C++20
+
+ template<input_iterator I, sentinel_for<I> S, class T1, class T2,
+ output_iterator<const T2&> O, class Proj = identity>
+ requires indirectly_copyable<I, O> &&
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
+ constexpr replace_copy_result<I, O>
+ replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
+ Proj proj = {}); // Since C++20
+
+ template<input_range R, class T1, class T2, output_iterator<const T2&> O,
+ class Proj = identity>
+ requires indirectly_copyable<iterator_t<R>, O> &&
+ indirect_binary_predicate<ranges::equal_to,
+ projected<iterator_t<R>, Proj>, const T1*>
+ constexpr replace_copy_result<borrowed_iterator_t<R>, O>
+ replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
+ Proj proj = {}); // Since C++20
+
+ template<class I, class O>
+ using replace_copy_if_result = in_out_result<I, O>; // Since C++20
+
+ template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
+ class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
+ requires indirectly_copyable<I, O>
+ constexpr replace_copy_if_result<I, O>
+ replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
+ Proj proj = {}); // Since C++20
+
+ template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
+ requires indirectly_copyable<iterator_t<R>, O>
+ constexpr replace_copy_if_result<borrowed_iterator_t<R>, O>
+ replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
+ Proj proj = {}); // Since C++20
+
+ template<class I>
+ using prev_permutation_result = in_found_result<I>; // Since C++20
+
+ template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
+ class Proj = identity>
+ requires sortable<I, Comp, Proj>
+ constexpr ranges::prev_permutation_result<I>
+ ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
+
+ template<bidirectional_range R, class Comp = ranges::less,
+ class Proj = identity>
+ requires sortable<iterator_t<R>, Comp, Proj>
+ constexpr ranges::prev_permutation_result<borrowed_iterator_t<R>>
+ ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
+
+ template<class I>
+ using next_permutation_result = in_found_result<I>; // Since C++20
+
+ template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
+ class Proj = identity>
+ requires sortable<I, Comp, Proj>
+ constexpr ranges::next_permutation_result<I>
+ ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
+
+ template<bidirectional_range R, class Comp = ranges::less,
+ class Proj = identity>
+ requires sortable<iterator_t<R>, Comp, Proj>
+ constexpr ranges::next_permutation_result<borrowed_iterator_t<R>>
+ ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
+
}
+template <class InputIterator, class Predicate>
constexpr bool // constexpr in C++20
all_of(InputIterator first, InputIterator last, Predicate pred);
@@ -1507,12 +1704,9 @@ template <class BidirectionalIterator, class Compare>
*/
#include <__assert> // all public C++ headers provide the assertion handler
-#include <__bits>
#include <__config>
#include <__debug>
#include <cstddef>
-#include <cstring>
-#include <memory>
#include <type_traits>
#include <version>
@@ -1587,6 +1781,7 @@ template <class BidirectionalIterator, class Compare>
#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 <class BidirectionalIterator, class Compare>
#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 <class BidirectionalIterator, class Compare>
#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 <class BidirectionalIterator, class Compare>
#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 <class BidirectionalIterator, class Compare>
#include <__algorithm/unwrap_iter.h>
#include <__algorithm/upper_bound.h>
-#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
-# include <chrono>
-# include <iterator>
-# include <utility>
-#endif
-
// standard-mandated includes
+
+// [algorithm.syn]
#include <initializer_list>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -1702,7 +1906,21 @@ template <class BidirectionalIterator, class Compare>
#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 <chrono>
+#endif
+
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+# include <atomic>
+# include <concepts>
+# include <cstring>
+# include <iterator>
+# include <memory>
+# include <stdexcept>
+# include <utility>
#endif
#endif // _LIBCPP_ALGORITHM