Tell me how to write a function that will take as an argument an array of any size, for example int elements, inside which it will be possible using the std::begin function to get a pointer to the first element of the array?
void func(array)
{
auto arr_begin = std::begin(array);
// ...
}
I found an example of a template function. It seems to be working correctly. Only it is not clear how this function learns that the argument was an array and how does it know the size of the array if it is not explicitly specified in the function? In fact, the parameter is written in the function as T& arr, i.e. T can be any type.
Why is the parameter not written like this: T(&arr)[] ?
I managed to write only a function that accepts an array of int elements but of a fixed size:
void func(const int (&arr)[5])
{
auto arr_begin = std::begin(arr); // OK
// ...
}
How to write the same function but without specifying a fixed size? And is it possible to do this in principle?