欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

The Usage of Lambda and Heap in the C++ STL

程序员文章站 2022-03-23 14:01:07
...

The Usage of Lambda and Heap in the C++ STL

Heap

In c++ STL, the heap had been implemented as the priority_queue.

Lambda with STL

To use decltype to inspects the declared type of an entity or the type and value category of an expression.

Code Example

// Using lambda to compare elements.
auto cmp = [](int left, int right) { return left < right;};
std::priority_queue<int, std::vector<int>, decltype(cmp)> heap(cmp);

Reference

http://en.cppreference.com/w/cpp/container/priority_queue