如果priority_queue的容器没有push_back功能怎么办
what if the container of priority_queue doesn't have push_back function
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_queue
的Container
必须满足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;
}
相关文章:
- 推导 std::vector::back() 的返回类型
- vector.back() 和 vector[vector.size() - 1] 之间的区别?
- vector.push_back(vector.back()+1) 是未定义的行为吗?
- C++自己的对象堆栈.在 push() 上复制了什么?
- C++ push() 和 pop() 方法使用指针的动态 LinkedList 的问题
- 如何像在javascript中一样"push" c ++映射
- 线路抑制状态错误 C4703 可能未初始化的局部指针变量"back"已使用
- std::vector using back(), pop_back(), push_back(), 得到'double free or corruption'错误
- vector.back()和vector.end()有什么区别
- 列表大小为 1,但 front() 和 back() 不相等
- 返回C++中没有 back() 方法的容器的最后一个元素?
- 在非空 std::list 上使用 std::list.back<int>() 时"Segmentation Fault"
- 模板堆栈类的复制构造函数中的 pop() 和 push() 不起作用
- 我们可以使用Back() - 值索引在其上执行向量插入
- 当我运行以下代码添加str.front() str.back时,它给了我200个,但为什么
- push(ing)back在循环中对象指针
- 在 C++ 中将元素添加到空向量:为什么 push.back 有效而 [] 无效
- 我似乎无法让 v.push.back() 处理字符串
- String::push_back() does not push back
- 向量resize(), push.back(), reserve()方法