草庐IT

back_emplace_iterator

全部标签

c++ - std::map emplace/insert 正在插入的移动值

目前我正在阅读C++1y论文,现在我正在尝试理解标题为Improvedinsertioninterfaceforunique-keymaps的n3873论文.该论文指出insert和emplace方法存在问题,它通过以下示例说明了该问题:std::map>m;m["foo"];std::unique_ptrp(newFoo);autores=m.emplace("foo",std::move(p));在上面的代码之后,它表达了以下内容:Whatisthevalueofp?Itiscurrentlyunspecifiedwhetherphasbeenmoved-from.(Theansw

c++ - 对 'std::istreambuf_iterator' 的用法感到困惑

以下是anexamplefromcppreference.com,TheCodeis:#include#include#include#includeintmain(){//typicalusecase:aninputstreamrepresentedasapairofiteratorsstd::istringstreamin("Hello,world");std::vectorv((std::istreambuf_iterator(in)),std::istreambuf_iterator());std::couti1(s),i2(s);std::cout我有两个问题:有人可以详细说

c++ - 如何处理 C++0x STL 中丢失的 'emplace_range'?

我有两个容器,假设它们是这样定义的:std::vector>a;std::vector>b;假设a和b都被填充了。我想使用move语义将整个容器a插入到b中的特定位置,以便unique_ptrmove到b。假设i是指向b中某处的有效迭代器。以下不起作用:b.insert(i,a.begin(),a.end());//error:triestocopy,notmove,unique_ptrs是否有另一种STL算法可以实现这种“move插入范围”?我想我需要一种emplace_range,但VS2010的STL中没有。我不想编写一个一个一个插入的循环,因为每次插入时都会向上movevect

c++ - 我们可以存储 unordered_map<T>::iterator 吗?

引用http://www.careercup.com/question?id=17188673来自chetan.j9voidInsert(strings){if(IsElementPresent(s))return;myMap[s]=myMapVector.size();unordered_map::iteratorit=myMap.find(s);myMapVector.push_back(it);}问题>我们可以存储unordered_map的迭代器供以后检索吗?根据我的理解,插入或删除元素后迭代器将失效。谢谢 最佳答案 @sy

c++ - 是否允许 std::vector::push_back 因重新分配或构造失败以外的任何原因抛出?

考虑:std::vectorv;v.reserve(1);v.push_back(1);//isthisstatementguaranteednottothrow?我选择了int因为它没有可以抛出的构造函数——显然,如果T的某些复制构造函数抛出异常,那么该异常就会转义vector::push_back.这个问题同样适用于insert作为push_back,但它的灵感来自Isitsafetopush_back'dynamicallyallocatedobject'tovector?,这恰好询问push_back.在C++03和C++0x标准/FCD中,vector::insert的描述说

c++ - push_back() 和 emplace_back() 在幕后

我目前正在自学C++,我很好奇push_back()和emplace_back()是如何工作的。当您尝试构建大型对象并将其推到容器的背面时,我一直认为emplace_back()更快。​​假设我有一个Student对象,我想将其附加到Studentsvector的后面。structStudent{stringname;intstudent_ID;doubleGPA;stringfavorite_food;stringfavorite_prof;inthours_slept;intbirthyear;Student(stringname_in,intID_in,doubleGPA_in,

c++ - boost::filter_iterator——我将如何使用 STL 做到这一点?

我收到了一个迭代器,我必须将它传递给另一个函数——但经过过滤以便跳过某些元素(这是一个指针范围,我想过滤掉NULL指针)。我在谷歌上搜索了“STLfilteriterator”以查看如何执行此操作,并且boost::filter_iterator上来了。这看起来不错,我可以使用它,但我也可以使用良好的旧STL来实现吗?当然,无需将元素复制到新容器中。我想我必须创建另一个迭代器类来提供必要的begin()、end()等函数并进行过滤?所以我必须重新实现boostiterator_filter...? 最佳答案 你是对的;您实际上是在自

c++ - 什么是 multimap::emplace() 和 move()?

我正在查看有关multimap的MSDN文档,发现它有一个成员函数multimap::emplace()。下面是该成员函数的示例。intmain(){usingnamespacestd;multimapm1;pairis1(1,"a");m1.emplace(move(is1));}看来emplace()和move()是C++0x。有人可以为我解释一下吗?我阅读了有关move()的内容,但我真的不明白它的作用(在幕后)。 最佳答案 使用vector更容易理解Eplacing。my_vector.emplace_back(1,2,3)

c++ - 从 lambda 函数构造的 boost::function_output_iterator 不可赋值

考虑以下代码片段:autof=[](intx){std::cout问题是,这样构造的function_output_iterator是不可赋值的,因此不满足Iterator概念,要求类型为CopyAssignable.这不是错误,因为boostFunctionOutputIteratordocumentation清楚says:UnaryFunctionmustbeAssignableandCopyConstructible.lambdafunction的While赋值运算符被删除:ClosureType&operator=(constClosureType&)=delete;所以这个行

c++ - std::vector 是否将其值类型的赋值运算符用于 push_back 元素?

如果是,为什么?为什么不使用值类型的拷贝构造函数?我收到以下错误:/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:Inmemberfunction`ClassWithoutAss&ClassWithoutAss::operator=(constClassWithoutAss&)':/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:238:instantiatedfrom`voidstd::vector::_M_insert_aux(__g