I have the below snippet which is acting as a predicate for the sort function. This is for sorting the value pair in a hash map which i have put in a vector. The sort is getting called on a vector
struct val_less : binary_function<pair<string, unsigned int>, pair<string, unsigned int>, bool>
{
bool operator() ( pair<string, unsigned int>&x , pair<string, unsigned int> &y )
const {
return x.second>y.second;
}
}val_gt;
I understand what the code is doing, but i do not understand why it is being done so. What is the binary_function and why do we need to use it as ":". what is the operator() function and why is it bool operator (). I understand the reference parameters as we want to change back the original vector.
Thanks