类模板:
template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> >
class priority_queue;
构造函数:
explicit priority_queue (const Compare& comp = Compare(),
const Container& ctnr = Container());
template <class InputIterator>
priority_queue (InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Container& ctnr = Container());
1. 关于构造函数的第一个参数 const Compare& comp
(1) 如果不指定,则采用类模板参数 Compare 创建的对象,而Compare 的默认值为 less(http://blog.csdn.net/duyiwuer2009/article/details/23277803)
因此,对于自定义结构,有两种方式实现比较操作:
a. 重载 "<"(即采用 less, 因为 less 重载调动操作符,比较通过 "<" 实现的)
b. 自定义 functor——重载调用操作符的类
The third template parameter supplies the means of making priority comparisons. It defaults to @c less<value_type> but can be anything defining a strict weak ordering.
实质上,comp 被传给了底层的堆方法,见下文 priority_queue 的实现
2. priority_queue 实质上不是容器,默认底层容器为 vector
This is not a true container, but an @e adaptor. It holds another container, and provides a wrapper interface to that container.
默认底层容器为 vector
The second template parameter defines the type of the underlying sequence/container. It defaults tostd::vector, but it can be any type that supports @cfront(), @cpush_back, @cpop_back, and random-access iterators, such as