草庐IT

REQUEST_ENABLE_BT

全部标签

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++ - enable_if 和互斥方法

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

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

npm ERR! code CERT_HAS_EXPIRED npm ERR! errno CERT_HAS_EXPIRED npm ERR! request to https://registry.

npminstall时报错codeCERT_HAS_EXPIRED一、报错情况二、解决方案一、报错情况 npmERR!codeCERT_HAS_EXPIREDnpmERR!errnoCERT_HAS_EXPIREDnpmERR!requesttohttps://registry.npm.taobao.org/vue-loaderfailed,reason:certificatehasexpirednpmERR!Acompletelogofthisruncanbefoundin:npmERR!D:\Environment\nvm\node_cache\_logs\2024-01-22T04_34

c++ - enable_if 检查迭代器的值类型是否是一对

我想为值类型为一对的迭代器编写一个专门的模板函数。我的期望是这应该匹配std::map的迭代器。为了检测对:templatestructis_pair:std::false_type{};templatestructis_pair>:std::true_type{};//alsotriedthis,butitdidn'thelptemplatestructis_pair>:std::true_type{};然后我在函数声明中使用enable_if:templatedecltype(auto)do_stuff(std::enable_if::value,ITR>itr){//access

c++ - 使用 enable_if 的模板特化在 Clang 中失败,适用于 GCC

我正在尝试删除基于模板类型的成员函数。问题是在未删除的情况下,使以后的模板特化与我的函数的类型签名匹配。我尝试了以下代码,它使用GCC(9.0.1)编译,但在Clang(9.0.0)中出错。我认为它也无法在MSVC++中构建代码。#include#includetemplatestructmy_type{templatestd::enable_if_t::value,my_type>my_fun(constmy_type&v){std::couttemplatestd::enable_if_t::value,my_type>my_type::my_fun(constmy_type&v)