나는이 작업을 수행 할 수 :STL priority_queue + comparator를 특정 생성자와 함께 사용하는 방법은 무엇입니까?
#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'를 선호하는 유일한 이유는 효율성입니다. –