1

我试图保持一个按属性映射中的值排序的堆。我尝试了下面的代码,但编译器不喜欢我对堆构造函数的参数 (PriorityQueueType pq(indirectComparison);)。根据文档(http://www.boost.org/doc/libs/1_51_0/doc/html/boost/heap/binomial_heap.html),有一个构造函数:

显式 binomial_heap(value_compare const & = value_compare());

这需要一个 value_compare,我认为它是我提供的 IndirectComparisonType 类型(我不太了解可选的模板参数和 base_maker::compare_argument 类型的东西)?

这是供参考的indirect_cmp 文档:http: //www.boost.org/doc/libs/1_51_0/boost/pending/indirect_cmp.hpp

#include <boost/heap/binomial_heap.hpp>
#include <boost/pending/indirect_cmp.hpp>
#include <boost/array.hpp>
#include <boost/graph/grid_graph.hpp>
#include <iostream>

int main(int, char*[])
{
  // Construct a graph
  boost::array<std::size_t, 2> lengths = { { 2,2 } };
  typedef boost::grid_graph<2> GraphType;
  GraphType graph(lengths);
  typedef boost::graph_traits<GraphType>::vertex_descriptor Vertex;
  typedef boost::property_map<GraphType,
boost::vertex_index_t>::const_type GridIndexMapType;
  GridIndexMapType gridIndexMap(get(boost::vertex_index, graph));

  // Construct a property map
  typedef boost::vector_property_map<float, GridIndexMapType> PriorityMapType;
  PriorityMapType priorityMap(gridIndexMap);

  // Construct the indirect comparison functor
  typedef boost::indirect_cmp<PriorityMapType, std::less<float> >
IndirectComparisonType;
  IndirectComparisonType indirectComparison(priorityMap);

  // Construct the queue
  typedef int ValueType;
  typedef boost::heap::binomial_heap<ValueType,
boost::heap::stable<false>, IndirectComparisonType> PriorityQueueType;
  PriorityQueueType pq(indirectComparison);

  return 0;
}

有谁知道如何正确地将这个间接比较函子提供给队列?

4

1 回答 1

0

您需要将模板选项括起来boost::heap::compare以对其进行标识,如docs中所示。

于 2012-09-05T21:15:11.520 回答