jjzjj

CONSTANT

全部标签

c++ - 编译器优化 "constant propagation"是什么意思?

摘自ScottMeyers的EffectiveC++:templateclassSquareMatrix:privateSquareMatrixBase{public:SquareMatrix():SquareMatrixBase(n,0),pData(newT[n*n]){this->setDataPtr(pData.get());}...private:boost::scoped_arraypData;};Regardlessofwherethedataisstored,thekeyresultfromabloatpointofviewisthatnowmany—maybeall—

c++ - 海湾合作委员会 4.1.2 : error: integer constant is too large for ‘long’ type

我编译了一段关于散列函数的代码并得到了错误:整数常量对于‘long’类型来说太大了。我用谷歌搜索了一下,它说要添加后缀“ULL”,但我确实有ULL作为后缀。这个后缀只有gcc4.4.1支持,我机器上只有gcc4.1.2,不允许安装新的编译器。有什么方法可以更改代码以解决问题吗?谢谢,-托尼unsignedlonglonghash(stringk){//FNVhashunsignedlonglongx=14695981039346656037ULL;for(unsignedinty=0;y 最佳答案 1099511628211对于(3

C++ : Initializing base class constant static variable with different value in derived class?

我有一个带有常量静态变量a的基类A。我需要类B的实例对静态变量a具有不同的值。这怎么能实现,最好是静态初始化?classA{public:staticconstinta;};constintA::a=1;classB:publicA{//???//Howtoset*a*toavaluespecifictoinstancesofclassB?}; 最佳答案 你不能。所有派生类共享一个静态变量实例。 关于C++:Initializingbaseclassconstantstaticvaria

c++ - std::bool_constant 背后的基本原理

我想知道,引入std::bool_constant背后的基本原理是什么?及其随后用于std::true_type和std::false_type(以及在头文件中定义的比较结构,参见N4389)在C++17中?到目前为止,我只能找到包含以下措辞的论文:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4334.htmlhttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4389.html虽然这两篇论文都提到了“基本原理”——https://issues.isocp

c++ - 在常数值上强制 Clang 为 "perform math early"

这与Howtoforceconstpropagationthroughaninlinefunction?有关Clang有一个集成的汇编程序;而且它不使用系统的汇编程序(通常是GNUAS(GAS))。非Clang早期执行了数学运算,一切都“正常工作”。我说“早”是因为@n.m。反对将其描述为“预处理器执行的数学运算”。但是这个想法是这个值在编译时是已知的,应该尽早评估它,就像预处理器评估#if(X%32==0)时一样。.下面,Clang3.6提示违反了约束。似乎常量没有在整个过程中传播:$exportCXX=/usr/local/bin/clang++$$CXX--versionclan

c++ - std::integral_constant<T, v>::value 总是有定义吗?

在C++14标准中,std::integral_constant模板定义如下:templatestructintegral_constant{staticconstexprTvalue=v;typedefTvalue_type;typedefintegral_constanttype;constexproperatorvalue_type()constnoexcept{returnvalue;}constexprvalue_typeoperator()()constnoexcept{returnvalue;}};它没有说明静态数据成员是否有相应的外联定义,即,templateconst

c++ - 编译时模板 `std::integral_constant` 计数器 - 如何实现它?

我有几种类型,我想“绑定(bind)”一个std::integral_constant编译时每种类型的顺序ID值。例子:structType00{};structType01{};structType02{};structType03{};structTypeXX{};structTypeYY{};templatestructTypeInfo{usingId=std::integral_constant;};intmain(){cout::Id::value;//Shouldalwaysprint0cout::Id::value;//Shouldalwaysprint1cout::Id

c++ - 为什么 `constexpr const int &a = 1;` 在 block 范围内失败?

N45277.1.5[dcl.constexpr]p9Aconstexprspecifierusedinanobjectdeclarationdeclarestheobjectasconst.Suchanobjectshallhaveliteraltypeandshallbeinitialized.Ifitisinitializedbyaconstructorcall,thatcallshallbeaconstantexpression(5.20).Otherwise,orifaconstexprspecifierisusedinareferencedeclaration,everyf

c++ - 部分模板特化和 icc

考虑以下代码:templatestructFoo{};templatestructFoo>{staticvoidprint(){std::cerrstructFoo>{staticvoidprint(){std::cerr>;Baz::print();return0;}当我使用icc16.0.1编译它时,我收到以下消息:main.cpp(38):error:morethanonepartialspecializationmatchesthetemplateargumentlistofclass"Foo>""Foo>""Foo>"Baz::print();使用clang3.7.1和gcc

c++ - 预处理器 "invalid integer constant expression"比较 int 和 double

在我的代码中的某处,我有预处理器定义#defineZOOM_FACTOR1我在另一个地方#ifdefZOOM_FACTOR#if(ZOOM_FACTOR==1)#defineFONT_SIZE8#else#defineFONT_SIZE12#endif#else#defineFONT_SIZE8#endif问题是当我将ZOOM_FACTOR值更改为float值时,例如1.5,出现编译错误C1017:无效的整数常量表达式。有谁知道我为什么会收到这个错误,有没有办法在预处理器指令中比较integer和floatingpointnumber? 最佳答案