// suppose you want to apply comparator on pair <int, string>
// declaration of priority queue
priority_queue<pair<int, string>, vector<pair<int, string>>, myComp> pq;
// here myComp is comparator
struct myComp {
bool operator()(
pair<int, string>& a,
pair<int, string>& b)
{
return a.first > b.first;
// can write more code if required. depends upon requirement.
}
};
// another way
auto compare = [](int lhs, int rhs){
return lhs < rhs;
};
priority_queue<int, vector<int>, decltype(compare) > pq(compare);
class Foo
{
};
class Compare
{
public:
bool operator() (Foo, Foo)
{
return true;
}
};
int main()
{
std::priority_queue<Foo, std::vector<Foo>, Compare> pq;
return 0;
}
struct CompareHeight {
bool operator()(Person const& p1, Person const& p2)
{
// return "true" if "p1" is ordered
// before "p2", for example:
return p1.height < p2.height;
}
};