如果priority_queue的容器没有push_back功能怎么办

what if the container of priority_queue doesn't have push_back function

本文关键字:push back 功能 怎么办 priority queue 如果      更新时间:2023-10-16

std::priority_queue::push

priority_queue中插入一个新元素。此新元素的内容初始化为 val。

此成员函数有效地调用基础容器对象push_back的成员函数,然后通过对包含容器的所有元素的范围调用 push_heap 算法,将其重新排序到其在堆中的位置。

现在,当我们制作自己的priority_queu并指定一个not in C++ STL且没有push_back函数的container时,std::priority_queue::push将如何工作......?

模板std::priority_queueContainer必须满足SequenceContainer要求并提供front()push_back()pop_back()。没有它们,代码根本无法编译,只是下面的代码无法编译。

template <typename T>
class Fail
{
public:
Fail() {a.make();}
private:
T a;
};
int main()
{
Fail<int> fail_int;
return 0;
}