Skip to content

Instantly share code, notes, and snippets.

@dnaga392
Created November 15, 2017 02:13
Show Gist options
  • Save dnaga392/54ccc73f7a309eb2bd1e7b0f85a78081 to your computer and use it in GitHub Desktop.
Save dnaga392/54ccc73f7a309eb2bd1e7b0f85a78081 to your computer and use it in GitHub Desktop.
(C++11) example to get array length by template method.
#include <iostream>
template<typename T, std::size_t N>
std::size_t array_length(const T (&a)[N])
{
return N;
}
int main(int argc, char *argv[])
{
int array[10];
std::cout << array_length(array) << std::endl;
return 0;
}