草庐IT

enable_if_c

全部标签

c++ - 将附加参数传递给 remove_if

我想使用remove_if函数从vector中删除元素,但将删除限制为N个元素。例子://predicatefunctionthatdeterminesifavalueisanoddnumber.boolIsOdd(inti){if(wedeletedmorethandeleteLimit)returnfalse;return((i%2)==1);}voidotherFunc(){intdeleteLimit=10;//removeoddnumbers:std::vector::iteratornewEnd=std::remove_if(myints.begin(),myints.en

c++ - boost::enable_if 不在函数签名中

这只是一个关于样式的问题:我不喜欢C++的模板元编程方式,它要求您使用返回类型或为SFINAE的技巧添加额外的虚拟参数。所以,我想到的是将SFINAE放在模板参数定义本身中,如下所示:#include#include#includeusingnamespacestd;template>::type>voidasd(){cout>::type>voidasd(){cout();asd();}这个例子让g++提示:../src/afg.cpp:10:97:error:redefinitionof‘templatevoidasd()’SFINAE本身可以工作,因为如果我删除例如带有disab

C++ 模板元编程, "static if"解决方法 - 可以改进吗?

我有一个函数可以扫描用户的文件系统,用路径填充一个vector,然后对它进行排序或不排序。由于用户应该能够在编译时决定他是否想要对vector进行排序,因此我使用模板和辅助类来代替非常需要(但不存在)的“静态if”。考虑这段代码:enumclassSort{Alphabetic,Unsorted};templatestructSortHelper;templatestructSortHelper{staticvoidsort(vector&mTarget){sort(begin(mTarget),end(mTarget));}};templatestructSortHelper{sta

c++ - 我如何在 Flex/bison 中实现 If 语句

我没有收到错误,请你帮我解决一下,这是.l和.y文件。谢谢。%{#include"ifanw.tab.h"externintyylval;%}%%"="{returnEQ;}"!="{returnNE;}""{returnGT;}">="{returnGE;}"+"{returnPLUS;}"-"{returnMINUS;}"*"{returnMULT;}"/"{returnDIVIDE;}")"{returnRPAREN;}"("{returnLPAREN;}":="{returnASSIGN;}";"{returnSEMICOLON;}"IF"{returnIF;}"THEN"{r

c++ - 如何在if语句的括号内声明一个变量?

我想在if语句的括号中声明一个局部变量。例如。if((charc=getc(stdin))==0x01)//ThisisnotOKwithg++.{ungetc(c,stdin);}我要的是,看看这个角色是不是我想要的。通俗地说,我想在if的行和if的主体中都使用变量(charc),但不在if.但是g++(GCC4.8.1)说expectedprimary-expressionbefore'char'。我想知道是否有办法做到这一点,因为我不想要类似的东西charc=getc(stdin);if(c==0x01){bla...} 最佳答案

c++ - if(double) 有效的 C++ 吗?

我刚遇到这行代码:if(lineDirection.length2()){...}其中length2返回一个double。让我有点困惑的是0.0等同于0、NULL和/或false。这是C++标准的一部分还是未定义的行为? 最佳答案 这是一个非常标准的行为(bool转换)$4.12/1-"Anrvalueofarithmetic,enumeration,pointer,orpointertomembertypecanbeconvertedtoanrvalueoftypebool.Azerovalue,nullpointervalue,

c++ - SFINAE enable_if 显式构造函数

我正在尝试通过enable_if在显式和隐式转换构造函数之间切换。我的代码目前看起来像#include#includeenumclassenabled{};templateusingenable_if_t=typenamestd::enable_if::type;templateusingdisable_if_t=typenamestd::enable_if::type;templatestructSStruct{staticconstexprstd::intmax_ta=A;};templatestructSCheckEnable:std::integral_constant{};t

c++ - 使用 GCC 优化 C/C++ 循环中的嵌套 if 语句

我正在使用GCC编译器测试C/C++中的各种优化。我目前有一个包含多个嵌套if语句的循环。条件是在程序开始执行时计算的。它看起来有点像这样:boolconditionA=getA();boolconditionB=getB();boolconditionC=getC();//Etc.startTiming();do{if(conditionA){doATrueStuff();if(conditionB){//Etc.}else{//Etc.}}else{doAFalseStuff();if(conditionB){//Etc.}else{//Etc.}}}while(testCondi

c++ - "if the context from which the specialization is referenced depends on a template parameter"是什么意思?

根据C++17标准,[temp.point]/4,强调我的,Foraclasstemplatespecialization,aclassmembertemplatespecialization,oraspecializationforaclassmemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecialization,ifthecontextfromwhichthespecializationisrefere

c++ - if 语句中的复合表达式

我偶然发现了执行此操作的能力。#includeusingnamespacestd;intmain(){if(({inti=1024;i==10;})){cout重要的反汇编区域好像是:->0x10000118f:movl$0x400,-0x18(%rbp);imm=0x4000x100001196:cmpl$0xa,-0x18(%rbp)0x10000119a:sete%al0x10000119d:andb$0x1,%al0x10000119f:movb%al,-0x19(%rbp)0x1000011a2:testb$0x1,-0x19(%rbp)0x1000011a6:je0x100