草庐IT

std=c++11

全部标签

c++ - VC++11 映射和多映射迭代器(重载)C2535

我正在玩新的VS2012,我可能对新的C++11有疑问。当我在项目设置中将平台工具集设置为VS2010(v100)时,这段代码完美运行。.h:typedefstd::multimapSizeMap;typedefstd::mapOffsetMap;private:inlinevoid_RemoveBlockL(SizeMap::iteratorsizeI);inlinevoid_RemoveBlockL(OffsetMap::iteratoroffsetI);.cpp:inlinevoidFoo::_RemoveBlockL(SizeMap::iteratorsizeI){//impe

c++ - 通过模板化引用传递 C++11 lambda

在gcc4.5中,使用-std=c++0x,以下代码可以按预期编译和工作,#includetemplatevoidcaller(Hh){h();}intmain(){autoc=[](){printf("A\n");};caller(c);caller([](){printf("B\n");});return0;}打印,AB但是,如果caller被定义为引用,templatevoidcaller(H&h){h();}编译器提示,test.cpp:Infunction‘intmain()’:test.cpp:61:34:error:nomatchingfunctionforcallto‘

c++11 standard-layout - 使用相同的访问控制

我认为POD(c++11,琐碎+标准布局)的全部意义在于确保类型与C兼容。给定以下代码://thatoneisastandardlayout,andtrivialwhichmakesitac++11PODstructBar{public:intx;public:inty;};AFAIU,编译器可能会重新排序x和y。这不会破坏与C的兼容性吗?为什么c++11中的98/03POD定义放宽被认为是个好主意? 最佳答案 AFAIU,compilermightreorderxandy.Wouldn'tthatbreakcompatibilit

c++ - 从 std::tuple 成员中移除引用

我在STL元组的帮助下实现了一些变量的保存/恢复功能,如下所示:doublea=1,b=2;intc=3;autotupleRef=std::make_tuple(std::ref(a),std::ref(b),std::ref(c));//hereI'msavingcurrentstateofa,b,cstd::tuplesaved=tupleRef;//heregoesblockofcode,wherea,b,andcgetspoiled......................////nowI'mrestoringinitialstateofa,b,ctupleRef=save

C++ 编译错误 - 命名空间 std 中的 "no type named ' 函数”

我正在为我的C++编程类(class)作业,其中涉及实现HashMap。我的导师给了我们一个头文件,我们需要将其与我们的HashMap类一起使用。提供的头文件包含以下行:typedefstd::functionHashFunction;根据我对C++的(有限的)理解,这会将HashFunction类型定义为std::function。但是,当我编译代码时,出现错误:./HashMap.h:46:15:error:notypenamed'function'innamespace'std'typedefstd::functionHashFunction;~~~~~^./HashMap.h:

c++ - boost std unique_ptr 的 STL 集合的序列化

我希望能够序列化std::unique_ptr的STL容器。可以吗?顺便说一句,单个std::unique_ptr一切正常。下面是我正在处理的代码,gcc给出了以下错误:useofdeletedfunction‘std::unique_ptr::unique_ptr(conststd::unique_ptr&)[with_Tp=MyDegrees;_Dp=std::default_delete;std::unique_ptr=std::unique_ptr]’如何使代码正常工作?#include#include#include#include#include#include#inclu

c++ - std::map 插入错误:没有运算符 "<"匹配这些操作数

在尝试提高我的C++和STL熟练程度时,遇到了std::map的问题,该问题由我定义的结构键入。相关代码:typedefstructkey_t{inta;intb;booloperator==(constkey_t&rhs){return(a==rhs.a)&&(b==rhs.b);}booloperatorfooMap;voidfunc(void){key_tkey;key.a=1;key.b=2;fooMap.insert(std::pair(key,100));}错误看起来像这样:"/opt/[redacted]/include/functional",line133:error

c++ - boost::container::vector 比 std::vector 快吗?为什么?

我对boostvector和stdvector做了一个有趣的测试如下intN=10000;{boost::timer::auto_cpu_timert;std::vectorv;for(inti=0;iv;for(inti=0;iwin32版本,vc2010编译,/O2/Oy-对于N=10000对于标准vector:0.140849s墙,0.140401s用户+0.000000s系统=0.140401sCPU(99.7%)fboostvector:0.056174s墙,0.062400s用户+0.000000s系统=0.062400sCPU(111.1%)对于N=100,000标准:1

c++ - std::vector 类型引用的无效初始化

这是错误:DummyService.hpp:35:error:invalidcovariantreturntypefor'virtualstd::vector>&DummyService::list(conststd::string&)'classBean{public:typedefstd::stringPath;virtual~Bean(){};virtualconstPath&getPath()=0;virtualconststd::string&getName()=0;protected:Bean();};classResourceBean:publicBean{public:

c++ - 成员函数检查 : Implement compilation-time checkings with C++11 features

我读到C++11有足够的静态检查(编译时),以便实现C++11的大部分内容(已删除)。(我在最近关于已删除概念的问题的评论中读到过此内容...-该问题因不具有建设性而很快被关闭)。下面的C++03代码仅检查类中是否存在成员函数(我的模板类要在该类上工作)。这里有4个搜索的成员函数,我总是使用相同的模式:定义函数原型(prototype)的typedef如果类型名称TExtension没有定义这样的成员函数,或者如果它有不同的原型(prototype),则调用static_cast会中断编译代码如下:templateclass{...voidcheckTemplateConcept(){