草庐IT

back_emplace_iterator

全部标签

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++ - 将参数包传递给 emplace STL 函数会导致编译错误

根据emplace_back的定义,voidemplace_back(Args&&...args);是一个可变模板函数。所以,我写了以下内容:#includeintmain(){std::vectormyvector2(10,0);myvector2.emplace_back(1,2,3,4,5,6);}编译器提示:g++-std=c++0xstlstudy.cc‘Internalcompilererror:Errorreportingroutinesre-entered.Pleasesubmitafullbugreport,withpreprocessedsourceifapprop

c++ - 如何为非 const 类调用 const_iterator?

这个问题在这里已经有了答案:Howtousetwofunctions,onereturningiterator,theotherreturningconst_iterator(2个答案)关闭8年前。我阅读了一些与此问题相关的其他线程,但没有为我的问题提供解决方案。希望大家给我出出主意或建议。我正在尝试实现这个名为Map的类。它应该包含2个迭代器-iterator和const_iterator。我实现了它们-iterator继承自const_iterator,在Map类中我有以下函数:iteratorbegin();iteratorend();const_iteratorbegin()c

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++ - 当没有任何意义时, `Iterator::pointer` 使用什么?

例如,考虑一些假设的to_upper_iterator遍历一系列字符,返回std::toupper对于operator*.这些迭代器别名对我来说很有意义:templatestructto_upper_iterator{usingvalue_type=CharT;usingreference=CharT;usingdifference_type=std::ptrdiff_t;usingiterator_category=std::random_access_iterator_tag;};没有意义的是什么应该/可以用于pointer别名。我试着把它关掉,但果然我遇到了编译错误。似乎这是由于

c++ - 错误 : no matching member function for call to 'push_back'

为什么我在最后两行收到错误?目标是在集合中找到对象,并修改其内容。usingnamespacestd;structmystruct{intid;vectory;mystruct(constintid):id(id){}booloperatorsx;mystructx(1);x.y.push_back(1);x.y.push_back(2);sx.insert(x);//set::iteratori=sx.find(1);constmystruct*x1=&(*i);constmystructx2=*x1;couty)y)y.push_back(4);}好像迭代器返回的是常量对象,不让我

c++ - std::map::const_iterator 泄露了对值的非常量引用?

我观察到std::map::const_iterator泄漏了对value_type的非常量引用:#include#includeintmain(intargc,char*argv[]){std::mapfoo={{1,1},{4,2}};constauto&m=foo;constauto&it=foo.find(1);printf("%d%d\n",it->first,it->second);int&i=it->second;i=3;auto&one=foo.at(1);printf("%d%d\n",1,one);return0;}输出$g++test.cc&&./a.out111

c++ - 如何从 OpenGL 加载图像 BACK?

我已经成功地将图像作为纹理加载到OpenGL(我使用GTKmm库中的Gdk::Pixbuf),但我不知道如何从OpenGL获取修改后的图像并将其加载到Gdk::Pixbuf...我想在OpenGL中修改图像并将它们保存在硬盘上。有一些代码:Glib::RefPtrpixmap=Gdk::Pixbuf::create_from_file("image.jpg");GLuinttexture[1];glBindTexture(GL_TEXTURE_2D,texture[1]);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LI

c++ - 如果容器元素是指针,为什么允许我从 const_iterator 调用非 const 成员函数?

考虑以下代码:#includeusingnamespacestd;structfoo{voidbar(){}};intmain(){{vectora;a.push_back(newfoo());a.push_back(newfoo());a.push_back(newfoo());vector::const_iteratoritr=a.begin();(*itr)->bar();//compiles-thisbecomesmoreconfusing//whenfoundinaconstmethod.Onfirst//glance,onewill(oratleastme)may//ass

c++ - 带有 volatile 的 push_back 与 emplace_back

以下代码对push_back失败,对emplace_back成功:#includevolatileintx=0;intmain(){std::vectorvec;vec.emplace_back(x);vec.push_back(x);//error:nomatchingfunctionforcallto'std::vector::push_back(volatileint&)'}我知道push_back失败是因为它需要一个引用并试图从该引用中隐式地丢弃volatile限定符。然而,emplace_back也接受一个引用(右值引用是引用)。为什么区别对待?