How do I create a set of pairs, the elements of which (the pairs) are sorted with a custom bool function? I write
set ,compare> my
Write a class that overloads the operator()
so it can be called like a function:
struct compare {
bool operator() (const pair &lhs, const pair &rhs) const{
return (lhs.second-lhs.first > rhs.second-rhs.first);
}
};
Then, you can use the class name as the type parameter
set, compare> myset;
Assuming compare
is the function you want to use:
set, bool(*)(const pair &lhs,
const pair &rhs)
> myset(&compare);