给定类C
和函数int f(C c)
,创建std::priority_queue<C>
使用标准<
比较器(不是在C
而是在f(C)
的合适惯用法是什么?
Refer 1
``// binary predicate function
bool Compare1(C item1, C item2){
return f(item1) > f(item2);
}`
//`binary predicate functor
class Compare2
{
public:
bool operator() (C item1, C item2)
{
return f(item1) > f(item2);
}
};
int main()
{
std::priority_queue<C, std::vector<C>, std::function<bool(C, C)>> pq1(Compare1);
std::priority_queue<C, std::vector<C>, Compare2> pq2;
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.