草庐IT

fno-implicit-templates

全部标签

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++ - 依赖类型 : 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

ElasticSearch索引模板(template)操作:创建、查询、修改、删除

官方文档链接:https://www.elastic.co/guide/en/elasticsearch/reference/6.6/indices-templates.html一:概述可以按下面几种方式理解索引模板:避免每次在创建索引库的时候,都需要手工指定每个索引库的配置信息;索引可以使用索引模板(indextemplate)进行创建,在新建索引时需要进行模板设置包括settings和mappings,通过模式匹配可使多个索引重复使用一个模板。将已经创建好的某个索引的参数设置(settings)和索引映射(mapping)保存下来作为模板,在创建新索引时,指定要使用的模板名,就可以直接重用

c++ - 在没有括号的宏中使用逗号 : How can I mix and match with a template?

考虑一个简单的宏:#defineECHO(x)xECHO(foo(1,2))这会产生我们期望的准确输出:foo(1,2)上面的例子之所以有效,是因为预处理器识别了与函数调用相邻的括号。现在考虑如果我使用模板而不是函数调用会发生什么:ECHO(template)这会导致错误,因为预处理器会解释template和bool>作为宏的两个单独参数。预处理器无法识别范围!有没有办法在宏中使用这样的模板? 最佳答案 #defineCOMMA,ECHO(template)有点痛,但有效。FWIW,如果参数的语法允许(),则不需要替换,例如,ECH

c++ - 链接器错误 'unresolved external symbol' : working with templates

我有一个基于模板的类[Allotter.h&Allotter.cpp]:templateclassAllotter{public:Allotter();quint32getAllotment(allotType*);boolremoveAllotment(quint32,intauto_destruct=0);private:QVector>indexReg;intinit_topIndex;};它的用法如[ActiveListener.h&ActiveListener.cpp]所示:classActiveListener:publicQObject{Q_OBJECTpublic:Ac

c++ - "if the context from which the specialization is referenced depends on a template parameter"是什么意思?

根据C++17标准,[temp.point]/4,强调我的,Foraclasstemplatespecialization,aclassmembertemplatespecialization,oraspecializationforaclassmemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecialization,ifthecontextfromwhichthespecializationisrefere

C++ : Ternary Operator (Conditional Operator) and its Implicit Type Conversion Rules

三元运算符的参数是否有隐式类型转换规则?三元运算符总是需要返回相同的类型。此类型仅由第二个和第三个参数(1st?2nd:3rd)确定,因此两个参数都转换为此类型。这种类型是如何确定的?更具体地说,我测试了一个例子:classpointclass{pointclass();pointclass(inti);//(pointclass)(int)operatorbool()const;//(bool)(pointclass)};我有一个类(pointclass),它支持从int进行隐式转换至pointclass和pointclass的隐式转换至bool.inti;pointclassp;b

c++ - "templating"命名空间

我想构建这样的东西:File1:templatenamespacemyNamespace{classmyClass1{myClass1(Vectorv){...}}}File2:templatenamespacemyNamespace{classmyClass2{myClass2(Vectorv){...}}}当然这是不可能的,因为你不能模板命名空间。相反,我可以使用结构而不是命名空间,但这样我就无法将命名空间函数分布到多个文件中。这样的问题有什么解决办法吗?PS:我知道我可以对类进行模板化,但是我必须在创建新类时指定要使用的vector类型。 最佳答案