961 | @@ -962,6 +962,16 @@ static bool CompareNodeTXTime(const NodeEvictionCandidate &a, const NodeEviction
962 | return a.nTimeConnected > b.nTimeConnected;
963 | }
964 |
965 | +
966 | +//! Sort an array by the specified comparator, then remove the last K elements.
967 | +template<typename T>
968 | +static void removeLastKElements(std::vector<T> &elements, bool(*comparator)(const T&, const T&), size_t k)
Maybe don't require comparator to be function pointer. It'd be nice to allow comparator to be a lambda or function class:
template<typename T, typename Compare>
static void removeLastKElements(std::vector<T> &elements, Compare comp, size_t k)
{
std::sort(elements.begin(), elements.end(), comp);
...
}
That's a good point, should have pulled that from your example. Old habits die hard.