#include <iostream>
using namespace std;
template <class T, class... Other>
auto sum(T& first, Other... other)
{
T mas[] = { other... };
cout << "size: " << sizeof...(other) << endl;
//T *f = other...;
for (int m : mas)
first += m;
return first;
}
int main()
{
int summa = 0;
sum(summa, 1, 2, 3, 4, 5, 6, 7);
cout << "sum: " << summa << endl;
return 0;
}
There is a short piece of code that outputs the following:
size: 7
sum: 28
The question is very simple and quick to get the same answer:
How do I access element by element each variable accounting parameter other
? I tried to create a pointer, but it constantly complains, in short, I don’t know how it looks syntactically.
I will make a reservation right away that I am not interested in how to decompose the elements into an array, I myself know how exactly I should refer to each element exactly other.
More precisely, how to expand the parameter package without recursion and not decomposing the elements into an array?