The order is different because < relation implies that std::sort sorts values in ascending order, and that std::priority_queue places the maximum element at the top. This is by designby design.
If you want to reverse the order in the priority queue, you need another comparator that swaps the arguments,
bool cmp2(const T& a, const T& b) { return cmp(b, a); } //... std::priority_queue<T, std::vector<T>, decltype(&cmp2)> queue(cmp2); This is in perfect analogy with going from std::less to std::greater as explained in this question.
Instead of introducing a separate function, you can use a lambda:
auto cmp2 = [](const auto& a, const auto& b) { return cmp(b, a); }; std::priority_queue<T, std::vector<T>, decltype(cmp2)> queue(cmp2);