草庐IT

builtin_constant_p

全部标签

c++ - std::regex_constants::optimize 使用的优化技术

我正在使用std::regex,在阅读std::regex_constants中定义的各种常量时,我​​遇到了std::optimize,阅读它,听起来它在我的应用程序中很有用(我只需要一个正则表达式实例,在开始时初始化,但在整个加载过程中多次使用它)。根据workingpapern3126(第1077页),std::regex_constants::optimize:Specifiesthattheregularexpressionengineshouldpaymoreattentiontothespeedwithwhichregularexpressionsarematched,a

c++ - 带有 -fno-builtin 的 GCC 似乎不起作用

我想比较GCC内置函数memcpy和libc中的函数。但是,-fno-builtin或-fno-builtin-memcpy的所有迭代似乎都被忽略了。//g++-O3foo.cpp-Sor//g++-O3-fno-builtinfoo.cpp-S#includeintmain(){volatileintn=1000;//intn=1000;float*x=newfloat[1000];float*y=newfloat[1000];memcpy(y,x,sizeof(float)*n);//__builtin_memcpy(y,x,sizeof(float)*n);}我发现,如果上面源代

c++ - 为什么 __builtin_prefetch 在这里没有任何作用?

我正在编写一个程序来解析文件。它由一个逐个字符解析并处理它们的主循环组成。这是主循环:charc;char*ptr;for(size_ti=0;i(sentenceMap)+i);c=*ptr;__builtin_prefetch(ptr+i+1);//sometreatmentonptrandc}如您所见,我添加了一条builtin_prefetch指令,希望在我的循环的下一次迭代中放入缓存。我尝试了不同的值:ptr+i+1、ptr+i+2、ptr+i+10,但似乎没有任何变化。为了衡量性能,我使用了valgrind的工具cachegrind,它可以指示缓存未命中数。在c=*ptr行

c++ - __builtin_offsetof 运算符的用途和返回类型是什么?

C++中__builtin_offsetof运算符(或Symbian中的_FOFF运算符)的用途是什么?此外它还返回什么?指针?字节数? 最佳答案 它是GCC编译器提供的内置函数,用于实现C和C++标准指定的offsetof宏:GCC-offsetof它返回POD结构/union成员所在的偏移量(以字节为单位)。示例:structabc1{inta,b,c;};unionabc2{inta,b,c;};structabc3{abc3(){}inta,b,c;};//non-PODunionabc4{abc4(){}inta,b,c;

c++ - __builtin_round 不是常量表达式

在G++中,各种内置数学函数在某些条件下是constexpr。例如,以下编译:staticconstexprdoubleA=__builtin_sqrt(16.0);staticconstexprdoubleB=__builtin_pow(A,2.0);虽然它们并不总是constexpr,这取决于参数。例如,__builtin_sqrt(NAN)在用作常量表达式时会导致编译错误。但我遇到了一个奇怪的情况,在我看来它应该是constexpr,但它不是:staticconstexprdoublevalue(){return1.23;}staticconstexprdoubleresult=

c++ - clang 中 regex_constants 的错误实现?

如standard中所述:match_prev_avail:--first是一个有效的迭代器位置。设置后,会导致match_not_bol和match_not_bow被忽略但我运行以下代码并得到:#include#includeusingnamespacestd;intmain(){regexre0("^bcd");stringstr="abcd";std::string::iteratorstart=str.begin()+1;cout输出:010match_prev_avail似乎被match_not_bol覆盖了。 最佳答案

c++ - std::integral_constant 背后的原因是什么?

它的实际用例是什么?std::integral_constant我可以理解这是一个值为2的包装器:typedefstd::integral_constanttwo_t但为什么不直接使用2或用2定义一个constint值呢? 最佳答案 在少数情况下std::integral_constant非常有用。其中之一是标签分发。例如,std::true_type和std::false_type只是std::integral_constant和std::integral_constant分别。每个typetrait源自std::true_typ

c++ - 为什么使用静态 "constants"而不是实际值?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion我正在查看最小二乘法的代码,我遇到了以下几行:staticdoubleone=1.0;staticdoublep1=0.1;staticdoublep5=0.5;...我想知道为什么有人会为1.0定义一个static。例如,我可以理解pi有一些东西,但是对于1.0和0.1等微不足道的数学值?我认为这会降低代码的可读性,但它可能还有一些我遗漏的其他好处。那么,这些定义有原因吗?或者,如果它没

c++ - 什么是 "symbolic constants"和 "magic constants"?

在BjarneStroustrup的ATourofC++中,每章末尾都列出了一些建议。在第一章的结尾,其中一个写道:Avoid‘‘magicconstants;’’usesymbolicconstants;什么是魔法常量和符号常量? 最佳答案 somethingElse=something*1440;//amagicconstantsomethingElse=something*TWIPS_PER_INCH;//asymbolicone第一个是魔法常量的例子,它除了它的值之外没有传达任何其他信息。后者更有用,因为意图很明确。如果您有

c++ - 为什么是非法的: copying vector of pointers into a vector of pointers to constants

问题以下代码无法在C++11(或C++14)中编译。我理解编译器的错误输出,但为什么标准不允许?//main.cpp#includeintmain(void){doublea=3.0;doubleb=3.0;//Itworkswithmerepointersconstdouble*ptrToConst=&a;/***/double*ptrToObj=&a;//ptrToObj=ptrToConst;//Illegal:that'sunderstandable…ptrToConst=ptrToObj;//Works//Butthesamedoesn'tworkwithvectorstop