Of course. std::sort can take a third parameter, which is used for comparison when sorting. For example, you can use the lambda function:
std::vector<std::vector<int>> vec;
Alternatively, you can pass anything that might be caused by a bool(const std::vector<int>&, const std::vector<int>&) signature bool(const std::vector<int>&, const std::vector<int>&) , for example, a pointer to a functor or function.
Editing response: just apply the COST function to a and b :
std::sort(vec.begin(), vec.end(), [](const std::vector<int>& a, const std::vector<int>& b) { return COST(a) < COST(b); });
Joseph mansfield
source share