草庐IT

Variadic

全部标签

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

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

c++ - 编译时 'String' 使用 Variadic 模板进行操作

大家好,我目前正在尝试编写一个编译时字符串加密(非常松散地使用“字符串”和“加密”这两个词)库。目前我的情况如下://Cacluatenarrowstringlengthatcompile-timetemplatestructCountArgs{templatestructCounter;templatestructCounter{staticunsignedlongconstValue=Counter::Value+1;};templatestructCounter{staticunsignedlongconstValue=1;};staticunsignedlongconstVal

c++ - Variadic 模板基类调用转移

在pre-11C++中我有这样的东西:templatestructFoo:T,U,V{boolinit(){if(!T::init()||!U::init()||!V::init())returnfalse;//dolocalinitandreturntrue/false}};我想将其转换为C++11可变参数语法以获得灵活长度参数列表的好处。我理解使用递归解压模板arg列表的概念,但我看不到正确的语法。这是我尝试过的:templatestructFoo:Features...{templateboolrecinit(F&arg,G&&...args){if(!F::init())ret

c++ - 递归 Variadic 模板函数的编译错误

我已经在Code::Blocks中准备了一个简单的可变参数模板测试,但是我收到了一个错误:Nomatchingfunctionforcallto'OutputSizes()'这是我的源代码:#include#includeusingnamespacestd;templatevoidOutputSizes(){std::cout();}intmain(){OutputSizes();return0;}我正在使用GNUGCC和-std=C++0x。使用-std=gnu++0x没有任何区别。 最佳答案 这是消除基本情况歧义的方法:#inc

c++ - variadic template template中的Variadic template推导

我不确定这个标题是否有意义,但这个例子实际上很简单://Aconverterstructwithagenericconstructor.templateclassTT>structconverter{templateconverter(constTT&);};//Afewclasstemplates.templatestructfoo{};templatestructfoo2{};templatestructfoo_variadic{};templatestructfoo_variadic2{};intmain(){//Allthesecompile.converter(foo{});

c++ - Variadic 模板代码可在 GCC 4.6 上编译,但不能在 clang 或 GCC 4.7 上编译

我有这段代码(从更复杂的版本简化而来):templateclassTest{public:templatevoidprint(void(*function)(A2...,A1...)){}};voidtest_print(inta,floatb,doublec){}intmain(){Testtest;test.print(&test_print);}如果我在GCC4.6.3上使用g++-std=c++0xfilename.cpp编译它,它编译正常但是在clang3.0上使用clang++-std=c++0xfilename.cpp它抛出以下错误:filename.cpp:14:10:

c++ - Boost 绑定(bind)占位符参数等于 Variadic 模板参数的数量

我想知道是否可以使用传递给可变参数模板的参数数量作为boost::bind调用中的占位符。像这样:templateboost::bind(&function,this,anArg,_1));//IfArgscountequals1boost::bind(&function,this,anArg,_1,_2));//IfArgscountequals2boost::bind(&function,this,anArg,_1,_2,_3));//IfArgscountequals3这可能吗?谢谢 最佳答案 肯定有一种偏特化的方法。你的va

c++ - 将 Variadic 模板包转换为 std::initializer_list

假设有一个接受多个字符串的函数:voidfun(conststd::initializer_list&strings){for(autos:strings)//dosomething}现在,我有一个可变参数template函数说foo()为:templatevoidfoo(){fun(???);}这个方法被外部调用为:foo();//whereA,B,C,Dareclasses这些作为参数传递的类应该包含一个共同的staticconst成员:staticconststd::stringvalue="...";这是我的问题(如何):在foo()中,检查是否所有的Args都包含value使

c++ - 将 NON-POD 类型传递给 Variadic 函数是未定义的行为?

Inthisdocument,作者说OnlyaPOD-typecanbeanargumentfortheellipsis"..."whilestd::stringisnotaPOD-type.我将此理解为将NON-POD类型传递给Variadic函数是未定义的行为。对吗?不过,他是在说C/C++标准吗?我试图在n3242C++规范中找到它。但是找不到。我想知道我的理解是否正确,这是一个标准。 最佳答案 它在C++115.2.2/7中指定:Passingapotentially-evaluatedargumentofclasstype

go - fmt.Println 中的 Variadic 变量扩展

这个问题在这里已经有了答案:Typeconvertingslicesofinterfaces(9个回答)关闭3年前。packagemainimport"fmt"funcmain(){a:=[]int{1,2,3}fmt.Println(a...)}运行会出现以下错误./program.go:5:不能在fmt.Println的参数中使用(type[]int)作为类型[]interface{}来自godocfmtPrintlnfuncPrintln(a...interface{})(nint,errerror)Println接受任何值,因为它是一个空接口(interface)。让我感到困惑