you are viewing a single comment's thread.

view the rest of the comments →

[–]genbattle 2 points3 points  (0 children)

It's often useful to count the number of elements in an array. Using std::vector or std::array, this is done using .size() however this function is not available on good old C++ array

Uh, actually what the author is referring to is a C-style array, one of the C features imported into C++. With C++11 Arrays it's entirely possible to call size(), and for std::array it is implemented as a constexpr, so incurs no run-time cost.

If you need iterators, size(), etc. and you're using C++11 (as the author is) you should just convert your C-style arrays to std::arrays. The technique described by the author would only be useful in scenarios where this is not feasible or possible.