I need to define a function with template parameter pack with C++14.
The caller of the function makes sure that the size of Args...
must be even, such as 2, 4, 6... And my function will pass them two by two to two functions.
template<typename F, typename F2, typename... Args>
void func(F f, F2 f2, Args&&... params) {
using params_t = std::tuple<Args...>;
auto tp = std::make_tuple(params...);
for (std::size_t i = 0; i < sizeof...(Args); ++i) {
f(std::get<i>(tp));
f2(std::get<++i>(tp));
}
}
// caller
func(f1, f2, "abc", 3, "def", "ppp");
This won't work because i
is not a constant expression.
What could I do? Is it the right and the only way to iterate over a parameter pack with std::tuple
?