1class Foo
2{
3
4};
5
6class Compare
7{
8public:
9 bool operator() (Foo, Foo)
10 {
11 return true;
12 }
13};
14
15int main()
16{
17 std::priority_queue<Foo, std::vector<Foo>, Compare> pq;
18 return 0;
19}
20
1void SamplePriorityQueueWithLamda()
2{
3 // using lambda to compare elements.
4 auto compare = [](int lhs, int rhs)
5 {
6 return lhs < rhs;
7 };
8
9 std::priority_queue<int, std::vector<int>, decltype(compare)> q(compare);
10
11 for(int n : {1,8,5,6,3,4,0,9,7,2})
12 q.push(n);
13
14
15 printQueue(q);
16}
17