How can I preallocate a std::priority_queue with a container of type std::vector?
std::priority_queue
Another solution might be to make your own class derived from std::priority_queue, such as:
class MyPQueue : public std::priority_queue>
{
public:
MyPQueue(size_t reserve_size)
{
this->c.reserve(reserve_size);
}
};
then, in the code, create a MyPQueue object in this way:
MyPQueue mpq(1024);
which object can be upcasted back to the base class whenether needed.
std::priority_queue>& pq = mpq;