Showing posts with label template. Show all posts
Showing posts with label template. Show all posts

Sunday, 10 April 2011

Calculating size of arrays - one dimensional and multiple dimensional

Someone asked at stackoverflow : How to get size of an array using metaprogramming?

My solution:

For one dimensional arrays,

template<typename T, size_t N>
size_t size_of_array(T (&)[N])
{
   return N;
}