std::array takes two template parameters:
typename T // the element type
size_t N // the size of the array
I want to define a function that takes a std::array as a parameter but only for a specific T, in this case char, but for any size array:
The below is malformed:
void f(array<char, size_t N> x) // ???
{
cout << N;
}
int main()
{
array<char, 42> A;
f(A); // should print 42
array<int, 42> B;
f(B); // should not compile
}
What is the correct way to write this?
Use a template function: