In C ++ 11, you can do this using the output of a template argument. It seems that already exists for this purpose:extent type_trait
#include <type_traits>
int rows = std::extent<decltype(array), 0>::value;
int cols = std::extent<decltype(array), 1>::value;
source
share