草庐IT

template-auto

全部标签

c++ - auto 的编译器问题?错误 : in a declarator-list 'auto' must always deduce to the same type

std::vectorvec;autoi=vec.begin(),j=std::next(i);Error:inadeclarator-list'auto'mustalwaysdeducetothesametype 最佳答案 在Linux上的g++中编译良好,因此它似乎是一个编译器错误。Probablythisone. 关于c++-auto的编译器问题?错误:inadeclarator-list'auto'mustalwaysdeducetothesametype,我们在StackOve

linux使用grep命令查询nginx的进程情况时总是出现 grep --color=auto nginx

问题:每次使用psaux|grep服务名命令查询某个服务的进程时,总会出现一条grep--color=auto服务名例如:psaux|grepnginx#会出现图片中的情况解答:这是因为grep也是一条命令,它在输出时,会把grep服务名也当做一个进程输出,假如使用grep命令查询某个服务的进程号,结果只显示一条grep--color=auto服务名。则说明虚拟机中没有改服务的进程。ChatGPT解答:因为psaux命令会列出当前系统中所有的进程信息,而grepnginx是用于筛选出包含“nginx”关键字的行。由于grep命令本身也被包括在进程列表中,所以它也会被psaux命令找到并显示出来

具有用户类型的 C++20 模板 <auto> 导致 GCC 9 中的 T/const T 类型不匹配

我正在尝试将非类型模板与自定义类型结合使用。structT{};templatestructU{};templatevoidf(U){}intmain(){constexprTt;f(U{});//OKf(U{});//OKf(U{});//Error}模板参数推导失败,gcctrunkwith-std=c++2agetsyop.cpp:10:5:note:templateargumentdeduction/substitutionfailed:yop.cpp:19:21:note:mismatchedtypes‘T’and‘constT’19|f(U{});//Error|^我是不是

c++ - gcc-4.9.2 : non-type template parameter

我在gcc-4.9.2上有一个奇怪的编译错误,相同的代码在其他编译器上工作,比如gcc-4.8或我能找到的任何clang。问题与non-typetemplate-arguments有关.所以考虑一下:#include#includeinttemplateParam;templatestructTestTemplate{intvalue(){}};templateintTestTemplate::value(){returntemplateParam;}TestTemplatetestVariable;intmain(){std::cout我在gcc-4.9.2中遇到以下错误:prog.

c++ - 这两个来源之间是否存在关于 `auto_ptr` 模板类的矛盾?

这site关于“所有权、来源和汇”的陈述:“当您复制auto_ptr时,您会自动将所有权从源auto_ptr转移到目标auto_ptr;如果目标auto_ptr已经拥有一个对象,则该对象首先被释放。复制后,只有目标auto_ptr拥有该指针,并会在适当的时候将其删除,而源将设置回空状态,不能再用于引用拥有的对象。".现在考虑operator=()的定义对于templacteclassauto_ptr,在Stroustrup的TheC++ProgrammingLanguageThirdEdition第14章第368页中:auto_ptr&operator=(auto_ptr&a)thro

C++ 模板 : Partial Template Specifications and Friend Classes

是否有可能以某种方式使部分模板规范成为友元类?IE。考虑你有以下模板类templateclassX{Tt;};现在你有了部分特化,例如,指针templateclassX{T*t;};我想要完成的是每一个可能的X是X的好友类对于任何S.IE。X应该是X的friend.当然,我想到了X中的常用模板友元声明:templateclassX{templatefriendclassX;}但是,这不会编译,g++告诉我:test4.cpp:34:15:错误:'templateclassX的特化'必须出现在命名空间范围内test4.cpp:34:21:错误:部分特化'X'声明'friend'这根本不可

c++ - constexpr 与 std::array - "Non-type template argument is not a constant expression"

这个问题在这里已经有了答案:Errorusingaconstexprasatemplateparameterwithinthesameclass(2个答案)关闭9年前。我正在尝试实现以下内容:#include#includeclassClass2{};classClass1{public:staticconstexpruint8_tGetMax(){return5;}staticconstexpruint8_tGetMin(){return0;}staticconstexpruint8_tGetCount(){returnGetMax()-GetMin()+1;}private:std

c++ - 函数参数列表中的 auto 暗示模板参数

在他的talkatcppcon(约13分钟),AndrewSutton提到您将“很快”能够写作autofunc(autoa,autob){...}这将被理解为templateautofunc(Ta,Ub){...}就像在C++14中为通用lambda引入的那样。此功能的名称是什么?这是ConceptsLite的一部分,还是单独提出的?如果确实有人提出,这显然没有进入C++14;如果有人知道,反对意见是什么? 最佳答案 缩写函数模板是的,它是ConceptsLite的一部分它在概念TS中,它远未为C++14做好准备。在thelates

c++ - 依赖类型 : Template argument deduction failed

在我的代码中,我使用了模板化图像类Image结合std::shared_ptr.这些图像指针应该传递给各种图像处理函数,其中一些函数与图像类型无关。考虑以下Image的定义和两个处理函数function1()和function2().#includetemplatestructImage{typedefstd::shared_ptr>Ptr;};templatevoidfunction1(typenameImage::Ptrimage){}templatevoidfunction2(std::shared_ptr>image){}同时function1()和function2()实际上

c++ - "template argument deduction for class templates"是否应该为可变类模板推导出空参数包?

“类模板的模板参数推导”提案(P0091R2)包含以下示例:templatestructX{X(Ts...)};Xx1{1};//OKXXx11;//OKX(除了构造函数定义缺少主体这一事实之外),该示例似乎表明用零参数构造的可变参数类模板将被推导为一个空的参数包。很遗憾,最新版本的g++不同意:intmain(){Xx1{1};Xx11;}Infunction'intmain()':error:invaliduseoftemplate-name'X'withoutanargumentlistXx11;^note:classtemplateargumentdeductionrequir