Boost堆设置用户定义的比较函数 [英] Boost heap Setting user defined compare function
本文介绍了Boost堆设置用户定义的比较函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近,我发现Boost.Heap在我的项目中非常有用。但我找不到任何示例代码显示如何设置任意比较函数。
Recently, I found Boost.Heap very useful in my project. But I could not find any example code showing how I can set up arbitrary compare function.
#include "boost/heap/fibonacci_heap.hpp"
using boost::heap::fibonacci_heap;
int main(){
fibonacci_heap<int> pq; //default compare function std::less<int>
}
例如,如何设置std :: greater< int>?
For example, how can I set std::greater< int >?
boost.heap文档说它可以通过设置一个选项来设置。但我不知道这是什么意思。任何人可以帮助?
The boost.heap document says that it can be set by setting an option. But I don't know what it means. Can anyone help?
推荐答案
尝试:
typedef boost::heap::fibonacci_heap<
int,
boost::heap::compare<std::greater<int> > > MyHeap;
本文档不显示如何指定选项。我不得不通过单元测试源代码来找出正确的用法语法。
The documentation does not show how to specify options. I had to dig through the unit test source code to find out the correct usage syntax.
这篇关于Boost堆设置用户定义的比较函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文