How can I preallocate a std::priority_queue
with a container of type std::vector
?
std::priority_queue
Yes, there's a constructor for that. It's slightly tedious that you also have to specify a comparator:
std::vector container;
container.reserve(1024);
std::priority_queue> pq (
std::less(), std::move(container));
You can also use evil shenanigans to access the protected member, but I wouldn't recommend it.