1. Let the array size be a template parameter (see link posted by TarikNeaj).
2. Write the function as you would have for raw arrays and take an int* as first argument and the size as a second argument. Calling the function would then look something like this: print_array(my_array.data(), my_array.size());
3. Pass an iterator pair to the function. This requires the use of templates. The page that TarikNeaj linked also contains an example of this (further down).
I haven't gotten to templates yet, so I picked #2.
Worked fine.
It appears the advantage of using a pointer based approach std::array->array.data() etc. allows the user to repeatedly pass the std::array container to a function without having the hard coding issue of the array element size when reusing the function for different arrays.
It appears the advantage of using a pointer based approach std::array->array.data() etc. allows the user to repeatedly pass the std::array container to a function without having the hard coding issue of the array element size when reusing the function for different arrays.
The advantage has a cost. Whereas when a template function is used and the size is provided automatically, when the pointer approach is used there exists an opportunity for the size provided to the function not to be accurate.
IOW, you've increased the opportunity for bugs to appear in code using the function.
How is there an opportunity for size provided to be inaccurate?
Is this a serious question? You provide the size rather than it being associated with the type. This means you can do things like: print_array(array, -1);
Yes, it is a serious question. I think its quite possible the question is lost in translation here between us. If you are referring to operator error I guess I get what you are saying. Otherwise no.
Further reflection I would guess that types would reduce this kind of error.