I think a lot of people have trouble with knowing how to get the size of an array,
so a while ago I created a function for getting the size of an array,
and a demo showing how to use that function.
(By size, I mean the number of elements in the array,
not the size in bytes - that’s what sizeof is for.)
I recently spent a few hours filling in the README to explain how it works,
and why the function should be implemented in that particular way,
so I’ve decided to make a thread linking to it in the hopes that people will have an easier time finding out about it,
and in the hopes that people will find it useful:
I mean the number of elements.
Or to put it more formally, the extent of the 0th dimension of the array.
It might seem odd, but most C++ literature does actually call the number of elements the ‘size’ of the array.
Hence std::size, which this function is a substitute for,
though std::size works for more than just arrays and this doesn’t.
I’ve made an edit in the first post to specify this.
I think part of the reason for the delay is that C++11 introduced std::array which is intended to replace ‘raw’ arrays,
but eventually they realised the benefit of a free function that works on both raw arrays and container types.
(It also took until C++17 to get a std::clamp function.)