我想这样做:如何在特定构造函数中使用STL priority_queue +比较器?
#include <queue>
#include <set>
class Comparator
{
public:
Comparator(SomeObject& rTool) : mrTools(rTool) {}
bool operator()(const std::string& a, const std::string& b)
{
return mrTools.doSomething(a,b);
}
private:
SomeObject& mrTools;
}
std::priority_queue<std::string, std::set<std::string>, Comparator> queue;
//<- this doesn't compile
我怎样才能initalize这个队列提供比较它在构造函数中所需要的参考?
无论如何,'priority_queue'的功能比'set'少。唯一(但可能是非常好的)选择'priority_queue'的原因是效率。 –