With a combination of std::transform
, std::multiset
, and an insert iterator you could.
vector v;
...fill it up
multiset ms;
transform(v.begin(), v.end(), inserter(ms, ms.begin()), criterionFunction);
Then the three max values are the last three elements.