【发布时间】:2011-05-10 08:32:08
【问题描述】:
我想要一个具有自定义排序的优先级队列,但是我很懒,我不想定义一个比较器类来实现 operator()。
我真的很想编译这样的东西:
std::priority_queue<int, std::vector<int>,
boost::bind(some_function, _1, _2, obj1, obj2)> queue;
其中 some_function 是一个布尔返回函数,带有四个参数,第一个和第二个是队列的整数,最后两个是计算排序所需的一些对象(常量引用)。
(错误:'boost::bind' 不能出现在常量表达式中)
但这不能编译。更简单的
std::priority_queue<int, std::vector<int>, &compare> queue;
不会编译,因为 compare 是一个返回 bool 的二进制函数。
(错误:“模板类 std::priority_queue”的模板参数列表中参数 3 的类型/值不匹配;预期类型,得到“比较”)
有什么建议吗?
【问题讨论】:
-
这里的
boost::bind没有关闭括号 - 在队列模板参数的 > 之前。这是发布的代码中的拼写错误还是您尝试编译的内容?
标签: c++ boost stl bind priority-queue