草庐IT

fno-implicit-templates

全部标签

c++ - 使用 std::tuple 构建基于 vector 的数据集请引用 variadic-templates

我想制作一个类模板如下:templateclassVectorTuple;例如,VectorTuple将实例化为Tuple,vector,vector>我对可变参数模板不熟悉。最糟糕的方法是从中复制代码并修改它。有没有一种简单的方法可以直接使用std::tuple来定义我的VectorTuple。 最佳答案 如果您正在寻找typedefvariadic-templates类型,那么,templateusingVectorTuple=std::tuple...>;现在你可以像这样使用它了VectorTupleobj;

C++11/14/17,GCC 7 与 GCC 8 : Name lookup for friend class templates

我想弄清楚以下代码在GCC7中是否有效,但在GCC8.1中无效。代码的作用是:定义(并转发声明)类模板MyGoodFriend(在全局命名空间中)在inner命名空间中定义一个类模板Befriended使MyGoodFriend的所有特化成为Befriended的friend有问题的部分是templatefriendclassMyGoodFriend;我明白问题是什么了。GCC8.1要求我在friend声明中使用完全限定名称::MyGoodFriend-然而,GCC7对MyGoodFriend很满意。这是代码:templateclassMyGoodFriend;namespaceinn

c++ - 在不需要时使用 "template"和 "typename"消歧器

Thisquestion涵盖何时以及为何在C++模板代码中需要typename和template消歧器。在C++03中不需要这些消歧器的情况下使用它们是否有效?在C++11中怎么样? 最佳答案 对于“有效”的某些定义,它在符合C++03/C++11的编译器中有效。C++03ISO/IEC14882:2003§14.2.5:[Note:justasisthecasewiththetypenameprefix,thetemplateprefixisallowedincaseswhereitisnotstrictlynecessary;i

c++ - Clang (OS X) 在特定的嵌套声明中需要 "template"关键字,而 VS 禁止它

我正在使用两个编译器(Xcodev5.0.2上的Clang和VisualStudio2012Update4)编写一个跨平台应用程序,我遇到了两个编译器不同意使用所需语法的场景嵌套声明中的template关键字。这是代码(归结为一个易于重现的测试用例):templatestructBase{templatestructInnerBase{};};templatestructDerived:publicBase{//the"template"keywordisREQUIREDinClang/OSXstructInnerDerived:publicBase::templateInnerBas

c++ - "template"关键字之前的 "class"关键字在做什么?

只是一些代码示例[不是现实生活中的例子]//atfilescopetemplatestructdemo{};templateclassdemo;//isthetemplatekeywordoptionalhere?第3行中的模板关键字是可选的吗?我以前没有(经常)看到模板关键字的这种用法。标准的哪一部分说允许这样做?编辑我认为g++有一个错误。templatestructdemo{};classdemo;//templatekeywordomitted在g++(4.5.1)上编译而在Comeau上失败"ComeauTest.c",line5:error:specializingclas

c++ - 没有参数的模板类 `template<>` 是什么意思?

没有参数的模板类是什么意思?例如,让我们以计算阶乘的模板类为例,其模板参数为N-N!。.基本上,这是类:templateclassFactorial{public:enum{fact=N*Factorial::fact};};但是,我发现这个类有一个“扩展类”,templateclassFactorial{public:enum{fact=1};};我的问题是:没有参数的模板是什么,template什么意思?提前致谢。 最佳答案 这个templateclassFactorial{public:enum{fact=1};};实际上是类

c++ - 为什么这有效(Templates,SFINAE)。 C++

关于昨天的帖子,今天早上这把我吵醒了。为什么这真的有效?就test这个函数而言,这个函数没有主体,怎么能执行任何操作呢?我想知道为什么以及如何工作?我真的很想知道您的答案。templateclassIsClassT{private:typedefcharOne;typedefstruct{chara[2];}Two;templatestaticOnetest(intC::*);//NOBODYHEREtemplatestaticTwotest(…);//NORHEREpublic:enum{Yes=sizeof(IsClassT::templatetest(0))==sizeof(On

c++ - 提升 : dereference a template argument if it's a pointer

如果它是一个指针(或智能指针),我可以使用什么来取消引用模板参数,或者如果它不是,我可以保持原样吗?templatevoidsubf(constT&item){item.foo();}templatevoidf(constT&item){subf(magic_dereference_function(item));}Boost中的任何内容都是一个选项。 最佳答案 templateT&maybe_deref(T&x){returnx;}templateT&maybe_deref(T*x){return*x;}您必须单独为智能指针添加重

c++ - "use of class template requires template argument list"是什么意思?

我是模板的新手,所以请原谅我的幼稚问题。我在这段代码中遇到错误:templateclassa{public:inti;a(t&ii):i(ii){}};intmain(){a*a1(newa(3));cout编译错误:'a':使用类模板需要模板参数列表'a':类没有构造函数 最佳答案 使用a*a1(newa(3));^^^^^^^^^如果你想让你的模板参数被自动推导,你可以使用一个辅助函数:templatea*createA(constT&arg)//pleaseaddconsttoyourctor,too.{returnnewa(

c++ - 为什么我们必须做 template <class/typename> T 而不仅仅是 template T

代替templatevoidfunc(Targ){/*something*/}为什么我们做不到templatevoidfunc(Targ){/*something*/}来自cplusplus.com:Theonlydifferencebetweenbothprototypesistheuseofeitherthekeywordclassorthekeywordtypename.Itsuseisindistinct,sincebothexpressionshaveexactlythesamemeaningandbehaveexactlythesameway.对我来说,这似乎是不必要的样板