你可以用需要状态的构造函数定义compare functor。
struct Compare
{
State state;
Compare(State state)
: state(state)
{
}
bool operator()(const Item& a, const Item& b)
{
... // use state
}
};
然后把用所需状态构造的实例传递给priority_queue。构造者:
priority_queue<Item, std::vector<Item>, Compare> queue(Compare(state));