We can still use same functions std::size() (in C++17) and std::ssize() (in C++20) as we did for std::vector and std::array But in older C++ versions such as C++11 and C++14, these functions are not available. Here we can use following function:
template <typename T, std::size_t N>
std::size_t size(const T (&)[N])
{
return N;
}
int array[]{1, 2, 3};
std::cout << size(array) << '\n';It uses TAD (Template argument deduction) for function templates to deduce the type template parameter T and non-type template parameter N from array.