I have this code snippet in C:
int foo[5];
int bar[10];
Func(foo, _countof(foo)); // (_countof(x) is the size of the array x)
Func(foo, _countof(bar));
void Func(int p[], int count)
{
for (int i = 0; i < count; i++)
{
// do something with p[i]
}
}
I need to translate this into C++
My first thought was something like this:
std::array<int, 5> foo;
std::array<int, 10> bar;
Func(foo, foo.size());
// or even better:
Func(foo);
So far so good, but now I'm stuck with the Func
function, I need to pass the std::array
and the size, but std::array<int, 5>
is not the same type as std::array<int, 10>
.
void Func(std::array<int, ???> a, size_t count)
{
}
Is there an elegant way to solve this using std::array
?
Do I need Func
to be a function template?
I know how to do it with std::vector
instead of std::array
.