Nancy Keuss wrote:
Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?
Thanks,
N.
#include <cstddef>
#include <utility>
typedef std::pair< std::size_t, std::size_t > Dimension_Pair;
template< typename T, std::size_t n, std::size_t m >
Dimension_Pair get_dimensions( T (&)[ n ][ m ] )
{
return Dimension_Pair( n, m );
}
#include <iostream>
int main( )
{
char c[ 3 ][ 5 ];
Dimension_Pair dimensions = get_dimensions( c );
std::cout << dimensions.first << ", " << dimensions.second
<< '\n';
}