I usually use std::vector and like to pass by reference to const. However, if my api can be called at some point by c-code, using pass by const-pointer may make sense, although you also need to send the size. If a function can be called using std::array or std::vector , you can decide to send a pointer (and size) or a set of iterators (start / end).
If we are talking about using std :: array, the template argument requires the size of the array. This will mean a normal function, you need a fixed size:
void myfunc( const std::array<int, 5>& mydata ){...}
However, if we perform a template function, template size, this is no longer a problem.
template<unsigned int SZ> void myfunc(const std::array<int, SZ>& mydata) {...}
If we are talking about c-style arrays allocated by stacks ... Good C ++ style prefers std :: array / std :: vector for c-style arrays. I would recommend reading the C ++ Coding Standard from Herb Sutter , chapter 77 on page 152 talks about the subject. When using c-style arrays, sending a pointer and size is the standard way to jump.
Atifm source share