构造后切换std :: priority_queue比较器

问题描述

我正在实现一个median cut algorithm,它使用优先级队列来跟踪下一个要拆分的框:

  • 前50%的削减将基于population
  • 剩余的50%削减将基于population * volume

我正在使用std::priority_queue,它看起来类似于步骤1:

auto compareVBoxPopulation = [](const VBox &a,const VBox &b) {
  return a.population < b.population;
};

auto compareVBoxPopulationAndVolume = [](const VBox &a,const VBox &b) {
  return (a.population * a.volume) < (b.population * b.volume);
};

std::priority_queue<VBox,std::vector<VBox>,decltype(compareVBoxPopulation)>
      queue(compareVBoxPopulation);

// do some cuts
// change comparator to compareVBoxPopulationAndVolume
// do some more cuts

我想将std::priority_queue的比较器从compareVBoxPopulation更改为compareVBoxPopulationAndVolume。我可以只创建另一个std::priority_queue,但是我想重用基础vector<VBox>内容

a bunch of constructors个容器,但是由于受保护,我无法访问vector中的std::priority_queue。理想情况下,我需要类似

priority_queue(const Compare& compare,priority_queue&& other);

这两个比较器具有相同的类型,因此在技术上可以正常工作。有没有办法得到这种行为?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)