It seems a simple problem, yet…
Sorting by indices, part 2
by Raymond Chen
From the article:
Before we dig into the Schwartzian transform, let's look at a more conventional generic way to sort by a key:
template<typename Iter, typename UnaryOperation, typename Compare> void sort_by(Iter first, Iter last, UnaryOperation op, Compare comp) { std::sort(first, last, [&](T& a, T& b) { return comp(op(a), op(b)); }); }The idea here is that you give a unary operator op that produces a sort key, and we sort the items by that key according to the comparer...
Add a Comment
Comments are closed.