草庐IT

queue_inserter

全部标签

c++ - 为什么在 std::copy 期间使用 std::back_inserter 而不是 end()?

我见过std::copy()使用std::back_inserter但我使用了std::end()并且两者都有效.我的问题是,如果std::end()工作正常,为什么还需要std::back_inserter?#include#include#include#includeusingnamespacestd;intmain(){//Declaringfirstcontainervectorv1={1,2,3};//Declaringsecondcontainerfor//copyingvaluesvectorv2={4,5,6};//Usingstd::back_inserterins

c++ - insert in string的效率

我正在尝试为比longlong更大的非常大的整数编写这个自定义加法类。我正在研究的一种方法是将整数保留为字符串,然后将字符转换为它们的int组件,然后添加每个“列”。我正在考虑的另一种方法是将字符串拆分为多个字符串,每个字符串都是longlong的大小,然后使用字符串流将其转换为longlong添加然后重新组合。无论如何,我发现加法最容易反向完成以允许结转数字这一事实。在这种情况下,我想知道字符串插入方法的效率。似乎因为一个字符串是一个字符数组,所以所有的字符都必须移动一个。所以它会有所不同,但效率似乎是O(n),其中n是字符串中的字符数。这是正确的,还是只是天真的解释?编辑:我现在对

c++ - 是否可以推断出 std::insert_iterator 包含的类型?

我有一个需要模板化迭代器类型的函数。它当前取消引用迭代器以检查被迭代的类型。templatevoidfunc(Iteratori){//Inspectthesizeoftheobjectsbeingiteratedconstsize_ttype_size=sizeof(*i);...}我最近发现一些标准迭代器类型,例如std::insert_iterator将*i定义为对i的简单引用.即sizeof(*i)是迭代器本身的大小;与sizeof(i)或sizeof(***i)相同是否有一种通用方法(支持C++03)来确定任何标准迭代器正在迭代的对象的大小或类型?

c++ - 为什么这个自定义比较器在构造 std::priority_queue 时失败,而它适用于 std::sort?

比较器comp定义如下。它适用于std::sort,但无法在std::priority_queue的构造函数中编译。问题是什么?谢谢。#include#include#includeusingnamespacestd;boolcomp(inta,intb){returna>b;}intmain(){vectorvec={4,2,1,3};sort(vec.begin(),vec.end(),comp);//OKpriority_queueq1(less(),vec);//OKpriority_queueq2(comp,vec);//Failreturn0;}错误信息:error:nom

c++ - 使用 `std::copy()` 和 `std::back_inserter()`

我有两个A类和B类都有如下成员:classA{...std::vector>>grid;}classB{...std::vector>>grid;}我发现当我使用std::copy()从A::grid复制到B::grid时,它会失败。这是我所做的://HereisinB'sconstructor.//IinitializeB::gridwiththesamesizeofA::gridgrid=vector>>(GetSetting().grid_cols());for(inti=0;i>(GetSetting().grid_rows());for(intj=0;j但如果我删除初始化部分

C++ 在 priority_queue 中使用 std::greater() 并排序

为什么这两种情况的文档说的是同一件事,但它们以相反的方式声明,一个使用greater而另一个使用greater().任何人都可以解释一下吗?文档priority_queuecpplibrary说那个compcanbeComparisonobjecttobeusedtoordertheheap.Thismaybeafunctionpointerorfunctionobjectpriority_queue,greater>minheap;//workspriority_queue,greater()>minheap;//whyfail?文档cpplibrarysort说的是同一件事,即co

C++ std::queue 不想 push()

这是一个简单的类和简单的测试函数:#include#includenamespace{usingnamespacestd;}classNameStream{queuestream;public:stringoperator*(){returnstream.front();}NameStream&operator++(int){stream.pop();return*this;}NameStream&operator++(){stream.pop();return*this;}NameStream&operator它落在NameStream&operator在队列的推送过程中,这是我的代

c++ - 为什么在使用 std::map::insert() 时编译顺序有时会导致段错误?

我有一个类叫做Controller,在其中,我有一个名为Button的类.Controller包含几个Button不同类型的实例(例如button_type_a、button_type_b)。controller.h#ifndef__controller__#define__controller__classController{public:classButton{public:Button(inttype=-1);private:inttype;};Controller();ButtonA;ButtonB;ButtonX;ButtonY;};#endif按钮类型为ints,我希望能

c++ - 从 priority_queue 弹出时出现排序问题,这是 std::priority_queue 的错误吗

#include#include#include#includestructTemp{intp;std::stringstr;};structTempCompare{booloperator()(Tempconst&a,Tempconst&b){returna.p>b.p;}};intmain(){std::priority_queue,TempCompare>pq;//EnableandDisablethefollowinglinetoseethedifferentoutput//{Tempt;t.p=8;t.str="str1";pq.push(t);}{Tempt;t.p=8;t

c++ -/boost/lockfree/queue.hpp: 错误: 静态断言失败: (boost::has_trivial_destructor<T>::value)

我正在尝试替换boost::lockfree::queue对于std::queue在这个文件中https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp我添加了#include;改线130,std::queuem_actions;,至boost::lockfree::queuem_actions;;删除所有与锁定有关的行;并更改了行103,m_actions.pop();,至m_actions.pop(a);.我在sconsbroadcas