2

Presently i'm trying to implement this solution: https://stackoverflow.com/a/29236236/8882282 And I have no problems when i'm using less<>(), but have a lot of them in any other cases(greater, my own comparator). For example:

std::vector<long long int> container;
container.reserve(dimension);
std::priority_queue<long long int, std::vector<long long int>> queue(std::greater<long long int>(), std::move(container));

"No matching constructor"

Have you any ideas?

1 Answers1

2

The default comparator for a std::priority_queue is std::less. You're passing in a std::greater comparator to the constructor.

They are different, completely unrelated, classes. That's your error.

You must explicitly declare your priority queue, as such:

std::priority_queue<long long int,
                    std::vector<long long int>,
                    std::greater<long long int>>
          queue(std::greater<long long int>(),
                std::move(container));
Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148