草庐IT

already_inserted

全部标签

c++ - 减少冗长 : inserting elements into map

我最近在熟悉C++11,auto关键字很棒!打字:for(autobar:bars){太令人满意了。保持代码的可读性和美观。仍然感觉它停止了你所有的动力如下:foo.insert(std::pair("soVerbose",baz));//Asopposedtosimply:foo.insert("soVerbose",baz);它是这样的有充分的理由吗?有什么巧妙的方法可以让它不那么冗长吗?我知道[]运算符可用于将元素插入map,但功能略有不同。 最佳答案 使用emplace功能:#include#include#includei

c++ - "already a friend"警告什么时候有用?

我的代码使用大量预处理器框架来生成一些实用程序类。显然,某些宏会导致相同的friend声明在一个类中被包含两次,如下所示:classFriendly{//:::friendclassBestie;friendclassBestie;//:::};当使用gcc(4.8.1)构建时,它会生成类似这样的警告BestieisalreadyafriendofFriendly[enabledbydefault]我真的看不出这个警告有什么用。我很好奇为什么它首先包含在gcc中。然而,由于SO社区很难回答这个问题,我将这样陈述我的问题:出现指示?我能想到的唯一可能暗示的问题是“你可能打算在这里写一些别

c++ - 模拟条件 back_inserter 之类的最佳方法?

我想用以下代码中的算法替换循环intnumbers[]={...};vectoroutput;for(int*it=numbers+from;it!=numbers+to;++it){intsquare=func(*it);if(predicate(square)){output.push_back(square);}}该程序旨在转换值并在条件发生时将它们复制到目的地。我无法使用std::copy_if,因为那样不会应用转换。我无法使用std::transform因为它缺少谓词因为转换变量的中间拷贝,编写transform_copy_if()甚至不是一个好主意。看来我唯一的希望是创建一

c++ - 是什么导致 VS2013 错误 LNK2005 : __xi_a already defined in MSVCRT. lib(cinitexe.obj)?

我的解决方案是昨天构建的。今天,除了.hpp和.cpp文件外,它没有改变任何东西。VisualStudio2013的完整错误文本(使用2013年11月CTP):Error1errorLNK2005:__xi_aalreadydefinedinMSVCRT.lib(cinitexe.obj)C:\Users\drtwox\dev\repos\game\trunk\engine\game\LIBCMT.lib(crt0init.obj)gameError2errorLNK2005:__xi_zalreadydefinedinMSVCRT.lib(cinitexe.obj)C:\Users\

c++ - 为什么 gcc-4.9.2 不支持 std::string.insert(iterator, range) 返回迭代器

根据cppreference,C++11应该支持:templateiteratorinsert(const_iteratorpos,InputItfirst,InputItlast);但是当我尝试使用g++4.9.2编译以下代码时:std::stringstr{"helloworld"},addition{"hmy"};autoiter=str.erase(str.begin(),str.begin()+4);iter=str.insert(next(iter),addition.begin(),addition.end());//Error我收到以下错误(liveexample):e

c++ - std::vector insert() 重新分配

我查看了std::vector代码,发现了一些我不太明白的东西。当capacity分配新缓冲区复制旧缓冲区的前缀(0-插入索引)在新缓冲区中构造新元素复制旧缓冲区的后缀(index-end)对旧缓冲区中的所有项目调用析构函数释放旧缓冲区据我所知,前缀和后缀的复制是用memmove完成的。memmove不是数据的纯二进制拷贝吗?它不会调用元素的构造函数,是吗?我想知道的是,如果内存只是移动,而不是在新缓冲区中重新构造,为什么函数会调用旧缓冲区中元素的析构函数? 最佳答案 我查看了MSVC8vector实现-我看不到memmove().

c++ - vim + C++ : insert a uuid in a guard clause

我正在尝试自动化文件注释标题。我一直在尝试弄清楚如何使用vim的autocmd将uuidgen命令的结果插入到我的header中。在页眉中,存在占位符文本,如下所示:#ifndef_UUID_#define_UUID_//Codegoeshere!#endif//_UUID_在.vimrc中填充_UUID_的自动命令行是:autocmdbufnewfile*.hexe"1,$s/_UUID_/".r!uuidgen."/g"问题出在r!uuidgen下。如何将shell命令执行的结果作为文本插入到autocmd行中?或者在vi替换命令中? 最佳答案

c++ - std::map::insert(...) 中的段错误

我使用了搜索,但没有找到令我满意的答案...所以...这是一段代码://VoteContainer.htypedefuint32_torder_id_t;typedefintdriver_id_t;classVote{public:enumDriverVoteResponse{YES,NO,TIMEOUT};structDriverResponse{driver_id_tdriver_id;time_ttime;DriverVoteResponseresponse;};Vote():m_order_id(0),m_time_until(0){};Vote(order_id_tinOrd

c++ - 如何正确(但有效地)实现类似 "vector::insert"的东西? (指针别名)

考虑vector的这个假设实现:template//ignoretheallocatorstructvector{typedefT*iterator;typedefconstT*const_iterator;templatevoidinsert(iteratorwhere,Itbegin,Itend){...}...}问题我们在这里面临一个微妙的问题:begin和end有可能引用同一vector中的项目,afterwhere。例如,如果用户说:vectoritems;for(inti=0;i如果It不是指针类型,那么我们没问题。但是我们不知道,所以我们必须检查[begin,end)没有

解决es报错:the shard cannot be allocated to the same node on which a copy of the shard already exists

一:报错信息通过命令:curl-XGET"http://{ip}:9200/_cluster/allocation/explain"查看集群状态:可以看到其active_shards_percent为36.1%,elasticsearch健康状态为yellow,原因就是其存在UNASSIGNEDshards的情况,而此时也影响到了es的正常使用。二、分析原因:如果我们只有一台机器,部署运行了es,但是却在index的settings中设置了replica为1,那么这个replicashard就会成为unassignedshards,因为分片不能分配到已经存在分片副本的同一节点.而当我们在查看原