Unsigned narrowing to int

I got this template function for getting the size of an array [], and I want to use unsigned since, obviously, the array size will never be negative and I want to be prepared for any extremely large arrays I'll implement in the future. However, my compiler is warning me that size is narrowing to an int, so I am afraid that that information is either lost of distorted.

Here is the code:
1
2
template<typename T, unsigned size>
inline unsigned GAL(T(&)[size]){return size;}


Any way I can avoid this narrowing? I'm not used to working with templates...
1
2
3
4
#include <cstddef>

template < typename T, std::size_t N >
inline constexpr std::size_t size( T(&)[N] ){ return N; }
Thanks! But just to be sure... the size in "const expr std::size_t size" represents the name of the function, right?
Yes, size() is the function.

And constexpr is a (single) keyword
http://www.stroustrup.com/C++11FAQ.html#constexpr
Topic archived. No new replies allowed.