草庐IT

可变性

全部标签

c++ - 为什么 Clang++ 编译器无法编译以下可变参数模板代码?

#include#include#include#includetemplatestructtest{usingargs_type=std::tuple;args_typex;templatevoidcallme(std::index_sequence){int_[]={(std::get(x).std::tuple_element::type::~type(),true)...};}};intmain(){}错误信息是clang-3.7-std=gnu++1y-Wc++14-extensionstest.cpptest.cpp:15:56:error:expected')'int_[

C++可变参数模板构造函数和通用构造函数

代码如(c++14):structS{inta;intb;};classC{public:C(charconst*,size_t){}//1C(Sconst&){}//2C(Sconst*){}//3templateC(T&&...){}//4//C(S){}//5//C(S*){}//6};Ss{1,2};Cc1{s};//calls4andnot2Cc2{"abc",3};//calls4andnot1Cc3{(charconst*)"abc",(size_t)3};//calls1-okCc4{s};//calls5ifuncommentedCc5{&s};//calls6ifu

c++ - 重载、可变参数函数和 bool 类型

以下程序编译正常并按预期工作。它的输出是:12#includeclassFoo{public:voidBar(constchar*b,...){printf("1\n");};voidBar(inta,constchar*b,...){printf("2\n");};};intmain(){Foofoo1;foo1.Bar("Test","xx",1,2);foo1.Bar(1,"xx","xx",2,2);}现在,如果我将第二个Bar函数的int参数更改为bool和foo1.Bar(1,"xx","xx",2,2);到foo1.Bar(true,"xx","xx",2,2);,那么下

c++ - 具有 const 引用的可变参数模板特化

如何特化具有参数常量引用的可变参数模板函数?例子:templateTfoo(Args...args)=delete;templateintfoo(inta,constchar*str,constTest&t){....}//Failstocompile//templateintfoo(inta,constchar*str,Test){....}//Okintmain(){autoi=foo(10,"teststring!",t);return0;}当使用声明的constTest&参数调用函数foo时,编译器无法看到专门的函数并回退到已删除的函数:error:useofdeletedfu

c++ - 类构造函数优先级与值包装器的可变模板构造函数

今天我发现我不明白C++的构造函数优先级规则。请参阅以下模板structwrappertemplatestructwrapper{Tvalue;wrapper(Tconst&v0):value{v0}{std::coutwrapper(As&&...as):value(std::forward(as)...){std::cout这是一个简单的模板值包装器,带有复制构造函数(wrapperconst&)、一个移动构造函数(wrapper&&w0)、一种值复制构造函数(Tconst&v0)、一种移动构造函数(T&&v0)和一种模板就地构造值构造函数(As&&...as,以STL容器的emp

c++ - 我如何 curry 可变参数模板模板参数?

Variadictemplate模板参数接受任何模板:templatestructTest1{usingtype=int;};templatestructTest2{usingtype=char*;};templateclassBeCurry>structCurrying{};usingcurry=Currying;usingcurry2=Currying;我想要Curryingtemplate模板类。这意味着:如果参数接受一个模板参数作为Test1,curry::apply::typegetTest1::type.如果参数接受两个模板参数为Test2,curry2::apply是一个

c++ - 无参数可变参数模板的模糊重载

相关:Ambiguousoverloadaccessingargument-lesstemplatefunctionswithvariadicparametersSimplevariadictemplatefunctioncan'tinstantinateWhyisthisvariadicfunctionambiguous?考虑这对可变参数模板:templateboolAll(Param&c){returntrue;}templateboolAll(Param&c){returnf(c)&&All(c);}这有效并编译。但是,没有第一个模板参数怎么写呢?听起来微不足道?嗯,这就是我的想

c++ - 在可变参数模板模板参数中使用默认模板参数

我发现下面的最小示例适用于gcc和clang甚至VisualStudio,但它不能使用icc编译。我试图确定这是否是有效的C++,但我无法找到标准的相关部分来回答我的问题,因为这是几个不同概念的组合。//structwithmultipletemplateparameterstemplatestructC{};//structthattriestouseC'sdefaultsecondparameterwithoutspecifyingittemplateclassF>structG{Fh;};intmain(){Gi;}使用icc(16.0.3),编译会出现以下错误:struct.c

c++ - 演绎指南和可变参数模板

考虑以下代码:#include#includetemplatestructcustom_wrapper{templatecustom_wrapper(Argarg):data(arg){}Tdata;};templatecustom_wrapper(Argarg)->custom_wrapper;templatestructcustom_tuple{templatecustom_tuple(Args...args):data(args...){}std::tupledata;};templatecustom_tuple(Args...args)->custom_tuple;intmai

c++ - 为什么只有有效的空可变参数包的模板格式错误?

这是什么道理temp.res#8.3(8)Thevalidityofatemplatemaybecheckedpriortoanyinstantiation.[ Note:Knowingwhichnamesaretypenamesallowsthesyntaxofeverytemplatetobecheckedinthisway.— endnote ]Theprogramisill-formed,nodiagnosticrequired,if:[..](8.3)everyvalidspecializationofavariadictemplaterequiresanemptytempl