23
23
#include " subspace/assertions/check.h"
24
24
#include " subspace/construct/into.h"
25
25
#include " subspace/containers/__private/slice_iter.h"
26
- #include " subspace/fn/callable.h"
26
+ #include " subspace/fn/fn_concepts.h"
27
+ #include " subspace/fn/run_fn.h"
27
28
#include " subspace/iter/iterator_defn.h"
28
29
#include " subspace/macros/lifetimebound.h"
29
30
#include " subspace/marker/unsafe.h"
@@ -236,16 +237,17 @@ class [[sus_trivial_abi]] Slice {
236
237
// / unspecified.
237
238
//
238
239
// TODO: Rust's stable sort is O(n * log(n)), so this can be improved.
239
- template <class F , int &... ,
240
- class R = std::invoke_result_t <F, const T&, const T&>>
240
+ template <::sus::fn::FnMut<:: sus::fn::Anything ( const T&, const T&)> F ,
241
+ int &..., class R = std::invoke_result_t <F, const T&, const T&>>
241
242
requires (::sus::ops::Ordering<R>)
242
243
void sort_by (F compare) noexcept
243
244
requires (!std::is_const_v<T>)
244
245
{
245
246
if (len_ > 0_usize) {
246
- std::stable_sort (
247
- data_, data_ + size_t {len_},
248
- [&compare](const T& l, const T& r) { return compare (l, r) < 0 ; });
247
+ std::stable_sort (data_, data_ + size_t {len_},
248
+ [&compare](const T& l, const T& r) {
249
+ return ::sus::run_mut (compare, l, r) < 0 ;
250
+ });
249
251
}
250
252
}
251
253
@@ -270,16 +272,17 @@ class [[sus_trivial_abi]] Slice {
270
272
// / The comparator function must define a total ordering for the elements in
271
273
// / the slice. If the ordering is not total, the order of the elements is
272
274
// / unspecified.
273
- template <class F , int &... ,
274
- class R = std::invoke_result_t <F, const T&, const T&>>
275
+ template <::sus::fn::FnMut<:: sus::fn::Anything ( const T&, const T&)> F ,
276
+ int &..., class R = std::invoke_result_t <F, const T&, const T&>>
275
277
requires (::sus::ops::Ordering<R>)
276
278
void sort_unstable_by (F compare) noexcept
277
279
requires (!std::is_const_v<T>)
278
280
{
279
281
if (len_ > 0_usize) {
280
- std::sort (
281
- data_, data_ + size_t {len_},
282
- [&compare](const T& l, const T& r) { return compare (l, r) < 0 ; });
282
+ std::sort (data_, data_ + size_t {len_},
283
+ [&compare](const T& l, const T& r) {
284
+ return ::sus::run_mut (compare, l, r) < 0 ;
285
+ });
283
286
}
284
287
}
285
288
0 commit comments