sort: use a comparator object for index sort
This commit is contained in:
parent
801ccf2ebd
commit
f3302ffd5f
@ -96,16 +96,27 @@ namespace cruft::sort {
|
|||||||
/// RandomIterator `data`.
|
/// RandomIterator `data`.
|
||||||
///
|
///
|
||||||
/// Does not modify any data element pointed to by `data`.
|
/// Does not modify any data element pointed to by `data`.
|
||||||
template <typename IndexT, typename RandomT>
|
template <
|
||||||
|
typename IndexT,
|
||||||
|
typename RandomT,
|
||||||
|
typename ComparatorT = std::less<>
|
||||||
|
>
|
||||||
void
|
void
|
||||||
indices (IndexT idx_first, IndexT idx_last, RandomT data)
|
indices (
|
||||||
{
|
IndexT idx_first,
|
||||||
|
IndexT idx_last,
|
||||||
|
RandomT data,
|
||||||
|
ComparatorT &&cmp
|
||||||
|
) {
|
||||||
// initialise a monotonic sequence of indices
|
// initialise a monotonic sequence of indices
|
||||||
std::iota (idx_first, idx_last, 0);
|
std::iota (idx_first, idx_last, 0);
|
||||||
|
|
||||||
// sort using the indices
|
// sort using the indices
|
||||||
std::sort (idx_first, idx_last, [&] (auto a, auto b) {
|
std::sort (idx_first, idx_last, [&] (auto a, auto b) {
|
||||||
return *(data + a) < *(data + b);
|
return cmp (
|
||||||
|
*(data + a),
|
||||||
|
*(data + b)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user