草庐IT

Archive_Template

全部标签

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++ - "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++ 模板部分特化 : Why cant I match the last type in variadic-template?

我尝试编写一个IsLast类型特征来检查给定类型是否是std::tuple中的最后一个类型,但下面的代码无法编译。我知道如何绕过它,但我很好奇为什么编译器不喜欢它。我想一定有一些我不知道的关于可变参数模板特化的规则。代码位于:https://godbolt.org/g/nXdodx错误信息:error:implicitinstantiationofundefinedtemplate'IsLast,int>,int>'还有关于特化声明的警告:warning:classtemplatepartialspecializationcontainstemplateparametersthatca

c++ - 警告 : specialization of template in different namespace

通过以下代码我得到了警告:warning:specializationof‘templatestructstd::iterator_traits’indifferentnamespace[-fpermissive]templateclassstd::iterator_traits{public:typedefWorddifference_type;typedefWordvalue_type;typedefToken_ptrpointer;typedefWord&reference;typedefstd::bidirectional_iterator_tagiterator_catego

c++ - 我们什么时候需要 .template 结构

我做了如下程序#include#includetemplatestructClass{templatevoiddisplay(){std::coutvoidfunc(Classk){k.display();}intmain(){Classd;func(d);}上面的程序没有编译因为display()是一个模板成员函数,所以.template的资格之前display()必须完成。我说得对吗?但是当我制作下面的程序时#include#includetemplateclassmyClass{Tdummy;/*******/public:templatevoidfunc(myClassobj)

c++ - 将 Curiously Recurring Template Pattern (CRTP) 与其他类型参数一起使用

我尝试使用CuriouslyRecurringTemplatePattern(CRTP)并提供额外的类型参数:templateclassBase{Int*i;Float*f;};...classA:publicBase{};这可能是一个错误,更合适的父类(superclass)是Base--尽管这种参数顺序不匹配不是那么明显。如果我可以在typedef中使用名称参数的含义,这个错误会更容易看到:templateclassBase{typenameSubclass::Int_t*i;//error:invaliduseofincompletetype‘classA’typenameSub

c++ - "template"不需要关键字? [gcc/clang/Comeau 错误?]

这是测试代码templatevoidf(){Tt;t.f(0);//compilesevenwithoutthe"template"keyword,whatamImissing?}classabc{public:templatevoidf(int){}};intmain(){f();}我正在使用g++4.4.6。谢谢P.S:我已经大大编辑了我的问题。请不要介意。编辑:我向EDG的人问了这个问题,这是MikeHerrick不得不说的Wedodiagnosethisasanerrorin--strictmodeaswellasanymodethatenablesdependentnamel

c++ - G++ 编译器错误或错误代码? : "template definition of non-template"

作为大型程序的特征类的一部分,我尝试创建一个静态类变量,该变量可能具有不同的值,具体取决于实例化封闭类模板的类型。我已经简化了相关代码以生成我正在谈论的内容的简单示例:#include#include#includetemplatestructFoo;templatestructFoo::value>::type>{staticstd::stringmessage;};templatestructFoo::value>::type>{staticstd::stringmessage;};templatestd::stringFoo::message;对于GCC4.6,这会产生一个编译器