草庐IT

is_constexpr_copiable

全部标签

c++ - 为什么 "initializer-string for array of chars is too long"在 C 中编译良好而不在 C++ 中编译?

以下程序在C中编译正常但有警告,但在C++中编译失败。为什么?这是什么原因?#includeintmain(void){chara[5]="Hello";a[0]='y';puts(a);for(inti=0;i警告:Warning:[Error]initializer-stringforarrayofcharsistoolong[-fpermissive]enabledbydefault但如果程序被编译为C++程序,则C++编译器会给出以下错误:[Error]initializer-stringforarrayofcharsistoolong[-fpermissive]我正在使用GC

c++ - constexpr 参数化函数指针

我有以下第三方API:usingStatisticsFunc=double(*)(conststd::vector&)libraryClass::ComputeStatistics(StatisticsFuncsf);我是这样使用的:obj1->ComputeStatistics([](constauto&v){returnhistogram("obj1",v);};obj2->ComputeStatistics([](constauto&v){returnhistogram("obj2",v);};但是所有这些lambda都只是重复的代码。我宁愿这样:obj1->ComputeSta

c++ - gcc 4.8 中静态 constexpr 成员数组的初始化

当使用-std=c++11时,以下代码在gcc4.9.1和clang-3.6中编译和运行:structBar{intx;};structFoo{staticconstexprBarbars[]={1,2,3};};constexprBarFoo::bars[];但是在gcc4.8.3中失败,导致报错./cpptest.cpp:14:43:error:couldnotconvert'1'from'int'to'constBar'staticconstexprBarbars[]={1,2,3};^./cpptest.cpp:14:43:error:couldnotconvert'2'fro

c++ - std::is_constructible 没有给出正确的结果

这个问题在这里已经有了答案:Whydoesis_constructibleclaimsomethingisconstructiblewhenitisn't?(2个答案)关闭6年前。源自thisCodeReview主题:#include#include#include#include#includetemplateclassaggregate_wrapper:publicT{private:usingbase=T;public:usingaggregate_type=T;templateaggregate_wrapper(Ts&&...xs):base{std::forward(xs).

c++ - 在编写平台相关代码时使用 constexpr if 而不是宏?

现在ifconstexpr是C++17的一部分,在编写平台相关代码和类似代码时,它是否是宏的良好替代品?我想知道,因为我真的不喜欢宏,并且只想将它们用于includeguards和includes。//thosevariablesshouldbegivenbythecompilerconstexprunsignedint__os=0x1;//currentosconstexprunsignedint__os_win=0x1;//Windowsconstexprunsignedint__os_linux=0x2;//Linux-flavorsconstexprunsignedint__o

c++ - 如果 count() 是 constexpr 函数,为什么 std::array<int, count()> 不能编译?

这个问题在这里已经有了答案:constexprnotworkingifthefunctionisdeclaredinsideclassscope(3个回答)3年前关闭。为什么下面的C++代码不能用VC2017编译?structFixedMatchResults{staticconstexprstd::size_tcount(){return20;};std::arrayresults;};错误是:errorC2975:'_Size':invalidtemplateargumentfor'std::array',expectedcompile-timeconstantexpression

c++ - constexpr 中的 std::variant 修改

考虑以下两个程序:#include#includeconstexprautof(){usingT=std::variant;Tt(false);t=T(true);returnstd::get(t);}templatevoidprint(){std::cout();}和#include#includeconstexprautof(){usingT=std::variant;Tt(false);t=T(42);returnstd::get(t);}templatevoidprint(){std::cout();}GCC编译这两个并输出预期的结果。在这两种情况下,Clang都不会编译它们中

c++ - TT : Is that possible/correct 上的模板化类中 T 上的模板化方法

我有一个以类型名T为模板的类MyClass。但在内部,我想要一个以另一种类型TT(与T无关)为模板的方法。阅读/修补后,我发现了以下符号:templateclassMyClass{public:templatevoidMyMethod(constTT¶m);};出于风格原因(我喜欢在一个头文件中声明模板化类,在另一个头文件中定义方法),我不会在类声明中定义方法。所以,我必须把它写成:template//thisisthetypeoftheclasstemplate//thisisthetypeofthemethodvoidMyClass::MyMethod(constTT&pa

c++ - 使用 constexpr 初始化数组?

我想知道是否可以使用constexpr函数(使用C++2011)初始化整个数组。在这里,我有一些东西可以说明我想做什么:templateconstunsignedintMyClass::_myVar[2][3]={{metaFunction(0,0,DIM),metaFunction(0,1,DIM),metaFunction(0,2,DIM)},{metaFunction(1,0,DIM),metaFunction(1,1,DIM),metaFunction(1,2,DIM)}};templateinlineconstexprunsignedintMyClass::metaFunct

docker启动时卡在“Docker is starting..“

言简意赅之:如果你试了包括重启wsl/关闭hyperV/wsl–update在内的大部分方法都没有效果的话,不妨把代理关掉/把网线拔掉/断网再打开docker试试吧,进去后就可以开代理了。(关于我电脑重启了n次,系统还原了两次,最后把自带代理的网线拔了忽然好了这件事,不知道是不是登录验证的问题)其他常规解决方法:https://stackoverflow.com/questions/43041331/docker-forever-in-docker-is-starting-at-windows-task(这里挺全的了)