这样地:
template <size_t... indices, typename... Ts>
void foo(const Things *things)
{
std::apply([](auto...args) {
bar(args...);
}, std::tuple_cat(std::make_tuple(indices, parse<Ts>(*(things++)))...));
}
如果
bar
是lambda而不是函数模板,您只需传递
酒吧
直接作为
std::apply
.
如果要避免复制的返回值
parse<Ts>(*(things++))
,你可以使用
std::forward_as_tuple
而不是
std::make_tuple
.
如果
*(things++)
让你不舒服的是使用
std::index_sequence
:
template <size_t... indices, typename... Ts>
void foo(const Things *things)
{
[=]<auto... Is>(std::index_sequence<Is...>) {
std::apply([](auto...args) {
bar(args...);
}, std::tuple_cat(std::make_tuple(indices, parse<Ts>(things[Is]))...));
}(std::index_sequence_for<Ts...>());
}