How to preallocate(reserve) a priority_queue?

前端 未结 4 928
-上瘾入骨i
-上瘾入骨i 2021-01-01 20:35

How can I preallocate a std::priority_queue with a container of type std::vector?

std::priority_queue

        
4条回答
  •  独厮守ぢ
    2021-01-01 20:44

    I don't have enough reputation to comment on Mike Seymour's post, but he ommited the third template argument of std::priority_queue :

    std::vector container;
    container.reserve(1024);
    std::priority_queue, std::less> pq(std::less(), std::move(container));
    

    It is quite verbose for sure, but it does the work.

提交回复
热议问题