authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-29 15:12:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-29 15:12:46-07:00
loge6ccc93aacb54f9c183dce43389c2be34e6fde9a
tree797936b1a016fe4fb1a68eac72959c175a8c1a93
parentb5dc8b67bc2e5dd920a5cabbe32c999f8ea71257

update libcxx to LLVM 15 rc3


42 files changed, 1343 insertions(+), 506 deletions(-)

lib/libcxx/include/__algorithm/algorithm_family.h deleted-52
......@@ -1,52 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
10#define _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/move.h>
14#include <__algorithm/ranges_move.h>
15#include <__config>
16#include <__utility/move.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _AlgPolicy>
25struct _AlgFamily;
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29template <>
30struct _AlgFamily<_RangeAlgPolicy> {
31 static constexpr auto __move = ranges::move;
32};
33
34#endif
35
36template <>
37struct _AlgFamily<_ClassicAlgPolicy> {
38
39 // move
40 template <class _InputIterator, class _OutputIterator>
41 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 static _OutputIterator
42 __move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
43 return std::move(
44 std::move(__first),
45 std::move(__last),
46 std::move(__result));
47 }
48};
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
lib/libcxx/include/__algorithm/clamp.h+2-2
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER > 14
2323template<class _Tp, class _Compare>
2424_LIBCPP_NODISCARD_EXT inline
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
25_LIBCPP_INLINE_VISIBILITY constexpr
2626const _Tp&
2727clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
2828{
......@@ -33,7 +33,7 @@ clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
3333
3434template<class _Tp>
3535_LIBCPP_NODISCARD_EXT inline
36_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
36_LIBCPP_INLINE_VISIBILITY constexpr
3737const _Tp&
3838clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
3939{
lib/libcxx/include/__algorithm/copy_backward.h+3-3
......@@ -20,7 +20,6 @@
2020#include <__ranges/subrange.h>
2121#include <__utility/move.h>
2222#include <__utility/pair.h>
23#include <cstring>
2423#include <type_traits>
2524
2625#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -44,9 +43,10 @@ __copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator _
4443template <class _AlgPolicy, class _Iter1, class _Sent1, class _Iter2,
4544 __enable_if_t<is_same<_AlgPolicy, _RangeAlgPolicy>::value, int> = 0>
4645_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
47 auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), std::move(__last)));
46 auto __last_iter = _IterOps<_AlgPolicy>::next(__first, std::move(__last));
47 auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), __last_iter));
4848 auto __ret = ranges::copy(std::move(__reverse_range), std::make_reverse_iterator(__result));
49 return std::make_pair(__ret.in.base(), __ret.out.base());
49 return std::make_pair(__last_iter, __ret.out.base());
5050}
5151#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
5252
lib/libcxx/include/__algorithm/find_first_of.h+2-1
......@@ -24,7 +24,8 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
2424_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
2525 _ForwardIterator1 __last1,
2626 _ForwardIterator2 __first2,
27 _ForwardIterator2 __last2, _BinaryPredicate __pred) {
27 _ForwardIterator2 __last2,
28 _BinaryPredicate&& __pred) {
2829 for (; __first1 != __last1; ++__first1)
2930 for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
3031 if (__pred(*__first1, *__j))
lib/libcxx/include/__algorithm/inplace_merge.h+2-4
......@@ -9,7 +9,6 @@
99#ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1010#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1111
12#include <__algorithm/algorithm_family.h>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/iterator_operations.h>
......@@ -65,7 +64,7 @@ void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
6564 {
6665 if (__first2 == __last2)
6766 {
68 _AlgFamily<_AlgPolicy>::__move(__first1, __last1, __result);
67 std::__move<_AlgPolicy>(__first1, __last1, __result);
6968 return;
7069 }
7170
......@@ -185,8 +184,7 @@ void __inplace_merge(
185184 difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
186185 // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
187186 // swap middle two partitions
188 // TODO(alg-policy): pass `_AlgPolicy` once it's supported by `rotate`.
189 __middle = _VSTD::rotate(__m1, __middle, __m2);
187 __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
190188 // __len12 and __len21 now have swapped meanings
191189 // merge smaller range with recursive call and larger with tail recursion elimination
192190 if (__len11 + __len21 < __len12 + __len22)
lib/libcxx/include/__algorithm/is_permutation.h+168-91
......@@ -11,10 +11,16 @@
1111#define _LIBCPP___ALGORITHM_IS_PERMUTATION_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__iterator/concepts.h>
1519#include <__iterator/distance.h>
1620#include <__iterator/iterator_traits.h>
1721#include <__iterator/next.h>
22#include <__utility/move.h>
23#include <type_traits>
1824
1925#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2026# pragma GCC system_header
......@@ -22,140 +28,211 @@
2228
2329_LIBCPP_BEGIN_NAMESPACE_STD
2430
25template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
26_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
27is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
28 _BinaryPredicate __pred) {
29 // shorten sequences as much as possible by lopping of any equal prefix
30 for (; __first1 != __last1; ++__first1, (void)++__first2)
31 if (!__pred(*__first1, *__first2))
32 break;
33 if (__first1 == __last1)
34 return true;
31template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class = void>
32struct _ConstTimeDistance : false_type {};
3533
36 // __first1 != __last1 && *__first1 != *__first2
37 typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
38 _D1 __l1 = _VSTD::distance(__first1, __last1);
39 if (__l1 == _D1(1))
40 return false;
41 _ForwardIterator2 __last2 = _VSTD::next(__first2, __l1);
42 // For each element in [f1, l1) see if there are the same number of
43 // equal elements in [f2, l2)
44 for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) {
34#if _LIBCPP_STD_VER > 17
35
36template <class _Iter1, class _Sent1, class _Iter2, class _Sent2>
37struct _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2, __enable_if_t<
38 sized_sentinel_for<_Sent1, _Iter1> &&
39 sized_sentinel_for<_Sent2, _Iter2>
40>> : true_type {};
41
42#else
43
44template <class _Iter1, class _Iter2>
45struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t<
46 is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value &&
47 is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value
48> > : true_type {};
49
50#endif // _LIBCPP_STD_VER > 17
51
52// Internal functions
53
54// For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2)
55template <class _AlgPolicy,
56 class _Iter1, class _Sent1, class _Iter2, class _Sent2,
57 class _Proj1, class _Proj2, class _Pred>
58_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
59__is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
60 _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
61 using _D1 = __iter_diff_t<_Iter1>;
62
63 for (auto __i = __first1; __i != __last1; ++__i) {
4564 // Have we already counted the number of *__i in [f1, l1)?
46 _ForwardIterator1 __match = __first1;
47 for (; __match != __i; ++__match)
48 if (__pred(*__match, *__i))
65 auto __match = __first1;
66 for (; __match != __i; ++__match) {
67 if (std::__invoke(__pred, std::__invoke(__proj1, *__match), std::__invoke(__proj1, *__i)))
4968 break;
69 }
70
5071 if (__match == __i) {
5172 // Count number of *__i in [f2, l2)
5273 _D1 __c2 = 0;
53 for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
54 if (__pred(*__i, *__j))
74 for (auto __j = __first2; __j != __last2; ++__j) {
75 if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj2, *__j)))
5576 ++__c2;
77 }
5678 if (__c2 == 0)
5779 return false;
80
5881 // Count number of *__i in [__i, l1) (we can start with 1)
5982 _D1 __c1 = 1;
60 for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
61 if (__pred(*__i, *__j))
83 for (auto __j = _IterOps<_AlgPolicy>::next(__i); __j != __last1; ++__j) {
84 if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj1, *__j)))
6285 ++__c1;
86 }
6387 if (__c1 != __c2)
6488 return false;
6589 }
6690 }
91
6792 return true;
6893}
6994
70template <class _ForwardIterator1, class _ForwardIterator2>
71_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
72is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
73 typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
74 typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
75 return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
95// 2+1 iterators, predicate. Not used by range algorithms.
96template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate>
97_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
98__is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2,
99 _BinaryPredicate&& __pred) {
100 // Shorten sequences as much as possible by lopping of any equal prefix.
101 for (; __first1 != __last1; ++__first1, (void)++__first2) {
102 if (!__pred(*__first1, *__first2))
103 break;
104 }
105
106 if (__first1 == __last1)
107 return true;
108
109 // __first1 != __last1 && *__first1 != *__first2
110 using _D1 = __iter_diff_t<_ForwardIterator1>;
111 _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
112 if (__l1 == _D1(1))
113 return false;
114 auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1);
115
116 return std::__is_permutation_impl<_AlgPolicy>(
117 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
118 __pred, __identity(), __identity());
76119}
77120
78#if _LIBCPP_STD_VER > 11
79template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
80_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
81__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
82 _ForwardIterator2 __last2, _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag) {
83 // shorten sequences as much as possible by lopping of any equal prefix
84 for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
85 if (!__pred(*__first1, *__first2))
121// 2+2 iterators, predicate, non-constant time `distance`.
122template <class _AlgPolicy,
123 class _Iter1, class _Sent1, class _Iter2, class _Sent2,
124 class _Proj1, class _Proj2, class _Pred>
125_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
126__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
127 _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
128 /*_ConstTimeDistance=*/false_type) {
129 // Shorten sequences as much as possible by lopping of any equal prefix.
130 while (__first1 != __last1 && __first2 != __last2) {
131 if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
86132 break;
133 ++__first1;
134 ++__first2;
135 }
136
87137 if (__first1 == __last1)
88138 return __first2 == __last2;
89 else if (__first2 == __last2)
139 if (__first2 == __last2) // Second range is shorter
90140 return false;
91141
92 typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
93 _D1 __l1 = _VSTD::distance(__first1, __last1);
142 using _D1 = __iter_diff_t<_Iter1>;
143 _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
94144
95 typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2;
96 _D2 __l2 = _VSTD::distance(__first2, __last2);
145 using _D2 = __iter_diff_t<_Iter2>;
146 _D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
97147 if (__l1 != __l2)
98148 return false;
99149
100 // For each element in [f1, l1) see if there are the same number of
101 // equal elements in [f2, l2)
102 for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) {
103 // Have we already counted the number of *__i in [f1, l1)?
104 _ForwardIterator1 __match = __first1;
105 for (; __match != __i; ++__match)
106 if (__pred(*__match, *__i))
107 break;
108 if (__match == __i) {
109 // Count number of *__i in [f2, l2)
110 _D1 __c2 = 0;
111 for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
112 if (__pred(*__i, *__j))
113 ++__c2;
114 if (__c2 == 0)
115 return false;
116 // Count number of *__i in [__i, l1) (we can start with 1)
117 _D1 __c1 = 1;
118 for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
119 if (__pred(*__i, *__j))
120 ++__c1;
121 if (__c1 != __c2)
122 return false;
123 }
124 }
125 return true;
150 return std::__is_permutation_impl<_AlgPolicy>(
151 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
152 __pred, __proj1, __proj2);
126153}
127154
128template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
129_LIBCPP_CONSTEXPR_AFTER_CXX17 bool __is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1,
130 _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2,
131 _BinaryPredicate __pred, random_access_iterator_tag,
132 random_access_iterator_tag) {
133 if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
155// 2+2 iterators, predicate, specialization for constant-time `distance` call.
156template <class _AlgPolicy,
157 class _Iter1, class _Sent1, class _Iter2, class _Sent2,
158 class _Proj1, class _Proj2, class _Pred>
159_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
160__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
161 _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
162 /*_ConstTimeDistance=*/true_type) {
163 if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
134164 return false;
135 return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
136 _BinaryPredicate&>(__first1, __last1, __first2, __pred);
165 return std::__is_permutation<_AlgPolicy>(
166 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
167 __pred, __proj1, __proj2,
168 /*_ConstTimeDistance=*/false_type());
169}
170
171// 2+2 iterators, predicate
172template <class _AlgPolicy,
173 class _Iter1, class _Sent1, class _Iter2, class _Sent2,
174 class _Proj1, class _Proj2, class _Pred>
175_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
176__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
177 _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
178 return std::__is_permutation<_AlgPolicy>(
179 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
180 __pred, __proj1, __proj2,
181 _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>());
137182}
138183
184// Public interface
185
186// 2+1 iterators, predicate
139187template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
140_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
188_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
141189is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
142 _ForwardIterator2 __last2, _BinaryPredicate __pred) {
143 return _VSTD::__is_permutation<_BinaryPredicate&>(
144 __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
145 typename iterator_traits<_ForwardIterator2>::iterator_category());
190 _BinaryPredicate __pred) {
191 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
192 "The predicate has to be callable");
193
194 return std::__is_permutation<_ClassicAlgPolicy>(
195 std::move(__first1), std::move(__last1), std::move(__first2), __pred);
146196}
147197
198// 2+1 iterators
199template <class _ForwardIterator1, class _ForwardIterator2>
200_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
201is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
202 using __v1 = __iter_value_type<_ForwardIterator1>;
203 using __v2 = __iter_value_type<_ForwardIterator2>;
204 return std::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
205}
206
207#if _LIBCPP_STD_VER > 11
208
209// 2+2 iterators
148210template <class _ForwardIterator1, class _ForwardIterator2>
149_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
211_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
150212is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
151213 _ForwardIterator2 __last2) {
152 typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
153 typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
154 return _VSTD::__is_permutation(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(),
155 typename iterator_traits<_ForwardIterator1>::iterator_category(),
156 typename iterator_traits<_ForwardIterator2>::iterator_category());
214 using __v1 = __iter_value_type<_ForwardIterator1>;
215 using __v2 = __iter_value_type<_ForwardIterator2>;
216
217 return std::__is_permutation<_ClassicAlgPolicy>(
218 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
219 __equal_to<__v1, __v2>(), __identity(), __identity());
157220}
158#endif
221
222// 2+2 iterators, predicate
223template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
224_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
225is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
226 _ForwardIterator2 __last2, _BinaryPredicate __pred) {
227 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
228 "The predicate has to be callable");
229
230 return std::__is_permutation<_ClassicAlgPolicy>(
231 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
232 __pred, __identity(), __identity());
233}
234
235#endif // _LIBCPP_STD_VER > 11
159236
160237_LIBCPP_END_NAMESPACE_STD
161238
lib/libcxx/include/__algorithm/iterator_operations.h+25-1
......@@ -10,13 +10,16 @@
1010#define _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
1111
1212#include <__algorithm/iter_swap.h>
13#include <__algorithm/ranges_iterator_concept.h>
1314#include <__config>
1415#include <__iterator/advance.h>
1516#include <__iterator/distance.h>
17#include <__iterator/incrementable_traits.h>
1618#include <__iterator/iter_move.h>
1719#include <__iterator/iter_swap.h>
1820#include <__iterator/iterator_traits.h>
1921#include <__iterator/next.h>
22#include <__iterator/prev.h>
2023#include <__iterator/readable_traits.h>
2124#include <__utility/declval.h>
2225#include <__utility/forward.h>
......@@ -40,11 +43,18 @@ struct _IterOps<_RangeAlgPolicy> {
4043 template <class _Iter>
4144 using __value_type = iter_value_t<_Iter>;
4245
46 template <class _Iter>
47 using __iterator_category = ranges::__iterator_concept<_Iter>;
48
49 template <class _Iter>
50 using __difference_type = iter_difference_t<_Iter>;
51
4352 static constexpr auto advance = ranges::advance;
4453 static constexpr auto distance = ranges::distance;
4554 static constexpr auto __iter_move = ranges::iter_move;
4655 static constexpr auto iter_swap = ranges::iter_swap;
4756 static constexpr auto next = ranges::next;
57 static constexpr auto prev = ranges::prev;
4858 static constexpr auto __advance_to = ranges::advance;
4959};
5060
......@@ -58,6 +68,12 @@ struct _IterOps<_ClassicAlgPolicy> {
5868 template <class _Iter>
5969 using __value_type = typename iterator_traits<_Iter>::value_type;
6070
71 template <class _Iter>
72 using __iterator_category = typename iterator_traits<_Iter>::iterator_category;
73
74 template <class _Iter>
75 using __difference_type = typename iterator_traits<_Iter>::difference_type;
76
6177 // advance
6278 template <class _Iter, class _Distance>
6379 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -132,10 +148,18 @@ struct _IterOps<_ClassicAlgPolicy> {
132148 template <class _Iter>
133149 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
134150 __uncvref_t<_Iter> next(_Iter&& __it,
135 typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1){
151 typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) {
136152 return std::next(std::forward<_Iter>(__it), __n);
137153 }
138154
155 // prev
156 template <class _Iter>
157 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
158 __uncvref_t<_Iter> prev(_Iter&& __iter,
159 typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) {
160 return std::prev(std::forward<_Iter>(__iter), __n);
161 }
162
139163 template <class _Iter>
140164 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
141165 void __advance_to(_Iter& __first, _Iter __last) {
lib/libcxx/include/__algorithm/move.h+15-11
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_H
1010#define _LIBCPP___ALGORITHM_MOVE_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__algorithm/unwrap_iter.h>
1314#include <__config>
1415#include <__iterator/iterator_traits.h>
......@@ -26,18 +27,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2627
2728// move
2829
29template <class _InIter, class _Sent, class _OutIter>
30template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
3031inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3132pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
3233 while (__first != __last) {
33 *__result = std::move(*__first);
34 *__result = _IterOps<_AlgPolicy>::__iter_move(__first);
3435 ++__first;
3536 ++__result;
3637 }
3738 return std::make_pair(std::move(__first), std::move(__result));
3839}
3940
40template <class _InType,
41template <class _AlgPolicy,
42 class _InType,
4143 class _OutType,
4244 class = __enable_if_t<is_same<typename remove_const<_InType>::type, _OutType>::value
4345 && is_trivially_move_assignable<_OutType>::value> >
......@@ -49,7 +51,7 @@ pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutTyp
4951 && !is_trivially_copyable<_InType>::value
5052#endif
5153 )
52 return std::__move_impl<_InType*, _InType*, _OutType*>(__first, __last, __result);
54 return std::__move_impl<_AlgPolicy, _InType*, _InType*, _OutType*>(__first, __last, __result);
5355 const size_t __n = static_cast<size_t>(__last - __first);
5456 ::__builtin_memmove(__result, __first, __n * sizeof(_OutType));
5557 return std::make_pair(__first + __n, __result + __n);
......@@ -65,7 +67,8 @@ template <class _Iter>
6567struct __is_trivially_move_assignable_unwrapped
6668 : __is_trivially_move_assignable_unwrapped_impl<decltype(std::__unwrap_iter<_Iter>(std::declval<_Iter>()))> {};
6769
68template <class _InIter,
70template <class _AlgPolicy,
71 class _InIter,
6972 class _OutIter,
7073 __enable_if_t<is_same<typename remove_const<typename iterator_traits<_InIter>::value_type>::type,
7174 typename iterator_traits<_OutIter>::value_type>::value
......@@ -81,33 +84,34 @@ __move_impl(reverse_iterator<_InIter> __first,
8184 auto __last_base = std::__unwrap_iter(__last.base());
8285 auto __result_base = std::__unwrap_iter(__result.base());
8386 auto __result_first = __result_base - (__first_base - __last_base);
84 std::__move_impl(__last_base, __first_base, __result_first);
87 std::__move_impl<_AlgPolicy>(__last_base, __first_base, __result_first);
8588 return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first)));
8689}
8790
88template <class _InIter, class _Sent, class _OutIter>
91template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
8992inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
9093__enable_if_t<is_copy_constructible<_InIter>::value
9194 && is_copy_constructible<_Sent>::value
9295 && is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
9396__move(_InIter __first, _Sent __last, _OutIter __result) {
94 auto __ret = std::__move_impl(std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result));
97 auto __ret = std::__move_impl<_AlgPolicy>(
98 std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result));
9599 return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
96100}
97101
98template <class _InIter, class _Sent, class _OutIter>
102template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
99103inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
100104__enable_if_t<!is_copy_constructible<_InIter>::value
101105 || !is_copy_constructible<_Sent>::value
102106 || !is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
103107__move(_InIter __first, _Sent __last, _OutIter __result) {
104 return std::__move_impl(std::move(__first), std::move(__last), std::move(__result));
108 return std::__move_impl<_AlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
105109}
106110
107111template <class _InputIterator, class _OutputIterator>
108112inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
109113_OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
110 return std::__move(__first, __last, __result).second;
114 return std::__move<_ClassicAlgPolicy>(__first, __last, __result).second;
111115}
112116
113117_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/move_backward.h+24-14
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1010#define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__algorithm/unwrap_iter.h>
1314#include <__config>
1415#include <__utility/move.h>
......@@ -21,25 +22,25 @@
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324
24template <class _InputIterator, class _OutputIterator>
25template <class _AlgPolicy, class _InputIterator, class _OutputIterator>
2526inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2627_OutputIterator
2728__move_backward_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
2829{
2930 while (__first != __last)
30 *--__result = _VSTD::move(*--__last);
31 *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last);
3132 return __result;
3233}
3334
34template <class _InputIterator, class _OutputIterator>
35template <class _AlgPolicy, class _InputIterator, class _OutputIterator>
3536inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3637_OutputIterator
37__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
38__move_backward_impl(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
3839{
39 return _VSTD::__move_backward_constexpr(__first, __last, __result);
40 return _VSTD::__move_backward_constexpr<_AlgPolicy>(__first, __last, __result);
4041}
4142
42template <class _Tp, class _Up>
43template <class _AlgPolicy, class _Tp, class _Up>
4344inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
4445typename enable_if
4546<
......@@ -47,7 +48,7 @@ typename enable_if
4748 is_trivially_move_assignable<_Up>::value,
4849 _Up*
4950>::type
50__move_backward(_Tp* __first, _Tp* __last, _Up* __result)
51__move_backward_impl(_Tp* __first, _Tp* __last, _Up* __result)
5152{
5253 const size_t __n = static_cast<size_t>(__last - __first);
5354 if (__n > 0)
......@@ -58,22 +59,31 @@ __move_backward(_Tp* __first, _Tp* __last, _Up* __result)
5859 return __result;
5960}
6061
61template <class _BidirectionalIterator1, class _BidirectionalIterator2>
62template <class _AlgPolicy, class _BidirectionalIterator1, class _BidirectionalIterator2>
6263inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
6364_BidirectionalIterator2
64move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
65 _BidirectionalIterator2 __result)
65__move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
66 _BidirectionalIterator2 __result)
6667{
6768 if (__libcpp_is_constant_evaluated()) {
68 return _VSTD::__move_backward_constexpr(__first, __last, __result);
69 return _VSTD::__move_backward_constexpr<_AlgPolicy>(__first, __last, __result);
6970 } else {
7071 return _VSTD::__rewrap_iter(__result,
71 _VSTD::__move_backward(_VSTD::__unwrap_iter(__first),
72 _VSTD::__unwrap_iter(__last),
73 _VSTD::__unwrap_iter(__result)));
72 _VSTD::__move_backward_impl<_AlgPolicy>(_VSTD::__unwrap_iter(__first),
73 _VSTD::__unwrap_iter(__last),
74 _VSTD::__unwrap_iter(__result)));
7475 }
7576}
7677
78template <class _BidirectionalIterator1, class _BidirectionalIterator2>
79inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
80_BidirectionalIterator2
81move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
82 _BidirectionalIterator2 __result)
83{
84 return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
85}
86
7787_LIBCPP_END_NAMESPACE_STD
7888
7989#endif // _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
lib/libcxx/include/__algorithm/next_permutation.h+22-14
......@@ -11,10 +11,12 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/reverse.h>
1516#include <__config>
1617#include <__iterator/iterator_traits.h>
17#include <__utility/swap.h>
18#include <__utility/move.h>
19#include <__utility/pair.h>
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2022# pragma GCC system_header
......@@ -22,29 +24,34 @@
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
2426
25template <class _Compare, class _BidirectionalIterator>
26_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
27__next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
27template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
28_LIBCPP_CONSTEXPR_AFTER_CXX17
29pair<_BidirectionalIterator, bool>
30__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
2831{
29 _BidirectionalIterator __i = __last;
32 using _Result = pair<_BidirectionalIterator, bool>;
33
34 _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
35 _BidirectionalIterator __i = __last_iter;
3036 if (__first == __last || __first == --__i)
31 return false;
37 return _Result(std::move(__last_iter), false);
38
3239 while (true)
3340 {
3441 _BidirectionalIterator __ip1 = __i;
3542 if (__comp(*--__i, *__ip1))
3643 {
37 _BidirectionalIterator __j = __last;
44 _BidirectionalIterator __j = __last_iter;
3845 while (!__comp(*__i, *--__j))
3946 ;
40 swap(*__i, *__j);
41 _VSTD::reverse(__ip1, __last);
42 return true;
47 _IterOps<_AlgPolicy>::iter_swap(__i, __j);
48 std::__reverse<_AlgPolicy>(__ip1, __last_iter);
49 return _Result(std::move(__last_iter), true);
4350 }
4451 if (__i == __first)
4552 {
46 _VSTD::reverse(__first, __last);
47 return false;
53 std::__reverse<_AlgPolicy>(__first, __last_iter);
54 return _Result(std::move(__last_iter), false);
4855 }
4956 }
5057}
......@@ -54,8 +61,9 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5461bool
5562next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
5663{
57 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
58 return _VSTD::__next_permutation<_Comp_ref>(__first, __last, __comp);
64 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
65 return std::__next_permutation<_ClassicAlgPolicy>(
66 std::move(__first), std::move(__last), static_cast<_Comp_ref>(__comp)).second;
5967}
6068
6169template <class _BidirectionalIterator>
lib/libcxx/include/__algorithm/prev_permutation.h+22-14
......@@ -11,10 +11,12 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/reverse.h>
1516#include <__config>
1617#include <__iterator/iterator_traits.h>
17#include <__utility/swap.h>
18#include <__utility/move.h>
19#include <__utility/pair.h>
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2022# pragma GCC system_header
......@@ -22,29 +24,34 @@
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
2426
25template <class _Compare, class _BidirectionalIterator>
26_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
27__prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
27template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
28_LIBCPP_CONSTEXPR_AFTER_CXX17
29pair<_BidirectionalIterator, bool>
30__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
2831{
29 _BidirectionalIterator __i = __last;
32 using _Result = pair<_BidirectionalIterator, bool>;
33
34 _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
35 _BidirectionalIterator __i = __last_iter;
3036 if (__first == __last || __first == --__i)
31 return false;
37 return _Result(std::move(__last_iter), false);
38
3239 while (true)
3340 {
3441 _BidirectionalIterator __ip1 = __i;
3542 if (__comp(*__ip1, *--__i))
3643 {
37 _BidirectionalIterator __j = __last;
44 _BidirectionalIterator __j = __last_iter;
3845 while (!__comp(*--__j, *__i))
3946 ;
40 swap(*__i, *__j);
41 _VSTD::reverse(__ip1, __last);
42 return true;
47 _IterOps<_AlgPolicy>::iter_swap(__i, __j);
48 std::__reverse<_AlgPolicy>(__ip1, __last_iter);
49 return _Result(std::move(__last_iter), true);
4350 }
4451 if (__i == __first)
4552 {
46 _VSTD::reverse(__first, __last);
47 return false;
53 std::__reverse<_AlgPolicy>(__first, __last_iter);
54 return _Result(std::move(__last_iter), false);
4855 }
4956 }
5057}
......@@ -54,8 +61,9 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5461bool
5562prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
5663{
57 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
58 return _VSTD::__prev_permutation<_Comp_ref>(__first, __last, __comp);
64 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
65 return std::__prev_permutation<_ClassicAlgPolicy>(
66 std::move(__first), std::move(__last), static_cast<_Comp_ref>(__comp)).second;
5967}
6068
6169template <class _BidirectionalIterator>
lib/libcxx/include/__algorithm/ranges_clamp.h created+65
......@@ -0,0 +1,65 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_CLAMP_H
10#define _LIBCPP___ALGORITHM_RANGES_CLAMP_H
11
12#include <__assert>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/projected.h>
19#include <__utility/forward.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30namespace __clamp {
31struct __fn {
32
33 template <class _Type,
34 class _Proj = identity,
35 indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
36 _LIBCPP_HIDE_FROM_ABI constexpr
37 const _Type& operator()(const _Type& __value,
38 const _Type& __low,
39 const _Type& __high,
40 _Comp __comp = {},
41 _Proj __proj = {}) const {
42 _LIBCPP_ASSERT(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
43 "Bad bounds passed to std::ranges::clamp");
44
45 if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, __low)))
46 return __low;
47 else if (std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __value)))
48 return __high;
49 else
50 return __value;
51 }
52
53};
54} // namespace __clamp
55
56inline namespace __cpo {
57 inline constexpr auto clamp = __clamp::__fn{};
58} // namespace __cpo
59} // namespace ranges
60
61_LIBCPP_END_NAMESPACE_STD
62
63#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
64
65#endif // _LIBCPP___ALGORITHM_RANGES_CLAMP_H
lib/libcxx/include/__algorithm/ranges_is_permutation.h created+89
......@@ -0,0 +1,89 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H
10#define _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H
11
12#include <__algorithm/is_permutation.h>
13#include <__algorithm/iterator_operations.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/distance.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __is_permutation {
34struct __fn {
35
36 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2,
37 class _Proj1, class _Proj2, class _Pred>
38 _LIBCPP_HIDE_FROM_ABI constexpr static
39 bool __is_permutation_func_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
40 _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
41 return std::__is_permutation<_RangeAlgPolicy>(
42 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
43 __pred, __proj1, __proj2);
44 }
45
46 template <forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
47 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
48 class _Proj1 = identity,
49 class _Proj2 = identity,
50 indirect_equivalence_relation<projected<_Iter1, _Proj1>,
51 projected<_Iter2, _Proj2>> _Pred = ranges::equal_to>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 bool operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
54 _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
55 return __is_permutation_func_impl(
56 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
57 __pred, __proj1, __proj2);
58 }
59
60 template <forward_range _Range1,
61 forward_range _Range2,
62 class _Proj1 = identity,
63 class _Proj2 = identity,
64 indirect_equivalence_relation<projected<iterator_t<_Range1>, _Proj1>, projected<iterator_t<_Range2>, _Proj2>> _Pred = ranges::equal_to>
65 _LIBCPP_HIDE_FROM_ABI constexpr
66 bool operator()(_Range1&& __range1, _Range2&& __range2,
67 _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
68 if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
69 if (ranges::distance(__range1) != ranges::distance(__range2))
70 return false;
71 }
72
73 return __is_permutation_func_impl(
74 ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), ranges::end(__range2),
75 __pred, __proj1, __proj2);
76 }
77};
78} // namespace __is_permutation
79
80inline namespace __cpo {
81 inline constexpr auto is_permutation = __is_permutation::__fn{};
82} // namespace __cpo
83} // namespace ranges
84
85_LIBCPP_END_NAMESPACE_STD
86
87#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
88
89#endif // _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H
lib/libcxx/include/__algorithm/ranges_move.h+2-13
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___ALGORITHM_RANGES_MOVE_H
1111
1212#include <__algorithm/in_out_result.h>
13#include <__algorithm/iterator_operations.h>
1314#include <__algorithm/move.h>
1415#include <__config>
1516#include <__iterator/concepts.h>
......@@ -36,24 +37,12 @@ namespace __move {
3637struct __fn {
3738
3839 template <class _InIter, class _Sent, class _OutIter>
39 requires __iter_move::__move_deref<_InIter> // check that we are allowed to std::move() the value
4040 _LIBCPP_HIDE_FROM_ABI constexpr static
4141 move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
42 auto __ret = std::__move(std::move(__first), std::move(__last), std::move(__result));
42 auto __ret = std::__move<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
4343 return {std::move(__ret.first), std::move(__ret.second)};
4444 }
4545
46 template <class _InIter, class _Sent, class _OutIter>
47 _LIBCPP_HIDE_FROM_ABI constexpr static
48 move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
49 while (__first != __last) {
50 *__result = ranges::iter_move(__first);
51 ++__first;
52 ++__result;
53 }
54 return {std::move(__first), std::move(__result)};
55 }
56
5746 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
5847 requires indirectly_movable<_InIter, _OutIter>
5948 _LIBCPP_HIDE_FROM_ABI constexpr
lib/libcxx/include/__algorithm/ranges_move_backward.h+3-2
......@@ -40,10 +40,11 @@ struct __fn {
4040 template <class _InIter, class _Sent, class _OutIter>
4141 _LIBCPP_HIDE_FROM_ABI constexpr static
4242 move_backward_result<_InIter, _OutIter> __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) {
43 auto __ret = ranges::move(std::make_reverse_iterator(ranges::next(__first, __last)),
43 auto __last_iter = ranges::next(__first, std::move(__last));
44 auto __ret = ranges::move(std::make_reverse_iterator(__last_iter),
4445 std::make_reverse_iterator(__first),
4546 std::make_reverse_iterator(__result));
46 return {std::move(__ret.in.base()), std::move(__ret.out.base())};
47 return {std::move(__last_iter), std::move(__ret.out.base())};
4748 }
4849
4950 template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, bidirectional_iterator _OutIter>
lib/libcxx/include/__algorithm/ranges_next_permutation.h created+72
......@@ -0,0 +1,72 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H
10#define _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H
11
12#include <__algorithm/in_found_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__algorithm/next_permutation.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/sortable.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36template <class _InIter>
37using next_permutation_result = in_found_result<_InIter>;
38
39namespace __next_permutation {
40
41struct __fn {
42 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
43 requires sortable<_Iter, _Comp, _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result<_Iter>
45 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
46 auto __result = std::__next_permutation<_RangeAlgPolicy>(
47 std::move(__first), std::move(__last), std::__make_projected(__comp, __proj));
48 return {std::move(__result.first), std::move(__result.second)};
49 }
50
51 template <bidirectional_range _Range, class _Comp = ranges::less, class _Proj = identity>
52 requires sortable<iterator_t<_Range>, _Comp, _Proj>
53 _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result<borrowed_iterator_t<_Range>>
54 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
55 auto __result = std::__next_permutation<_RangeAlgPolicy>(
56 ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj));
57 return {std::move(__result.first), std::move(__result.second)};
58 }
59};
60
61} // namespace __next_permutation
62
63inline namespace __cpo {
64constexpr inline auto next_permutation = __next_permutation::__fn{};
65} // namespace __cpo
66} // namespace ranges
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
71
72#endif // _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H
lib/libcxx/include/__algorithm/ranges_prev_permutation.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H
10#define _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H
11
12#include <__algorithm/in_found_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__algorithm/prev_permutation.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/sortable.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36template <class _InIter>
37using prev_permutation_result = in_found_result<_InIter>;
38
39namespace __prev_permutation {
40
41struct __fn {
42
43 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
44 class _Comp = ranges::less, class _Proj = identity>
45 requires sortable<_Iter, _Comp, _Proj>
46 _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<_Iter>
47 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
48 auto __result = std::__prev_permutation<_RangeAlgPolicy>(
49 std::move(__first), std::move(__last), std::__make_projected(__comp, __proj));
50 return {std::move(__result.first), std::move(__result.second)};
51 }
52
53 template <bidirectional_range _Range,
54 class _Comp = ranges::less, class _Proj = identity>
55 requires sortable<iterator_t<_Range>, _Comp, _Proj>
56 _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<borrowed_iterator_t<_Range>>
57 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
58 auto __result = std::__prev_permutation<_RangeAlgPolicy>(
59 ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj));
60 return {std::move(__result.first), std::move(__result.second)};
61 }
62
63};
64
65} // namespace __prev_permutation
66
67inline namespace __cpo {
68constexpr inline auto prev_permutation = __prev_permutation::__fn{};
69} // namespace __cpo
70} // namespace ranges
71
72_LIBCPP_END_NAMESPACE_STD
73
74#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
75
76#endif // _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H
lib/libcxx/include/__algorithm/ranges_remove_copy.h+25-30
......@@ -10,19 +10,16 @@
1010#define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H
1111
1212#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/remove_copy.h>
13#include <__algorithm/ranges_remove_copy_if.h>
1514#include <__config>
1615#include <__functional/identity.h>
1716#include <__functional/invoke.h>
1817#include <__functional/ranges_operations.h>
1918#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
2119#include <__iterator/projected.h>
2220#include <__ranges/access.h>
2321#include <__ranges/concepts.h>
2422#include <__ranges/dangling.h>
25#include <__utility/forward.h>
2623#include <__utility/move.h>
2724
2825#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -40,32 +37,30 @@ using remove_copy_result = in_out_result<_InIter, _OutIter>;
4037
4138namespace __remove_copy {
4239
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter, class _Type,
46 class _Proj = identity>
47 requires indirectly_copyable<_InIter, _OutIter> &&
48 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type*>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 remove_copy_result<_InIter, _OutIter>
51 operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
52 // TODO: implement
53 (void)__first; (void)__last; (void)__result; (void)__value; (void)__proj;
54 return {};
55 }
56
57 template <input_range _Range, weakly_incrementable _OutIter, class _Type, class _Proj = identity>
58 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
59 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 remove_copy_result<borrowed_iterator_t<_Range>, _OutIter>
62 operator()(_Range&& __range, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
63 // TODO: implement
64 (void)__range; (void)__result; (void)__value; (void)__proj;
65 return {};
66 }
67
68};
40 struct __fn {
41 template <input_iterator _InIter,
42 sentinel_for<_InIter> _Sent,
43 weakly_incrementable _OutIter,
44 class _Type,
45 class _Proj = identity>
46 requires indirectly_copyable<_InIter, _OutIter> &&
47 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type*>
48 _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result<_InIter, _OutIter>
49 operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
50 auto __pred = [&](auto&& __val) { return __value == __val; };
51 return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
52 }
53
54 template <input_range _Range, weakly_incrementable _OutIter, class _Type, class _Proj = identity>
55 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
56 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
57 _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result<borrowed_iterator_t<_Range>, _OutIter>
58 operator()(_Range&& __range, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
59 auto __pred = [&](auto&& __val) { return __value == __val; };
60 return ranges::__remove_copy_if_impl(
61 ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj);
62 }
63 };
6964
7065} // namespace __remove_copy
7166
lib/libcxx/include/__algorithm/ranges_remove_copy_if.h+34-24
......@@ -38,33 +38,43 @@ namespace ranges {
3838template <class _InIter, class _OutIter>
3939using remove_copy_if_result = in_out_result<_InIter, _OutIter>;
4040
41namespace __remove_copy_if {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter,
46 class _Proj = identity, indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
47 requires indirectly_copyable<_InIter, _OutIter>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 remove_copy_if_result<_InIter, _OutIter>
50 operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
51 // TODO: implement
52 (void)__first; (void)__last; (void)__result; (void)__pred; (void)__proj;
53 return {};
41template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
42_LIBCPP_HIDE_FROM_ABI constexpr in_out_result<_InIter, _OutIter>
43__remove_copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
44 for (; __first != __last; ++__first) {
45 if (!std::invoke(__pred, std::invoke(__proj, *__first))) {
46 *__result = *__first;
47 ++__result;
48 }
5449 }
50 return {std::move(__first), std::move(__result)};
51}
5552
56 template <input_range _Range, weakly_incrementable _OutIter, class _Proj = identity,
57 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
58 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 remove_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
61 operator()(_Range&& __range, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
62 // TODO: implement
63 (void)__range; (void)__result; (void)__pred; (void)__proj;
64 return {};
65 }
53namespace __remove_copy_if {
6654
67};
55 struct __fn {
56 template <input_iterator _InIter,
57 sentinel_for<_InIter> _Sent,
58 weakly_incrementable _OutIter,
59 class _Proj = identity,
60 indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
61 requires indirectly_copyable<_InIter, _OutIter>
62 _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result<_InIter, _OutIter>
63 operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
64 return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
65 }
66
67 template <input_range _Range,
68 weakly_incrementable _OutIter,
69 class _Proj = identity,
70 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
71 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
72 _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
73 operator()(_Range&& __range, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
74 return ranges::__remove_copy_if_impl(
75 ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj);
76 }
77 };
6878
6979} // namespace __remove_copy_if
7080
lib/libcxx/include/__algorithm/ranges_replace_copy.h+38-31
......@@ -10,19 +10,16 @@
1010#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H
1111
1212#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/replace_copy.h>
13#include <__algorithm/ranges_replace_copy_if.h>
1514#include <__config>
1615#include <__functional/identity.h>
1716#include <__functional/invoke.h>
1817#include <__functional/ranges_operations.h>
1918#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
2119#include <__iterator/projected.h>
2220#include <__ranges/access.h>
2321#include <__ranges/concepts.h>
2422#include <__ranges/dangling.h>
25#include <__utility/forward.h>
2623#include <__utility/move.h>
2724
2825#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -40,35 +37,45 @@ using replace_copy_result = in_out_result<_InIter, _OutIter>;
4037
4138namespace __replace_copy {
4239
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, class _Type1, class _Type2,
46 output_iterator<const _Type2&> _OutIter, class _Proj = identity>
47 requires indirectly_copyable<_InIter, _OutIter> &&
48 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type1*>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 replace_copy_result<_InIter, _OutIter>
51 operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type1& __old_value, const _Type2& __new_value,
40 struct __fn {
41 template <input_iterator _InIter,
42 sentinel_for<_InIter> _Sent,
43 class _OldType,
44 class _NewType,
45 output_iterator<const _NewType&> _OutIter,
46 class _Proj = identity>
47 requires indirectly_copyable<_InIter, _OutIter> &&
48 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _OldType*>
49 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<_InIter, _OutIter>
50 operator()(_InIter __first,
51 _Sent __last,
52 _OutIter __result,
53 const _OldType& __old_value,
54 const _NewType& __new_value,
5255 _Proj __proj = {}) const {
53 // TODO: implement
54 (void)__first; (void)__last; (void)__result; (void)__old_value; (void)__new_value; (void)__proj;
55 return {};
56 }
57
58 template <input_range _Range, class _Type1, class _Type2, output_iterator<const _Type2&> _OutIter,
59 class _Proj = identity>
60 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
61 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type1*>
62 _LIBCPP_HIDE_FROM_ABI constexpr
63 replace_copy_result<borrowed_iterator_t<_Range>, _OutIter>
64 operator()(_Range&& __range, _OutIter __result, const _Type1& __old_value, const _Type2& __new_value,
56 auto __pred = [&](const auto& __value) { return __value == __old_value; };
57 return ranges::__replace_copy_if_impl(
58 std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj);
59 }
60
61 template <input_range _Range,
62 class _OldType,
63 class _NewType,
64 output_iterator<const _NewType&> _OutIter,
65 class _Proj = identity>
66 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
67 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _OldType*>
68 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<borrowed_iterator_t<_Range>, _OutIter>
69 operator()(_Range&& __range,
70 _OutIter __result,
71 const _OldType& __old_value,
72 const _NewType& __new_value,
6573 _Proj __proj = {}) const {
66 // TODO: implement
67 (void)__range; (void)__result; (void)__old_value; (void)__new_value; (void)__proj;
68 return {};
69 }
70
71};
74 auto __pred = [&](const auto& __value) { return __value == __old_value; };
75 return ranges::__replace_copy_if_impl(
76 ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj);
77 }
78 };
7279
7380} // namespace __replace_copy
7481
lib/libcxx/include/__algorithm/ranges_replace_copy_if.h+42-30
......@@ -10,19 +10,14 @@
1010#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
1111
1212#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/replace_copy_if.h>
1513#include <__config>
1614#include <__functional/identity.h>
1715#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
1916#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
2117#include <__iterator/projected.h>
2218#include <__ranges/access.h>
2319#include <__ranges/concepts.h>
2420#include <__ranges/dangling.h>
25#include <__utility/forward.h>
2621#include <__utility/move.h>
2722
2823#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -38,34 +33,51 @@ namespace ranges {
3833template <class _InIter, class _OutIter>
3934using replace_copy_if_result = in_out_result<_InIter, _OutIter>;
4035
41namespace __replace_copy_if {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, class _Type, output_iterator<const _Type&> _OutIter,
46 class _Proj = identity, indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
47 requires indirectly_copyable<_InIter, _OutIter>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 replace_copy_if_result<_InIter, _OutIter>
50 operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value,
51 _Proj __proj = {}) const {
52 // TODO: implement
53 (void)__first; (void)__last; (void)__result; (void)__pred; (void)__new_value; (void)__proj;
54 return {};
36template <class _InIter, class _Sent, class _OutIter, class _Pred, class _Type, class _Proj>
37_LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> __replace_copy_if_impl(
38 _InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, const _Type& __new_value, _Proj& __proj) {
39 while (__first != __last) {
40 if (std::invoke(__pred, std::invoke(__proj, *__first)))
41 *__result = __new_value;
42 else
43 *__result = *__first;
44
45 ++__first;
46 ++__result;
5547 }
5648
57 template <input_range _Range, class _Type, output_iterator<const _Type&> _OutIter, class _Proj = identity,
58 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
59 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 replace_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
62 operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
63 // TODO: implement
64 (void)__range; (void)__result; (void)__pred; (void)__new_value; (void)__proj;
65 return {};
66 }
49 return {std::move(__first), std::move(__result)};
50}
51
52namespace __replace_copy_if {
6753
68};
54 struct __fn {
55 template <input_iterator _InIter,
56 sentinel_for<_InIter> _Sent,
57 class _Type,
58 output_iterator<const _Type&> _OutIter,
59 class _Proj = identity,
60 indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
61 requires indirectly_copyable<_InIter, _OutIter>
62 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> operator()(
63 _InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {})
64 const {
65 return ranges::__replace_copy_if_impl(
66 std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj);
67 }
68
69 template <input_range _Range,
70 class _Type,
71 output_iterator<const _Type&> _OutIter,
72 class _Proj = identity,
73 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
74 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
75 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
76 operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
77 return ranges::__replace_copy_if_impl(
78 ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj);
79 }
80 };
6981
7082} // namespace __replace_copy_if
7183
lib/libcxx/include/__algorithm/ranges_rotate.h created+71
......@@ -0,0 +1,71 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H
10#define _LIBCPP___ALGORITHM_RANGES_ROTATE_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/ranges_iterator_concept.h>
14#include <__algorithm/rotate.h>
15#include <__config>
16#include <__iterator/concepts.h>
17#include <__iterator/iterator_traits.h>
18#include <__iterator/permutable.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/subrange.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __rotate {
34
35struct __fn {
36
37 template <class _Iter, class _Sent>
38 _LIBCPP_HIDE_FROM_ABI constexpr
39 static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
40 auto __ret = std::__rotate<_RangeAlgPolicy>(
41 std::move(__first), std::move(__middle), std::move(__last));
42 return {std::move(__ret.first), std::move(__ret.second)};
43 }
44
45 template <permutable _Iter, sentinel_for<_Iter> _Sent>
46 _LIBCPP_HIDE_FROM_ABI constexpr
47 subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const {
48 return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last));
49 }
50
51 template <forward_range _Range>
52 requires permutable<iterator_t<_Range>>
53 _LIBCPP_HIDE_FROM_ABI constexpr
54 borrowed_subrange_t<_Range> operator()(_Range&& __range, iterator_t<_Range> __middle) const {
55 return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range));
56 }
57
58};
59
60} // namespace __rotate
61
62inline namespace __cpo {
63 inline constexpr auto rotate = __rotate::__fn{};
64} // namespace __cpo
65} // namespace ranges
66
67_LIBCPP_END_NAMESPACE_STD
68
69#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
70
71#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H
lib/libcxx/include/__algorithm/ranges_sample.h created+74
......@@ -0,0 +1,74 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
10#define _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/sample.h>
14#include <__algorithm/uniform_random_bit_generator_adaptor.h>
15#include <__config>
16#include <__iterator/concepts.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iterator_traits.h>
19#include <__random/uniform_random_bit_generator.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__utility/forward.h>
23#include <__utility/move.h>
24#include <type_traits>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35namespace __sample {
36
37struct __fn {
38
39 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Gen>
40 requires (forward_iterator<_Iter> || random_access_iterator<_OutIter>) &&
41 indirectly_copyable<_Iter, _OutIter> &&
42 uniform_random_bit_generator<remove_reference_t<_Gen>>
43 _LIBCPP_HIDE_FROM_ABI
44 _OutIter operator()(_Iter __first, _Sent __last,
45 _OutIter __out_first, iter_difference_t<_Iter> __n, _Gen&& __gen) const {
46 _ClassicGenAdaptor<_Gen> __adapted_gen(__gen);
47 return std::__sample<_RangeAlgPolicy>(
48 std::move(__first), std::move(__last), std::move(__out_first), __n, __adapted_gen);
49 }
50
51 template <input_range _Range, weakly_incrementable _OutIter, class _Gen>
52 requires (forward_range<_Range> || random_access_iterator<_OutIter>) &&
53 indirectly_copyable<iterator_t<_Range>, _OutIter> &&
54 uniform_random_bit_generator<remove_reference_t<_Gen>>
55 _LIBCPP_HIDE_FROM_ABI
56 _OutIter operator()(_Range&& __range, _OutIter __out_first, range_difference_t<_Range> __n, _Gen&& __gen) const {
57 return (*this)(ranges::begin(__range), ranges::end(__range),
58 std::move(__out_first), __n, std::forward<_Gen>(__gen));
59 }
60
61};
62
63} // namespace __sample
64
65inline namespace __cpo {
66 inline constexpr auto sample = __sample::__fn{};
67} // namespace __cpo
68} // namespace ranges
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73
74#endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
lib/libcxx/include/__algorithm/ranges_shuffle.h+1-33
......@@ -11,6 +11,7 @@
1111
1212#include <__algorithm/iterator_operations.h>
1313#include <__algorithm/shuffle.h>
14#include <__algorithm/uniform_random_bit_generator_adaptor.h>
1415#include <__config>
1516#include <__functional/invoke.h>
1617#include <__functional/ranges_operations.h>
......@@ -32,43 +33,12 @@
3233
3334#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3435
35_LIBCPP_PUSH_MACROS
36#include <__undef_macros>
37
3836_LIBCPP_BEGIN_NAMESPACE_STD
3937
4038namespace ranges {
4139namespace __shuffle {
4240
4341struct __fn {
44 // `std::shuffle` is more constrained than `std::ranges::shuffle`. `std::ranges::shuffle` only requires the given
45 // generator to satisfy the `std::uniform_random_bit_generator` concept. `std::shuffle` requires the given
46 // generator to meet the uniform random bit generator requirements; these requirements include satisfying
47 // `std::uniform_random_bit_generator` and add a requirement for the generator to provide a nested `result_type`
48 // typedef (see `[rand.req.urng]`).
49 //
50 // To reuse the implementation from `std::shuffle`, make the given generator meet the classic requirements by wrapping
51 // it into an adaptor type that forwards all of its interface and adds the required typedef.
52 template <class _Gen>
53 class _ClassicGenAdaptor {
54 private:
55 // The generator is not required to be copyable or movable, so it has to be stored as a reference.
56 _Gen& __gen;
57
58 public:
59 using result_type = invoke_result_t<_Gen&>;
60
61 _LIBCPP_HIDE_FROM_ABI
62 static constexpr auto min() { return __uncvref_t<_Gen>::min(); }
63 _LIBCPP_HIDE_FROM_ABI
64 static constexpr auto max() { return __uncvref_t<_Gen>::max(); }
65
66 _LIBCPP_HIDE_FROM_ABI
67 constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen(__g) {}
68
69 _LIBCPP_HIDE_FROM_ABI
70 constexpr auto operator()() const { return __gen(); }
71 };
7242
7343 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Gen>
7444 requires permutable<_Iter> && uniform_random_bit_generator<remove_reference_t<_Gen>>
......@@ -96,8 +66,6 @@ inline namespace __cpo {
9666
9767_LIBCPP_END_NAMESPACE_STD
9868
99_LIBCPP_POP_MACROS
100
10169#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
10270
10371#endif // _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H
lib/libcxx/include/__algorithm/ranges_swap_ranges.h+5-6
......@@ -10,6 +10,8 @@
1010#define _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H
1111
1212#include <__algorithm/in_in_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/swap_ranges.h>
1315#include <__config>
1416#include <__iterator/concepts.h>
1517#include <__iterator/iter_swap.h>
......@@ -38,12 +40,9 @@ struct __fn {
3840 requires indirectly_swappable<_I1, _I2>
3941 _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2>
4042 operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2) const {
41 while (__first1 != __last1 && __first2 != __last2) {
42 ranges::iter_swap(__first1, __first2);
43 ++__first1;
44 ++__first2;
45 }
46 return {_VSTD::move(__first1), _VSTD::move(__first2)};
43 auto __ret = std::__swap_ranges<_RangeAlgPolicy>(
44 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2));
45 return {std::move(__ret.first), std::move(__ret.second)};
4746 }
4847
4948 template <input_range _R1, input_range _R2>
lib/libcxx/include/__algorithm/reverse.h+16-7
......@@ -10,8 +10,10 @@
1010#define _LIBCPP___ALGORITHM_REVERSE_H
1111
1212#include <__algorithm/iter_swap.h>
13#include <__algorithm/iterator_operations.h>
1314#include <__config>
1415#include <__iterator/iterator_traits.h>
16#include <__utility/move.h>
1517
1618#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1719# pragma GCC system_header
......@@ -19,28 +21,35 @@
1921
2022_LIBCPP_BEGIN_NAMESPACE_STD
2123
22template <class _BidirectionalIterator>
24template <class _AlgPolicy, class _BidirectionalIterator>
2325inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2426void
25__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
27__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
2628{
2729 while (__first != __last)
2830 {
2931 if (__first == --__last)
3032 break;
31 _VSTD::iter_swap(__first, __last);
33 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
3234 ++__first;
3335 }
3436}
3537
36template <class _RandomAccessIterator>
38template <class _AlgPolicy, class _RandomAccessIterator>
3739inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3840void
39__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
41__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
4042{
4143 if (__first != __last)
4244 for (; __first < --__last; ++__first)
43 _VSTD::iter_swap(__first, __last);
45 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
46}
47
48template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
49_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
50void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
51 using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>;
52 std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory());
4453}
4554
4655template <class _BidirectionalIterator>
......@@ -48,7 +57,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
4857void
4958reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
5059{
51 _VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category());
60 std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last));
5261}
5362
5463_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/rotate.h+32-25
......@@ -15,10 +15,8 @@
1515#include <__algorithm/swap_ranges.h>
1616#include <__config>
1717#include <__iterator/iterator_traits.h>
18#include <__iterator/next.h>
19#include <__iterator/prev.h>
2018#include <__utility/move.h>
21#include <__utility/swap.h>
19#include <__utility/pair.h>
2220#include <type_traits>
2321
2422#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -32,9 +30,11 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
3230__rotate_left(_ForwardIterator __first, _ForwardIterator __last)
3331{
3432 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
35 value_type __tmp = _IterOps<_AlgPolicy>::__iter_move(__first);
36 // TODO(ranges): pass `_AlgPolicy` to `move`.
37 _ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first);
33 using _Ops = _IterOps<_AlgPolicy>;
34
35 value_type __tmp = _Ops::__iter_move(__first);
36 _ForwardIterator __lm1 = std::__move<_AlgPolicy>(
37 _Ops::next(__first), __last, __first).second;
3838 *__lm1 = _VSTD::move(__tmp);
3939 return __lm1;
4040}
......@@ -44,11 +44,11 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _BidirectionalIterator
4444__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
4545{
4646 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
47 // TODO(ranges): pass `_AlgPolicy` to `prev`.
48 _BidirectionalIterator __lm1 = _VSTD::prev(__last);
49 value_type __tmp = _IterOps<_AlgPolicy>::__iter_move(__lm1);
50 // TODO(ranges): pass `_AlgPolicy` to `move_backward`.
51 _BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last);
47 using _Ops = _IterOps<_AlgPolicy>;
48
49 _BidirectionalIterator __lm1 = _Ops::prev(__last);
50 value_type __tmp = _Ops::__iter_move(__lm1);
51 _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last));
5252 *__first = _VSTD::move(__tmp);
5353 return __fp1;
5454}
......@@ -108,26 +108,26 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
108108{
109109 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
110110 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
111 using _Ops = _IterOps<_AlgPolicy>;
111112
112113 const difference_type __m1 = __middle - __first;
113 const difference_type __m2 = __last - __middle;
114 const difference_type __m2 = _Ops::distance(__middle, __last);
114115 if (__m1 == __m2)
115116 {
116 // TODO(ranges): pass `_AlgPolicy` to `swap_ranges`.
117 _VSTD::swap_ranges(__first, __middle, __middle);
117 std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last);
118118 return __middle;
119119 }
120120 const difference_type __g = _VSTD::__algo_gcd(__m1, __m2);
121121 for (_RandomAccessIterator __p = __first + __g; __p != __first;)
122122 {
123 value_type __t(_IterOps<_AlgPolicy>::__iter_move(--__p));
123 value_type __t(_Ops::__iter_move(--__p));
124124 _RandomAccessIterator __p1 = __p;
125125 _RandomAccessIterator __p2 = __p1 + __m1;
126126 do
127127 {
128 *__p1 = _IterOps<_AlgPolicy>::__iter_move(__p2);
128 *__p1 = _Ops::__iter_move(__p2);
129129 __p1 = __p2;
130 const difference_type __d = __last - __p2;
130 const difference_type __d = _Ops::distance(__p2, __last);
131131 if (__m1 < __d)
132132 __p2 += __m1;
133133 else
......@@ -188,16 +188,23 @@ __rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ra
188188 return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
189189}
190190
191template <class _AlgPolicy, class _RandomAccessIterator, class _IterCategory>
191template <class _AlgPolicy, class _Iterator, class _Sentinel>
192192_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
193_RandomAccessIterator __rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle,
194 _RandomAccessIterator __last, _IterCategory __iter_category) {
193pair<_Iterator, _Iterator>
194__rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) {
195 using _Ret = pair<_Iterator, _Iterator>;
196 _Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last);
197
195198 if (__first == __middle)
196 return __last;
199 return _Ret(__last_iter, __last_iter);
197200 if (__middle == __last)
198 return __first;
201 return _Ret(std::move(__first), std::move(__last_iter));
202
203 using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>;
204 auto __result = std::__rotate_impl<_AlgPolicy>(
205 std::move(__first), std::move(__middle), __last_iter, _IterCategory());
199206
200 return std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __iter_category);
207 return _Ret(std::move(__result), std::move(__last_iter));
201208}
202209
203210template <class _ForwardIterator>
......@@ -205,8 +212,8 @@ inline _LIBCPP_INLINE_VISIBILITY
205212_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
206213rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
207214{
208 return std::__rotate<_ClassicAlgPolicy>(__first, __middle, __last,
209 typename iterator_traits<_ForwardIterator>::iterator_category());
215 return std::__rotate<_ClassicAlgPolicy>(
216 std::move(__first), std::move(__middle), std::move(__last)).first;
210217}
211218
212219_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/sample.h+28-20
......@@ -9,12 +9,14 @@
99#ifndef _LIBCPP___ALGORITHM_SAMPLE_H
1010#define _LIBCPP___ALGORITHM_SAMPLE_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__algorithm/min.h>
1314#include <__assert>
1415#include <__config>
1516#include <__iterator/distance.h>
1617#include <__iterator/iterator_traits.h>
1718#include <__random/uniform_int_distribution.h>
19#include <__utility/move.h>
1820#include <type_traits>
1921
2022#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -26,13 +28,14 @@ _LIBCPP_PUSH_MACROS
2628
2729_LIBCPP_BEGIN_NAMESPACE_STD
2830
29template <class _PopulationIterator, class _SampleIterator, class _Distance,
31template <class _AlgPolicy,
32 class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
3033 class _UniformRandomNumberGenerator>
3134_LIBCPP_INLINE_VISIBILITY
3235_SampleIterator __sample(_PopulationIterator __first,
33 _PopulationIterator __last, _SampleIterator __output_iter,
36 _PopulationSentinel __last, _SampleIterator __output_iter,
3437 _Distance __n,
35 _UniformRandomNumberGenerator & __g,
38 _UniformRandomNumberGenerator& __g,
3639 input_iterator_tag) {
3740
3841 _Distance __k = 0;
......@@ -47,15 +50,16 @@ _SampleIterator __sample(_PopulationIterator __first,
4750 return __output_iter + _VSTD::min(__n, __k);
4851}
4952
50template <class _PopulationIterator, class _SampleIterator, class _Distance,
53template <class _AlgPolicy,
54 class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
5155 class _UniformRandomNumberGenerator>
5256_LIBCPP_INLINE_VISIBILITY
5357_SampleIterator __sample(_PopulationIterator __first,
54 _PopulationIterator __last, _SampleIterator __output_iter,
58 _PopulationSentinel __last, _SampleIterator __output_iter,
5559 _Distance __n,
5660 _UniformRandomNumberGenerator& __g,
5761 forward_iterator_tag) {
58 _Distance __unsampled_sz = _VSTD::distance(__first, __last);
62 _Distance __unsampled_sz = _IterOps<_AlgPolicy>::distance(__first, __last);
5963 for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) {
6064 _Distance __r = uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g);
6165 if (__r < __n) {
......@@ -66,24 +70,22 @@ _SampleIterator __sample(_PopulationIterator __first,
6670 return __output_iter;
6771}
6872
69template <class _PopulationIterator, class _SampleIterator, class _Distance,
73template <class _AlgPolicy,
74 class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance,
7075 class _UniformRandomNumberGenerator>
7176_LIBCPP_INLINE_VISIBILITY
7277_SampleIterator __sample(_PopulationIterator __first,
73 _PopulationIterator __last, _SampleIterator __output_iter,
78 _PopulationSentinel __last, _SampleIterator __output_iter,
7479 _Distance __n, _UniformRandomNumberGenerator& __g) {
75 typedef typename iterator_traits<_PopulationIterator>::iterator_category
76 _PopCategory;
77 typedef typename iterator_traits<_PopulationIterator>::difference_type
78 _Difference;
79 static_assert(__is_cpp17_forward_iterator<_PopulationIterator>::value ||
80 __is_cpp17_random_access_iterator<_SampleIterator>::value,
81 "SampleIterator must meet the requirements of RandomAccessIterator");
82 typedef typename common_type<_Distance, _Difference>::type _CommonType;
8380 _LIBCPP_ASSERT(__n >= 0, "N must be a positive number.");
84 return _VSTD::__sample(
85 __first, __last, __output_iter, _CommonType(__n),
86 __g, _PopCategory());
81
82 using _PopIterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_PopulationIterator>;
83 using _Difference = typename _IterOps<_AlgPolicy>::template __difference_type<_PopulationIterator>;
84 using _CommonType = typename common_type<_Distance, _Difference>::type;
85
86 return std::__sample<_AlgPolicy>(
87 std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n),
88 __g, _PopIterCategory());
8789}
8890
8991#if _LIBCPP_STD_VER > 14
......@@ -93,8 +95,14 @@ inline _LIBCPP_INLINE_VISIBILITY
9395_SampleIterator sample(_PopulationIterator __first,
9496 _PopulationIterator __last, _SampleIterator __output_iter,
9597 _Distance __n, _UniformRandomNumberGenerator&& __g) {
96 return _VSTD::__sample(__first, __last, __output_iter, __n, __g);
98 static_assert(__is_cpp17_forward_iterator<_PopulationIterator>::value ||
99 __is_cpp17_random_access_iterator<_SampleIterator>::value,
100 "SampleIterator must meet the requirements of RandomAccessIterator");
101
102 return std::__sample<_ClassicAlgPolicy>(
103 std::move(__first), std::move(__last), std::move(__output_iter), __n, __g);
97104}
105
98106#endif // _LIBCPP_STD_VER > 14
99107
100108_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/stable_partition.h+2-2
......@@ -108,7 +108,7 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
108108__second_half_done:
109109 // TTTFFFFFTTTTTFFFFF
110110 // f ff m sf l
111 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false, __fit);
111 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
112112 // TTTTTTTTFFFFFFFFFF
113113 // |
114114}
......@@ -253,7 +253,7 @@ __first_half_done:
253253__second_half_done:
254254 // TTTFFFFFTTTTTFFFFF
255255 // f ff m sf l
256 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false, __bit);
256 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
257257 // TTTTTTTTFFFFFFFFFF
258258 // |
259259}
lib/libcxx/include/__algorithm/swap_ranges.h+33-4
......@@ -9,8 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_SWAP_RANGES_H
1010#define _LIBCPP___ALGORITHM_SWAP_RANGES_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__config>
13#include <__utility/swap.h>
14#include <__utility/move.h>
15#include <__utility/pair.h>
1416
1517#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618# pragma GCC system_header
......@@ -18,12 +20,39 @@
1820
1921_LIBCPP_BEGIN_NAMESPACE_STD
2022
23// 2+2 iterators: the shorter size will be used.
24template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>
25_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
26pair<_ForwardIterator1, _ForwardIterator2>
27__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) {
28 while (__first1 != __last1 && __first2 != __last2) {
29 _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
30 ++__first1;
31 ++__first2;
32 }
33
34 return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2));
35}
36
37// 2+1 iterators: size2 >= size1.
38template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2>
39_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
40pair<_ForwardIterator1, _ForwardIterator2>
41__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) {
42 while (__first1 != __last1) {
43 _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
44 ++__first1;
45 ++__first2;
46 }
47
48 return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2));
49}
50
2151template <class _ForwardIterator1, class _ForwardIterator2>
2252inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2
2353swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
24 for (; __first1 != __last1; ++__first1, (void)++__first2)
25 swap(*__first1, *__first2);
26 return __first2;
54 return std::__swap_ranges<_ClassicAlgPolicy>(
55 std::move(__first1), std::move(__last1), std::move(__first2)).second;
2756}
2857
2958_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h created+62
......@@ -0,0 +1,62 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H
10#define _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H
11
12#include <__config>
13#include <__functional/invoke.h>
14#include <type_traits>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20#if _LIBCPP_STD_VER > 17
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27// Range versions of random algorithms (e.g. `std::shuffle`) are less constrained than their classic counterparts.
28// Range algorithms only require the given generator to satisfy the `std::uniform_random_bit_generator` concept.
29// Classic algorithms require the given generator to meet the uniform random bit generator requirements; these
30// requirements include satisfying `std::uniform_random_bit_generator` and add a requirement for the generator to
31// provide a nested `result_type` typedef (see `[rand.req.urng]`).
32//
33// To be able to reuse classic implementations, make the given generator meet the classic requirements by wrapping
34// it into an adaptor type that forwards all of its interface and adds the required typedef.
35template <class _Gen>
36class _ClassicGenAdaptor {
37private:
38 // The generator is not required to be copyable or movable, so it has to be stored as a reference.
39 _Gen& __gen;
40
41public:
42 using result_type = invoke_result_t<_Gen&>;
43
44 _LIBCPP_HIDE_FROM_ABI
45 static constexpr auto min() { return __uncvref_t<_Gen>::min(); }
46 _LIBCPP_HIDE_FROM_ABI
47 static constexpr auto max() { return __uncvref_t<_Gen>::max(); }
48
49 _LIBCPP_HIDE_FROM_ABI
50 constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen(__g) {}
51
52 _LIBCPP_HIDE_FROM_ABI
53 constexpr auto operator()() const { return __gen(); }
54};
55
56_LIBCPP_END_NAMESPACE_STD
57
58_LIBCPP_POP_MACROS
59
60#endif // _LIBCPP_STD_VER > 17
61
62#endif // _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H
lib/libcxx/include/__availability+7-17
......@@ -166,11 +166,11 @@
166166 // user has provided their own).
167167 //
168168 // Users can pass -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED
169 // to the compiler to tell the library to ignore the fact that the
170 // default function isn't available on their deployment target. Note that
171 // defining this macro but failing to define a custom function will lead to
172 // a load-time error on back-deployment targets, so it should be avoided.
173# define _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT
169 // to the compiler to tell the library not to define its own verbose abort.
170 // Note that defining this macro but failing to define a custom function
171 // will lead to a load-time error on back-deployment targets, so it should
172 // be avoided.
173// # define _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY
174174
175175#elif defined(__APPLE__)
176176
......@@ -271,8 +271,8 @@
271271 __attribute__((unavailable))
272272# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
273273
274# define _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT \
275 __attribute__((unavailable))
274# define _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY
275
276276#else
277277
278278// ...New vendors can add availability markup here...
......@@ -296,14 +296,4 @@
296296# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
297297#endif
298298
299// Define the special verbose termination function availability attribute, which can be silenced by
300// users if they provide their own custom function. The rest of the code should not use the
301// *_DEFAULT_* macro directly, since that would make it ignore the fact that the user provided
302// a custom function.
303#if defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
304# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT /* nothing */
305#else
306# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT
307#endif
308
309299#endif // _LIBCPP___AVAILABILITY
lib/libcxx/include/__iterator/incrementable_traits.h+1
......@@ -13,6 +13,7 @@
1313#include <__config>
1414#include <__type_traits/is_primary_template.h>
1515#include <concepts>
16#include <cstddef>
1617#include <type_traits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__iterator/iterator_traits.h+7
......@@ -14,6 +14,7 @@
1414#include <__iterator/incrementable_traits.h>
1515#include <__iterator/readable_traits.h>
1616#include <concepts>
17#include <cstddef>
1718#include <type_traits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -507,6 +508,12 @@ using __iterator_category_type = typename iterator_traits<_Iter>::iterator_categ
507508template <class _Iter>
508509using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer;
509510
511template <class _Iter>
512using __iter_diff_t = typename iterator_traits<_Iter>::difference_type;
513
514template<class _InputIterator>
515using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
516
510517_LIBCPP_END_NAMESPACE_STD
511518
512519#endif // _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
lib/libcxx/include/__iterator/reverse_iterator.h+9-1
......@@ -363,7 +363,7 @@ class __unconstrained_reverse_iterator {
363363 _Iter __iter_;
364364
365365public:
366 static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value);
366 static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value || bidirectional_iterator<_Iter>);
367367
368368 using iterator_type = _Iter;
369369 using iterator_category =
......@@ -391,6 +391,14 @@ public:
391391 }
392392 }
393393
394 _LIBCPP_HIDE_FROM_ABI friend constexpr
395 iter_rvalue_reference_t<_Iter> iter_move(const __unconstrained_reverse_iterator& __i)
396 noexcept(is_nothrow_copy_constructible_v<_Iter> &&
397 noexcept(ranges::iter_move(--declval<_Iter&>()))) {
398 auto __tmp = __i.base();
399 return ranges::iter_move(--__tmp);
400 }
401
394402 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator++() {
395403 --__iter_;
396404 return *this;
lib/libcxx/include/__memory/pointer_traits.h+24-2
......@@ -12,6 +12,7 @@
1212
1313#include <__config>
1414#include <__memory/addressof.h>
15#include <cstddef>
1516#include <type_traits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -171,9 +172,30 @@ _Tp* __to_address(_Tp* __p) _NOEXCEPT {
171172 return __p;
172173}
173174
175template <class _Pointer, class = void>
176struct _HasToAddress : false_type {};
177
178template <class _Pointer>
179struct _HasToAddress<_Pointer,
180 decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))
181> : true_type {};
182
183template <class _Pointer, class = void>
184struct _HasArrow : false_type {};
185
186template <class _Pointer>
187struct _HasArrow<_Pointer,
188 decltype((void)declval<const _Pointer&>().operator->())
189> : true_type {};
190
191template <class _Pointer>
192struct _IsFancyPointer {
193 static const bool value = _HasArrow<_Pointer>::value || _HasToAddress<_Pointer>::value;
194};
195
174196// enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers
175197template <class _Pointer, class = __enable_if_t<
176 !is_pointer<_Pointer>::value && !is_array<_Pointer>::value && !is_function<_Pointer>::value
198 _And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value
177199> >
178200_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
179201typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type
......@@ -208,7 +230,7 @@ auto to_address(_Tp *__p) noexcept {
208230
209231template <class _Pointer>
210232inline _LIBCPP_INLINE_VISIBILITY constexpr
211auto to_address(const _Pointer& __p) noexcept {
233auto to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) {
212234 return _VSTD::__to_address(__p);
213235}
214236#endif
lib/libcxx/include/__ranges/size.h+1
......@@ -16,6 +16,7 @@
1616#include <__ranges/access.h>
1717#include <__utility/auto_cast.h>
1818#include <concepts>
19#include <cstddef>
1920#include <type_traits>
2021
2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__verbose_abort+25-1
......@@ -17,11 +17,35 @@
1717# pragma GCC system_header
1818#endif
1919
20// Provide a default implementation of __libcpp_verbose_abort if we know that neither the built
21// library not the user is providing one. Otherwise, just declare it and use the one from the
22// built library or the one provided by the user.
23//
24// We can't provide a great implementation because it needs to be pretty much
25// dependency-free (this is included everywhere else in the library).
26#if defined(_LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY) && !defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
27
28extern "C" void abort();
29
2030_LIBCPP_BEGIN_NAMESPACE_STD
2131
22_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
32_LIBCPP_NORETURN _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) _LIBCPP_HIDE_FROM_ABI inline
33void __libcpp_verbose_abort(const char *, ...) {
34 ::abort();
35 __builtin_unreachable(); // never reached, but needed to tell the compiler that the function never returns
36}
37
38_LIBCPP_END_NAMESPACE_STD
39
40#else
41
42_LIBCPP_BEGIN_NAMESPACE_STD
43
44_LIBCPP_NORETURN _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
2345void __libcpp_verbose_abort(const char *__format, ...);
2446
2547_LIBCPP_END_NAMESPACE_STD
2648
49#endif
50
2751#endif // _LIBCPP___VERBOSE_ABORT
lib/libcxx/include/algorithm+149
......@@ -593,6 +593,11 @@ namespace ranges {
593593 constexpr borrowed_iterator_t<R>
594594 ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
595595
596 template<class T, class Proj = identity,
597 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
598 constexpr const T&
599 ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {}); // since C++20
600
596601 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
597602 class Proj1 = identity, class Proj2 = identity,
598603 indirect_strict_weak_order<projected<I1, Proj1>,
......@@ -745,6 +750,13 @@ namespace ranges {
745750 constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
746751 ranges::reverse_copy(R&& r, O result); // since C++20
747752
753 template<permutable I, sentinel_for<I> S>
754 constexpr subrange<I> rotate(I first, I middle, S last); // since C++20
755
756 template<forward_range R>
757 requires permutable<iterator_t<R>>
758 constexpr borrowed_subrange_t<R> rotate(R&& r, iterator_t<R> middle); // Since C++20
759
748760 template <class _InIter, class _OutIter>
749761 using rotate_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
750762
......@@ -758,6 +770,18 @@ namespace ranges {
758770 constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
759771 ranges::rotate_copy(R&& r, iterator_t<R> middle, O result); // since C++20
760772
773 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Gen>
774 requires (forward_iterator<I> || random_access_iterator<O>) &&
775 indirectly_copyable<I, O> &&
776 uniform_random_bit_generator<remove_reference_t<Gen>>
777 O sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g); // Since C++20
778
779 template<input_range R, weakly_incrementable O, class Gen>
780 requires (forward_range<R> || random_access_iterator<O>) &&
781 indirectly_copyable<iterator_t<R>, O> &&
782 uniform_random_bit_generator<remove_reference_t<Gen>>
783 O sample(R&& r, O out, range_difference_t<R> n, Gen&& g); // Since C++20
784
761785 template<random_access_iterator I, sentinel_for<I> S, class Gen>
762786 requires permutable<I> &&
763787 uniform_random_bit_generator<remove_reference_t<Gen>>
......@@ -768,6 +792,21 @@ namespace ranges {
768792 uniform_random_bit_generator<remove_reference_t<Gen>>
769793 borrowed_iterator_t<R> shuffle(R&& r, Gen&& g); // Since C++20
770794
795 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
796 sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
797 indirect_equivalence_relation<projected<I1, Proj1>,
798 projected<I2, Proj2>> Pred = ranges::equal_to>
799 constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
800 Pred pred = {},
801 Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
802
803 template<forward_range R1, forward_range R2,
804 class Proj1 = identity, class Proj2 = identity,
805 indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
806 projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
807 constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
808 Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
809
771810 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
772811 sentinel_for<I2> S2, class Pred = ranges::equal_to,
773812 class Proj1 = identity, class Proj2 = identity>
......@@ -912,8 +951,108 @@ namespace ranges {
912951 indirectly_copyable_storable<iterator_t<R>, O>)
913952 constexpr unique_copy_result<borrowed_iterator_t<R>, O>
914953 unique_copy(R&& r, O result, C comp = {}, Proj proj = {}); // Since C++20
954
955 template<class I, class O>
956 using remove_copy_result = in_out_result<I, O>; // Since C++20
957
958 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
959 class Proj = identity>
960 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
961 constexpr remove_copy_result<I, O>
962 remove_copy(I first, S last, O result, const T& value, Proj proj = {}); // Since C++20
963
964 template<input_range R, weakly_incrementable O, class T, class Proj = identity>
965 requires indirectly_copyable<iterator_t<R>, O> &&
966 indirect_binary_predicate<ranges::equal_to,
967 projected<iterator_t<R>, Proj>, const T*>
968 constexpr remove_copy_result<borrowed_iterator_t<R>, O>
969 remove_copy(R&& r, O result, const T& value, Proj proj = {}); // Since C++20
970
971 template<class I, class O>
972 using remove_copy_if_result = in_out_result<I, O>; // Since C++20
973
974 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
975 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
976 requires indirectly_copyable<I, O>
977 constexpr remove_copy_if_result<I, O>
978 remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // Since C++20
979
980 template<input_range R, weakly_incrementable O, class Proj = identity,
981 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
982 requires indirectly_copyable<iterator_t<R>, O>
983 constexpr remove_copy_if_result<borrowed_iterator_t<R>, O>
984 remove_copy_if(R&& r, O result, Pred pred, Proj proj = {}); // Since C++20
985
986 template<class I, class O>
987 using replace_copy_result = in_out_result<I, O>; // Since C++20
988
989 template<input_iterator I, sentinel_for<I> S, class T1, class T2,
990 output_iterator<const T2&> O, class Proj = identity>
991 requires indirectly_copyable<I, O> &&
992 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
993 constexpr replace_copy_result<I, O>
994 replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
995 Proj proj = {}); // Since C++20
996
997 template<input_range R, class T1, class T2, output_iterator<const T2&> O,
998 class Proj = identity>
999 requires indirectly_copyable<iterator_t<R>, O> &&
1000 indirect_binary_predicate<ranges::equal_to,
1001 projected<iterator_t<R>, Proj>, const T1*>
1002 constexpr replace_copy_result<borrowed_iterator_t<R>, O>
1003 replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
1004 Proj proj = {}); // Since C++20
1005
1006 template<class I, class O>
1007 using replace_copy_if_result = in_out_result<I, O>; // Since C++20
1008
1009 template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
1010 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
1011 requires indirectly_copyable<I, O>
1012 constexpr replace_copy_if_result<I, O>
1013 replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
1014 Proj proj = {}); // Since C++20
1015
1016 template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
1017 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
1018 requires indirectly_copyable<iterator_t<R>, O>
1019 constexpr replace_copy_if_result<borrowed_iterator_t<R>, O>
1020 replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
1021 Proj proj = {}); // Since C++20
1022
1023 template<class I>
1024 using prev_permutation_result = in_found_result<I>; // Since C++20
1025
1026 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
1027 class Proj = identity>
1028 requires sortable<I, Comp, Proj>
1029 constexpr ranges::prev_permutation_result<I>
1030 ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
1031
1032 template<bidirectional_range R, class Comp = ranges::less,
1033 class Proj = identity>
1034 requires sortable<iterator_t<R>, Comp, Proj>
1035 constexpr ranges::prev_permutation_result<borrowed_iterator_t<R>>
1036 ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
1037
1038 template<class I>
1039 using next_permutation_result = in_found_result<I>; // Since C++20
1040
1041 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
1042 class Proj = identity>
1043 requires sortable<I, Comp, Proj>
1044 constexpr ranges::next_permutation_result<I>
1045 ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
1046
1047 template<bidirectional_range R, class Comp = ranges::less,
1048 class Proj = identity>
1049 requires sortable<iterator_t<R>, Comp, Proj>
1050 constexpr ranges::next_permutation_result<borrowed_iterator_t<R>>
1051 ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
1052
9151053}
9161054
1055template <class InputIterator, class Predicate>
9171056 constexpr bool // constexpr in C++20
9181057 all_of(InputIterator first, InputIterator last, Predicate pred);
9191058
......@@ -1645,6 +1784,7 @@ template <class BidirectionalIterator, class Compare>
16451784#include <__algorithm/ranges_all_of.h>
16461785#include <__algorithm/ranges_any_of.h>
16471786#include <__algorithm/ranges_binary_search.h>
1787#include <__algorithm/ranges_clamp.h>
16481788#include <__algorithm/ranges_copy.h>
16491789#include <__algorithm/ranges_copy_backward.h>
16501790#include <__algorithm/ranges_copy_if.h>
......@@ -1669,6 +1809,7 @@ template <class BidirectionalIterator, class Compare>
16691809#include <__algorithm/ranges_is_heap.h>
16701810#include <__algorithm/ranges_is_heap_until.h>
16711811#include <__algorithm/ranges_is_partitioned.h>
1812#include <__algorithm/ranges_is_permutation.h>
16721813#include <__algorithm/ranges_is_sorted.h>
16731814#include <__algorithm/ranges_is_sorted_until.h>
16741815#include <__algorithm/ranges_lexicographical_compare.h>
......@@ -1684,6 +1825,7 @@ template <class BidirectionalIterator, class Compare>
16841825#include <__algorithm/ranges_mismatch.h>
16851826#include <__algorithm/ranges_move.h>
16861827#include <__algorithm/ranges_move_backward.h>
1828#include <__algorithm/ranges_next_permutation.h>
16871829#include <__algorithm/ranges_none_of.h>
16881830#include <__algorithm/ranges_nth_element.h>
16891831#include <__algorithm/ranges_partial_sort.h>
......@@ -1692,14 +1834,21 @@ template <class BidirectionalIterator, class Compare>
16921834#include <__algorithm/ranges_partition_copy.h>
16931835#include <__algorithm/ranges_partition_point.h>
16941836#include <__algorithm/ranges_pop_heap.h>
1837#include <__algorithm/ranges_prev_permutation.h>
16951838#include <__algorithm/ranges_push_heap.h>
16961839#include <__algorithm/ranges_remove.h>
1840#include <__algorithm/ranges_remove_copy.h>
1841#include <__algorithm/ranges_remove_copy_if.h>
16971842#include <__algorithm/ranges_remove_if.h>
16981843#include <__algorithm/ranges_replace.h>
1844#include <__algorithm/ranges_replace_copy.h>
1845#include <__algorithm/ranges_replace_copy_if.h>
16991846#include <__algorithm/ranges_replace_if.h>
17001847#include <__algorithm/ranges_reverse.h>
17011848#include <__algorithm/ranges_reverse_copy.h>
1849#include <__algorithm/ranges_rotate.h>
17021850#include <__algorithm/ranges_rotate_copy.h>
1851#include <__algorithm/ranges_sample.h>
17031852#include <__algorithm/ranges_search.h>
17041853#include <__algorithm/ranges_search_n.h>
17051854#include <__algorithm/ranges_set_difference.h>
lib/libcxx/include/format+56-45
......@@ -23,16 +23,23 @@ namespace std {
2323 using format_args = basic_format_args<format_context>;
2424 using wformat_args = basic_format_args<wformat_context>;
2525
26 // [format.fmt.string], class template basic-format-string
26 // [format.fmt.string], class template basic_format_string
2727 template<class charT, class... Args>
28 struct basic-format-string; // exposition only
28 struct basic_format_string { // since C++23, exposition only before C++23
29 private:
30 basic_string_view<charT> str; // exposition only
2931
32 public:
33 template<class T> consteval basic_format_string(const T& s);
34
35 constexpr basic_string_view<charT> get() const noexcept { return str; }
36 };
3037 template<class... Args>
31 using format-string = // exposition only
32 basic-format-string<char, type_identity_t<Args>...>;
38 using format_string = // since C++23, exposition only before C++23
39 basic_format_string<char, type_identity_t<Args>...>;
3340 template<class... Args>
34 using wformat-string = // exposition only
35 basic-format-string<wchar_t, type_identity_t<Args>...>;
41 using wformat_string = // since C++23, exposition only before C++23
42 basic_format_string<wchar_t, type_identity_t<Args>...>;
3643
3744 // [format.functions], formatting functions
3845 template<class... Args>
......@@ -233,7 +240,7 @@ private:
233240};
234241
235242// Dummy format_context only providing the parts used during constant
236// validation of the basic-format-string.
243// validation of the basic_format_string.
237244template <class _CharT>
238245struct _LIBCPP_TEMPLATE_VIS __compile_time_basic_format_context {
239246public:
......@@ -468,17 +475,21 @@ __vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
468475} // namespace __format
469476
470477template <class _CharT, class... _Args>
471struct _LIBCPP_TEMPLATE_VIS __basic_format_string {
472 basic_string_view<_CharT> __str_;
473
478struct _LIBCPP_TEMPLATE_VIS basic_format_string {
474479 template <class _Tp>
475480 requires convertible_to<const _Tp&, basic_string_view<_CharT>>
476 consteval __basic_format_string(const _Tp& __str) : __str_{__str} {
481 consteval basic_format_string(const _Tp& __str) : __str_{__str} {
477482 __format::__vformat_to(basic_format_parse_context<_CharT>{__str_, sizeof...(_Args)},
478483 _Context{__types_.data(), __handles_.data(), sizeof...(_Args)});
479484 }
480485
486 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT constexpr basic_string_view<_CharT> get() const noexcept {
487 return __str_;
488 }
489
481490private:
491 basic_string_view<_CharT> __str_;
492
482493 using _Context = __format::__compile_time_basic_format_context<_CharT>;
483494
484495 static constexpr array<__format::__arg_t, sizeof...(_Args)> __types_{
......@@ -510,11 +521,11 @@ private:
510521};
511522
512523template <class... _Args>
513using __format_string_t = __basic_format_string<char, type_identity_t<_Args>...>;
524using format_string = basic_format_string<char, type_identity_t<_Args>...>;
514525
515526#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
516527template <class... _Args>
517using __wformat_string_t = __basic_format_string<wchar_t, type_identity_t<_Args>...>;
528using wformat_string = basic_format_string<wchar_t, type_identity_t<_Args>...>;
518529#endif
519530
520531template <class _OutIt, class _CharT, class _FormatOutIt>
......@@ -555,16 +566,16 @@ vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
555566
556567template <output_iterator<const char&> _OutIt, class... _Args>
557568_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
558format_to(_OutIt __out_it, __format_string_t<_Args...> __fmt, _Args&&... __args) {
559 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_,
569format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) {
570 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.get(),
560571 _VSTD::make_format_args(__args...));
561572}
562573
563574#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
564575template <output_iterator<const wchar_t&> _OutIt, class... _Args>
565576_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
566format_to(_OutIt __out_it, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
567 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_,
577format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
578 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.get(),
568579 _VSTD::make_wformat_args(__args...));
569580}
570581#endif
......@@ -586,16 +597,16 @@ vformat(wstring_view __fmt, wformat_args __args) {
586597#endif
587598
588599template <class... _Args>
589_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(__format_string_t<_Args...> __fmt,
600_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(format_string<_Args...> __fmt,
590601 _Args&&... __args) {
591 return _VSTD::vformat(__fmt.__str_, _VSTD::make_format_args(__args...));
602 return _VSTD::vformat(__fmt.get(), _VSTD::make_format_args(__args...));
592603}
593604
594605#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
595606template <class... _Args>
596607_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
597format(__wformat_string_t<_Args...> __fmt, _Args&&... __args) {
598 return _VSTD::vformat(__fmt.__str_, _VSTD::make_wformat_args(__args...));
608format(wformat_string<_Args...> __fmt, _Args&&... __args) {
609 return _VSTD::vformat(__fmt.get(), _VSTD::make_wformat_args(__args...));
599610}
600611#endif
601612
......@@ -611,16 +622,16 @@ _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it,
611622
612623template <output_iterator<const char&> _OutIt, class... _Args>
613624_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
614format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __format_string_t<_Args...> __fmt, _Args&&... __args) {
615 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_format_args(__args...));
625format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, format_string<_Args...> __fmt, _Args&&... __args) {
626 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, __fmt.get(), _VSTD::make_format_args(__args...));
616627}
617628
618629#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
619630template <output_iterator<const wchar_t&> _OutIt, class... _Args>
620631_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
621format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __wformat_string_t<_Args...> __fmt,
632format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wformat_string<_Args...> __fmt,
622633 _Args&&... __args) {
623 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_wformat_args(__args...));
634 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, __fmt.get(), _VSTD::make_wformat_args(__args...));
624635}
625636#endif
626637
......@@ -634,15 +645,15 @@ _LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt,
634645
635646template <class... _Args>
636647_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
637formatted_size(__format_string_t<_Args...> __fmt, _Args&&... __args) {
638 return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)});
648formatted_size(format_string<_Args...> __fmt, _Args&&... __args) {
649 return _VSTD::__vformatted_size(__fmt.get(), basic_format_args{_VSTD::make_format_args(__args...)});
639650}
640651
641652#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
642653template <class... _Args>
643654_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
644formatted_size(__wformat_string_t<_Args...> __fmt, _Args&&... __args) {
645 return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)});
655formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
656 return _VSTD::__vformatted_size(__fmt.get(), basic_format_args{_VSTD::make_wformat_args(__args...)});
646657}
647658#endif
648659
......@@ -686,16 +697,16 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt v
686697
687698template <output_iterator<const char&> _OutIt, class... _Args>
688699_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
689format_to(_OutIt __out_it, locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) {
690 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_,
700format_to(_OutIt __out_it, locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
701 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.get(),
691702 _VSTD::make_format_args(__args...));
692703}
693704
694705#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
695706template <output_iterator<const wchar_t&> _OutIt, class... _Args>
696707_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
697format_to(_OutIt __out_it, locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
698 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_,
708format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
709 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.get(),
699710 _VSTD::make_wformat_args(__args...));
700711}
701712#endif
......@@ -720,17 +731,17 @@ vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
720731
721732template <class... _Args>
722733_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(locale __loc,
723 __format_string_t<_Args...> __fmt,
734 format_string<_Args...> __fmt,
724735 _Args&&... __args) {
725 return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_,
736 return _VSTD::vformat(_VSTD::move(__loc), __fmt.get(),
726737 _VSTD::make_format_args(__args...));
727738}
728739
729740#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
730741template <class... _Args>
731742_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
732format(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
733 return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_,
743format(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
744 return _VSTD::vformat(_VSTD::move(__loc), __fmt.get(),
734745 _VSTD::make_wformat_args(__args...));
735746}
736747#endif
......@@ -748,18 +759,18 @@ _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it,
748759
749760template <output_iterator<const char&> _OutIt, class... _Args>
750761_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
751format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __format_string_t<_Args...> __fmt,
762format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, format_string<_Args...> __fmt,
752763 _Args&&... __args) {
753 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_,
764 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.get(),
754765 _VSTD::make_format_args(__args...));
755766}
756767
757768#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
758769template <output_iterator<const wchar_t&> _OutIt, class... _Args>
759770_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
760format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __wformat_string_t<_Args...> __fmt,
771format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, wformat_string<_Args...> __fmt,
761772 _Args&&... __args) {
762 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_,
773 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.get(),
763774 _VSTD::make_wformat_args(__args...));
764775}
765776#endif
......@@ -775,15 +786,15 @@ _LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(locale __loc, basic_string_view<_
775786
776787template <class... _Args>
777788_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
778formatted_size(locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) {
779 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)});
789formatted_size(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
790 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.get(), basic_format_args{_VSTD::make_format_args(__args...)});
780791}
781792
782793#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
783794template <class... _Args>
784795_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
785formatted_size(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
786 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)});
796formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
797 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.get(), basic_format_args{_VSTD::make_wformat_args(__args...)});
787798}
788799#endif
789800
lib/libcxx/include/span+4-3
......@@ -453,9 +453,10 @@ public:
453453 : __data{_VSTD::to_address(__first)}, __size{__count} {}
454454
455455 template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End>
456 _LIBCPP_INLINE_VISIBILITY
457 constexpr span(_It __first, _End __last)
458 : __data(_VSTD::to_address(__first)), __size(__last - __first) {}
456 _LIBCPP_INLINE_VISIBILITY constexpr span(_It __first, _End __last)
457 : __data(_VSTD::to_address(__first)), __size(__last - __first) {
458 _LIBCPP_ASSERT(__last - __first >= 0, "invalid range in span's constructor (iterator, sentinel)");
459 }
459460
460461 template <size_t _Sz>
461462 _LIBCPP_INLINE_VISIBILITY
lib/libcxx/include/version+5-3
......@@ -331,8 +331,8 @@ __cpp_lib_void_t 201411L <type_traits>
331331# define __cpp_lib_erase_if 202002L
332332# undef __cpp_lib_execution
333333// # define __cpp_lib_execution 201902L
334# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format)
335// # define __cpp_lib_format 202106L
334# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
335# define __cpp_lib_format 202106L
336336# endif
337337# define __cpp_lib_generic_unordered_lookup 201811L
338338# define __cpp_lib_int_pow2 202002L
......@@ -351,7 +351,9 @@ __cpp_lib_void_t 201411L <type_traits>
351351# define __cpp_lib_list_remove_return_type 201806L
352352# define __cpp_lib_math_constants 201907L
353353// # define __cpp_lib_polymorphic_allocator 201902L
354// # define __cpp_lib_ranges 201811L
354# if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
355# define __cpp_lib_ranges 201811L
356# endif
355357# define __cpp_lib_remove_cvref 201711L
356358# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)
357359# define __cpp_lib_semaphore 201907L