How can I preallocate a std::priority_queue with a container of type std::vector?
std::priority_queue
In general with C++11 you can write a make_reserved function as below.
#include
#include
#include
#include
template
std::vector make_reserved(const std::size_t n)
{
std::vector v;
v.reserve(n);
return v;
}
int main()
{
using Q = std::priority_queue>;
auto q = Q(std::less(), make_reserved(100));
std::cout << q.size() << std::endl;
}