Currently working through a leetcode problem for which I need a min Heap of pairs.
I am trying to use a priority_queue with int pairs and a custom compare type.
Attempts of implementation of the same have failed with the following error:
In file included from prog_joined.cpp:1: In file included from ./precompiled/headers.h:55: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/queue:64: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_queue.h:467:7: error: static_assert failed due to requirement 'is_same<int, std::pair<int, int>>::value' "value_type must be the same as the underlying container" static_assert(is_same<_Tp, typename _Sequence::value_type>::value, ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Line 9: Char 67: note: in instantiation of template class 'std::priority_queue<int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>, std::greater>' requested here priority_queue<int, vector<pair<int, int>>, greater> pq;
Here's the code with which I'm trying to implement the heap:
#include <queue>
#include <utility>
using namespace std;
//...
priority_queue<int, pair<int, int>, greater<int>> pq;
intwould beginstd::priority_queue<std::pair<int, int>, ...and requires a comparator for such pairs.