草庐IT

enable-term-driver

全部标签

c++ - enable_if 用于没有返回类型的函数

我最近遇到了一个有趣的enable_if用法版本,它用于有条件地启用具有更好可读性的函数,因为该函数的返回类型不是enable_if的一部分(请参阅cleaner_usage):#includeusingmaybe_integral=int/*=orfloat--thenwon'tcompile*/;usingreturn_type=int;typenamestd::enable_if::value,return_type>::typetraditional_usage(){return1;}template::value,int>::type=0>return_typecleaner

c++ - template<class = enable_if_t<...>> 做什么?

我一直在阅读STL文件,以学习格式化代码的更好方法,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。template,thread>::value>>explicitthread(_Fn&&_Fx,_Args&&..._Ax){//constructwith_Fx(_Ax...)...}std::enable_if_t是templateusingenable_if_t=typenameenable_if::type;templatestructenable_if{//typeis_Tyfor_Testusingtype=_Ty;};该代码在thread和str

c++ - std::enable_if 不能用于禁用此声明

我有一段相当复杂的代码,我将其简化为这个复制器:#include#includetemplatestructouter{templatestructinner{templatestructproblem;usingTA=std::tuple;usingTB=std::tuple;templatestructproblem::value::value>::type>{staticconstexprautoval(){return1;}//actuallyacomplexfunction};templatestructproblem::value>=std::tuple_size::val

c++ - xutility.h 错误 C2064 : term does not evaluate to a function taking 2 arguments

我有问题要问。我创建了一个名为AstarPlanlama的类并具有以下2个函数:boolAstarPlanlama::nodeComp(constNode*lhs,constNode*rhs){returnlhs->FF;}voidAstarPlanlama::enKucukFliNodeBul(std::list*OPEN){std::list::iteratorit=std::min_element(OPEN->begin(),OPEN->end(),&AstarPlanlama::nodeComp);OPEN->sort(&AstarPlanlama::nodeComp);Q=O

c++ - enable_if 和互斥方法

我不明白为什么下面的代码不起作用。编译器(gcc)似乎同时实例化了两者方法,显然整数是有符号或无符号的,所以总是失败。我虽然enable_if在这里是为了避免这种情况。问:为什么编译出错,如何避免?usingnamespaceboost;//orstdasyouwanttemplatestructtest{//ifsignedtemplate,int>::type=0>test&operator,int>::type=0>test&operatorx;xetc.testy;yetc.} 最佳答案 SFINAE仅适用于immediat

NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver解决办法

NVIDIA-SMIhasfailedbecauseitcouldn‘tcommunicatewiththeNVIDIAdriver解决办法参考链接1参考链接2参考链接32023.3.17更新今天突然又出现这个问题,一开始我就以为内核自动更新,便想去降低内核版本,一看旧版本的内核,发现都被自动删除了,然后我之前也将内核自动更新取消了啊,输入命令dpkg--get-selections|greplinux-image打印内核版本显示也是hold,按道理内核并没有更新。一开始没发现问题,便一直尝试下载旧版本内核来解决,一直没成功。最后无意间在ubuntu的应用中点开nvidiaxserverset

c++ - enable_if 只有 C++11 吗?

在C++引用网站上查找enable_if,据说它只是C++11的一个特性。但是,我在C++98类型上使用GCC编译器编译了我自己的enable_if版本,它运行良好并且似乎能够用于任何版本的C++(打印1):#includenamespaceegg{templatestructenable_if{};templatestructenable_if{typedefTtype;};}intmain(){egg::enable_if::typex=1;std::cout我说的enable_if是任何C++版本的一个有效功能,但只是引入到C++标准中,或者还有其他原因吗?

c++ - 使用 enable_if 重载函数时出错

我有这段代码,其中一个函数根据可用的成员有不同的实现:#includetemplatestructD{structinner{Tfirst;};};templatestructD{usinginner=std::vector;};templateclassC{usingB=D;typenameB::innerb;public:typenamestd::enable_if().first),T>::value,T>::typefirst(){returnb.first;}typenamestd::enable_if()[0]),T>::value,T>::typefirst(){retu

c++ - 为什么 std::shared_ptr 的别名构造函数不初始化 std::enabled_shared_from_this?

考虑以下代码:structFoo:std::enable_shared_from_this{};structBar{Foofoo;};intmain(){std::shared_ptrbar_p(newBar);//makeshared_ptrtomemberwithaliasingconstructorstd::shared_ptrfoo_p(bar_p,&bar_p->foo);assert(bar_p->foo.shared_from_this());//fail!throwsbad_weak_ptr}不幸的是,它没有按预期工作(至少在GCC4.8.2中)。我查看了代码,似乎别名

c++ - 将 apiVersion 参数设置为 0 时的 VK_ERROR_INCOMPATIBLE_DRIVER

我正在尝试创建一个vulkan实例。这是我的代码:vk::ApplicationInfoappInfo("Test",1,nullptr,0,0);vk::InstanceCreateInfoinfo;info.pApplicationInfo(&appInfo);vk::Instanceinstance;constautoresult=vk::createInstance(&info,nullptr,&instance);std::cout但是这会返回VK_ERROR_INCOMPATIBLE_DRIVER。如果我不提供自己的ApplicationInfo而是使用默认构造的,它就可以