【发布时间】:2016-12-09 13:12:38
【问题描述】:
我有这样的功能:
template <typename ... Types>
void foo(const Types & ... values)
{
// expected that 'values' is sequence like
// '1, customvalue1, 2, customvalue2, 3,...'
}
第二个功能:
template <typename ... Types>
void bar(const Types & ... values)
{
// where 'values' are any variables
// some magic here
foo((int_seq<sizeof...(Types)>, values)...);
}
我想将任何变量序列传递给 bar,以便将该序列转换为 '1, value1, 2, value2, 3, value3' 之类的序列>。因此,每个值都遵循其基本序列中的编号。但是我不能创建这个'魔术代码'来在这两种状态之间转换编译阶段的序列。
【问题讨论】:
-
我假设
bar应该调用foo?不递归调用自己? -
你看过关联数组吗?对于这种类型的数据结构,这似乎是一个问题
-
是的,我错了,当然是 'foo',而不是 'bar'
标签: c++ templates c++11 variadic-templates variadic-functions