Boost heap Setting user defined compare function

2019-02-19 17:30发布

问题:

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>
}

For example, how can I set std::greater< int >?

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?

回答1:

Try this:

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.



标签: c++ boost heap