[英]Boost priority queue comparison function
How to change comparison function on a priority queue with boost library? 如何使用Boost库更改优先级队列上的比较功能? I have a struct like this :
我有一个这样的结构:
struct decreasingOrderMyType
{
bool operator() (const MyType & lhs, const MyType & rhs) const
{
return lhs.value > rhs.value;
}
};
and i would like use it to compare my elements. 我想用它来比较我的元素。
thanks! 谢谢!
For the std::priority_queue I have it specified as: std::priority_queue<DistanceTuple, std::vector<DistanceTuple>, SmallestOnTop > pq;
对于std :: priority_queue,我将其指定为:
std::priority_queue<DistanceTuple, std::vector<DistanceTuple>, SmallestOnTop > pq;
DistanceTuple
is a std::pair
and SmallestOnTop
is a functor to compare the std::pair
DistanceTuple
是一个std::pair
而SmallestOnTop
是一个函子,用于比较std::pair
Update: I was wrong, they are not identical. 更新:我错了,它们并不相同。 The boost version uses named parameters.
Boost版本使用命名参数。 Which work like this:
像这样的工作:
boost::heap::priority_queue<MyType,
boost::heap::compare<decreasingOrderMyType> > pq;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.