Implementation with function parameter packs

I don't understand how can implement this functionality with variadic templates. I don't understand if it is possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template<typename Func, typename C>
void applyFunction(Func func, C &c)
   { for(size_t z = 0; z < c.size(); z++) func(c[z]); }

template<typename Func, typename C1, typename C2>
void applyFunction(Func func, C1 &c1, C2 &c2)
   { for(size_t z = 0; z < c1.size(); z++) func(c1[z], c2[z]); }

// the same with parameters C1, C2, C3
// the same with parameters C1, C2, C3, C4

int main()
{
   array<int, 10> a, b;
   applyFunction([](int &a, int b) { a += b; }, a, b);   // a += b;

   int len = 0;
   applyFunction([&len](int a) { len += a * a; }, a);   // a.length2();
}


I want to merge the 4 template functions above, in one like:
1
2
3
template<typename Func, typename... C>
void applyFunction(Func func, C... &c)
   { for(size_t z = 0; z < ??????.size(); z++) func(??????[z]); }
Topic archived. No new replies allowed.