@@ -16,14 +16,37 @@ According to the benchmarks, it is slower than `std::sort()` on randomized seque
1616ones. ` gfx::timsort ` should be usable as a drop-in replacement for ` std::stable_sort ` , with the difference that it
1717can't fallback to a O(n log² n) algorithm when there isn't enough extra heap memory available.
1818
19- Additionally ` gfx::timsort ` can take a [ projection function] ( https://ezoeryou.github.io/blog/article/2019-01-22-ranges-projection.html )
20- after the comparison function. The support is a bit rougher than in the linked article or the C++20 standard library:
21- unless ` std::invoke ` is available, only instances of types callable with parentheses can be used, there is no support
22- for pointer to members.
19+ ` gfx::timsort ` also has a few additional features and guarantees compared to ` std::stable_sort ` :
20+ * It can take a [ projection function] ( https://ezoeryou.github.io/blog/article/2019-01-22-ranges-projection.html )
21+ after the comparison function. The support is a bit rougher than in the linked article or the C++20 standard library:
22+ unless ` std::invoke ` is available, only instances of types callable with parentheses can be used, there is no support
23+ for pointer to members.
24+ * It can also be passed a range instead of a pair of iterators, in which case it will sort the whole range.
25+ * This implementation of timsort notably avoids using the postfix ` ++ ` or ` -- ` operators: only their prefix equivalents
26+ are used, which means that timsort will work even if the postfix operators are not present or return an incompatible
27+ type such as ` void ` .
2328
24- This implementation of timsort notably avoids using the postfix ` ++ ` or ` -- ` operators: only their prefix equivalents
25- are used, which means that timsort will work even if the postfix operators are not present or return an incompatible
26- type such as ` void ` .
29+
30+ The full list of available signatures is as follows (in namespace ` gfx ` ):
31+
32+ ``` cpp
33+ // Overloads taking a pair of iterators
34+ template <typename RandomAccessIterator>
35+ void timsort (RandomAccessIterator const first, RandomAccessIterator const last);
36+ template <typename RandomAccessIterator, typename Compare>
37+ void timsort(RandomAccessIterator const first, RandomAccessIterator const last,
38+ Compare compare);
39+ template <typename RandomAccessIterator, typename Compare, typename Projection>
40+ void timsort(RandomAccessIterator const first, RandomAccessIterator const last,
41+ Compare compare, Projection projection);
42+ // Overloads taking a range
43+ template <typename RandomAccessRange >
44+ void timsort(RandomAccessRange &range);
45+ template <typename RandomAccessRange, typename Compare>
46+ void timsort(RandomAccessRange &range, Compare compare);
47+ template <typename RandomAccessRange, typename Compare, typename Projection>
48+ void timsort(RandomAccessRange &range, Compare compare, Projection projection);
49+ ```
2750
2851## EXAMPLE
2952
@@ -39,9 +62,8 @@ size_t len(const std::string& str) {
3962}
4063
4164// Sort a vector of strings by length
42- std::vector< std::string > vec;
43- // ... fill vec ...
44- gfx::timsort(vec.begin(), vec.end(), std::less<size_t>(), &len);
65+ std::vector<std::string> collection = { /* ... */ };
66+ gfx::timsort(collection, std::less<std::string>{}, &len);
4567```
4668
4769## COMPATIBILITY
0 commit comments