I am trying to create a priority queue with a custom comparator but the following code gives me a compile error:
auto comparator = [](std::pair<std::vector<int>, File&> const &a, std::pair<std::vector<int>, File&> const &b) {
return a.first.front() > b.first.front();
};
std::priority_queue<std::pair<std::vector<uint64_t>, File&>,
std::vector<std::pair<std::vector<uint64_t>, File&>>,
decltype(comparator)> pq;
This is the error I am getting:
In template: no matching constructor for initialization of 'std::priority_queue<std::pair<std::vector, moderndbs::File &>, std::vector<std::pair<std::vector, moderndbs::File &>>, (lambda at
std::pair<std::vector<int>, File&>, but you are trying to use it to compare values of a different typestd::pair<std::vector<uint64_t>, File&>comparatorto the priority queue, but not the instance itself, the queue has to default-construct one. However, lambdas are not default-constructible before C++20. You need to compile with C++20 support enabled for this to work, or else passcomparatortopq's constructor, as instd::priority_queue<...> pq{comparator}