Array size metafunction - is it in boost somewhere? Array size metafunction - is it in boost somewhere? arrays arrays

Array size metafunction - is it in boost somewhere?


I eventually found the answer myself - boost::size():

#include <boost/range.hpp>int array[10];boost::size(array); // returns 10


In the new C++ standard, std::array from the header has the method size(), which returns a constexpr and is therefore available at compile time.

You should be able to to something like

std::array< YourType, N > arr;constexpr auto totalSize = arr.size() * sizeof( std::array< YourType, N >::value_type );

Hope this helps...


C++ 17 support std::size() (defined in header <iterator>)

#include <iterator>int my_array[10];std::size(my_array);std::vector<int> my_vector(10);std::size(my_vector);