草庐IT

insert-if-non-existent

全部标签

c# - 为什么 if( !A && !B ) 不能优化为单个 TEST 指令?

if(!A&&!B)似乎应该编译为moveax,dwordptr[esp+A_offset]testeax,dwordptr[esp+B_offset]jne~~~~~~~~~~编译器实际生成moveax,dwordptr[esp+A_offset]testeax,eaxjne~~~~~~~~~~moveax,dwordptr[esp+B_offset]testeax,eaxjne~~~~~~~~~~看这里转储8B45F8moveax,dwordptr[b]837DFC00cmpdwordptr[a],07504jnemain+32h(0A71072h)85C0testeax,eax7

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

我有以下功能(简化示例):QByteArrayDecompressBytes(constQByteArray&content){/*functionbody(withotherreturnexpressions)*/do{returncontent;}while(content.size()!=0);}添加最后一行用于测试,替换使用的宏。VisualStudio没有发现此代码有问题,但g++生成了warning:controlreachesendofnon-voidfunction[-Wreturn-type]将最后一行更改为returncontent;删除警告。我的问题:为什么编译器

c++ - template<class = enable_if_t<...>> 做什么?

我一直在阅读STL文件,以学习格式化代码的更好方法,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。template,thread>::value>>explicitthread(_Fn&&_Fx,_Args&&..._Ax){//constructwith_Fx(_Ax...)...}std::enable_if_t是templateusingenable_if_t=typenameenable_if::type;templatestructenable_if{//typeis_Tyfor_Testusingtype=_Ty;};该代码在thread和str

c++ - std::enable_if 不能用于禁用此声明

我有一段相当复杂的代码,我将其简化为这个复制器:#include#includetemplatestructouter{templatestructinner{templatestructproblem;usingTA=std::tuple;usingTB=std::tuple;templatestructproblem::value::value>::type>{staticconstexprautoval(){return1;}//actuallyacomplexfunction};templatestructproblem::value>=std::tuple_size::val

c++ - 英特尔线程构建 block 并发队列 : Using pop() over pop_if_present()

与pop()相比,使用阻塞调用有什么区别,while(pop_if_present(...))哪个应该优先于另一个?为什么?我希望更深入地了解在while(pop_if_present(...))情况下轮询自己与让系统为您完成轮询之间的权衡。这是一个很普遍的主题。例如,使用boost::asio我可以执行myIO.run()来阻止或执行以下操作:while(1){myIO.poll()}一个可能的解释是调用while(pop_if_present(...))的线程将保持忙碌,所以这很糟糕。但是某人或某物必须轮询异步事件。当它委托(delegate)给操作系统或库时,为什么以及如何能更便

c++ - if语句中的getline

根据我的阅读,在bool上下文中使用的getline()返回到void*的隐式转换。我在网络上的任何地方都没有找到对这一声明的任何真正引用。它到处都说隐式转换不存在,并且在bool上下文中指针应该是同类的(如果ptr==0比0转换为类型指针ptr).同样在标准中说在bool上下文中它被转换为未指定的bool类型。这到底是什么意思? 最佳答案 简而言之:这意味着您可以在if语句中使用getline(),如果有效,您将进入if语句block。在龙:getline()usedinaBooleancontextreturnsanimplic

c++ - "if (var)"使用数字转换而不是 bool 值

为什么if(var)...使用数字转换而不是bool值?我有一个实现两者的类:operatorint(){....}operatorbool(){....}但是如果我使用:if(my_class_var)....;然后使用int转换而不是boolean?!!?!编辑:正如versedmarald所说,这是正确的。我发现了不同之处。我实际上使用的是:operatorint(){....}operatorbool()const{...}还是被迷住了,为什么不一样?gcc版本4.6.2 最佳答案 如果你说的是真的,我认为你的编译器违反了标

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++ - enable_if 和互斥方法

我不明白为什么下面的代码不起作用。编译器(gcc)似乎同时实例化了两者方法,显然整数是有符号或无符号的,所以总是失败。我虽然enable_if在这里是为了避免这种情况。问:为什么编译出错,如何避免?usingnamespaceboost;//orstdasyouwanttemplatestructtest{//ifsignedtemplate,int>::type=0>test&operator,int>::type=0>test&operatorx;xetc.testy;yetc.} 最佳答案 SFINAE仅适用于immediat

c++ - enable_if 只有 C++11 吗?

在C++引用网站上查找enable_if,据说它只是C++11的一个特性。但是,我在C++98类型上使用GCC编译器编译了我自己的enable_if版本,它运行良好并且似乎能够用于任何版本的C++(打印1):#includenamespaceegg{templatestructenable_if{};templatestructenable_if{typedefTtype;};}intmain(){egg::enable_if::typex=1;std::cout我说的enable_if是任何C++版本的一个有效功能,但只是引入到C++标准中,或者还有其他原因吗?