草庐IT

with_static

全部标签

c++ - 如何仅在实际使用成员模板时才在成员模板中进行 static_assert?

考虑这个简单的类:templateclassFoo{public:Foo(Tconst&val):_val(val){}templateFoo(Fooconst&){static_assert(false,"CannotconvertfromFootoFoo.");}operatorT&(){return_val;}operatorTconst&()const{return_val;}private:T_val;};它允许从模板类型隐式构造并隐式转换回该类型,一个简单的包装器。现在,我不想启用不相关的Foo之间的转换,由于这些隐式构造/转换,这是可能的。我可以将模板化复制构造函数设为私

c++ - C 和 C++ 中的 Const、static、extern 及其组合

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭10年前。1)static、extern和const有何不同,它们在C和C++中的使用有何不同?(默认联动等差异)2)C中使用的头文件中允许以下声明和定义,然后包含在多个文件中。staticinttestvar=233;externintone;externintshow();intabc;constintxyz;//constintxyz=123;produceserrorconstdefinition

【论文笔记】AK卷积(Convolutional Kernel with Arbitrary Sampled Shapes and Arbitrary Number of Parameters)

本文介绍AK卷积,传统的卷积有2个缺陷:1、卷积运算在固定大小的窗口运行、无法捕获其他窗口的信息,并且窗口的形状是固定的;2、卷积核的尺寸固定为,窗口大小固定为k,随着k增加,参数会快速增加。针对传统卷积的缺陷,作者提出了AK卷积,AK卷积拥有任意形状和任意的参数。作者在yolov5n和yolov8n上进行了测试,效果非常好。论文地址:AKConv:ConvolutionalKernelwithArbitrarySampledShapesandArbitraryNumberofParameters代码:https://github.com/cv-zhangxin/akconv一、AKConv前

c++ - “static const”、 “#define” 和 “enum” 在性能和内存使用方面的区别

可能是因为#define语句的内联。我知道答案可能取决于编译器,那么假设是GCC。已有类似问题aboutC和aboutC++,但它们更多地是关于使用方面的。 最佳答案 编译器会在给定基本优化后将它们视为相同。检查起来相当容易-考虑以下C代码:#definea1staticconstintb=2;typedefenum{FOUR=4}enum_t;intmain(){enum_tc=FOUR;printf("%d\n",a);printf("%d\n",b);printf("%d\n",c);return0;}用gcc-O3编译:00

C++ 重载歧义 : conversion versus promotion with primitive types

在这段代码中:voidf(floatf,longinti){cout有一个歧义。Checkitout!.但是,第二个参数是有符号整数。将int绑定(bind)到longint参数需要提升,但对于float,则需要转换。由于第一个参数是关于两个重载的完全匹配,所以它不算数。但是关于第二个参数,它在第一次过载(提升)上的排名优于在第二个(转化)上的排名。为什么会出现解析歧义,而不是选择第一个重载? 最佳答案 int到long是一个转换。short到int是一种提升。(有关积分促销的完整列表,请参阅[conv.prom]。)同理,floa

c++ - 带 static_assert() 的逗号运算符

当尝试使用static_assert作为参数来计算逗号运算符时编译失败voidfvoid(){}intmain(){inta=(1,2);//a=2intb=(fvoid(),3);//b=3intd=(,5);//^//error:expectedprimary-expressionbefore','token.OKintc=(static_assert(true),4);//^~~~~~~~~~~~~//error:expectedprimary-expressionbefore'static_assert'.Why?}看起来static_assert()在编译后甚至没有解析为vo

c++ - 将 C 风格的转换更改为 static_cast 总是安全的吗?

由于cppcheckcstyleCast样式警告,我正在尝试消除代码库中的所有C样式转换。将C风格的转换更改为static_cast总是安全的吗?安全,我的意思是,是否存在旧的C风格转换可以正常工作,但static_cast会引发错误或未定义行为的情况?type1a;type2b=(type2)a;//Cstylecasttype2b=static_cast(a);//Isthisalwaysavalidreplacementforabovecast? 最佳答案 C风格的转换通常是static_cast的组合或reinterpret

c++ - 如何将 `boost::static_visitor` 实例传递给函数

我正在使用boost::variant在我的项目中经常出现。我的同事们现在想出了传递特定boost::static_visitor实例的想法。以自定义访问类型。她有一些代码如下:#include#includetypedefboost::variantTVar;structVisitor1:publicboost::static_visitor{templateresult_typeoperator()(constT&){return42;}};structVisitor2:publicboost::static_visitor{templateresult_typeoperator(

c++ - C++中static的含义

我认为我的C++相当不错,事实证明我不是。我之前问过一个问题:C++constlvaluereferences其中一个答案中有以下代码:#includeusingnamespacestd;int&GenX(boolreset){staticint*x=newint;*x=100;if(reset){deletex;x=newint;*x=200;}return*x;}classYStore{public:YStore(int&x);int&getX(){returnmy_x;}private:int&my_x;};YStore::YStore(int&x):my_x(x){}intma

c++11:为什么 std::forward 中的 static_assert 是必需的?

在move.h中,forward有两个重载templateconstexpr_Tp&&forward(typenamestd::remove_reference::type&__t)noexcept{returnstatic_cast(__t);}templateconstexpr_Tp&&forward(typenamestd::remove_reference::type&&__t)noexcept{static_assert(!std::is_lvalue_reference::value,"templateargumentsubstituting_Tpisanlvalueref