diff --git a/algo/sort.hpp b/algo/sort.hpp index bbfa990e..977aff73 100644 --- a/algo/sort.hpp +++ b/algo/sort.hpp @@ -96,16 +96,27 @@ namespace cruft::sort { /// RandomIterator `data`. /// /// Does not modify any data element pointed to by `data`. - template + template < + typename IndexT, + typename RandomT, + typename ComparatorT = std::less<> + > 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 std::iota (idx_first, idx_last, 0); // sort using the indices std::sort (idx_first, idx_last, [&] (auto a, auto b) { - return *(data + a) < *(data + b); + return cmp ( + *(data + a), + *(data + b) + ); }); }