I have a templatized function and I want to static_assert
that it\'s type has a size of three. This code illustrates what I\'m trying to do, but doesn\'t work:<
I suspect you're having this error because at compile time (which is when *static_assert* is evaluated) the dimensions of cArray and stdArray are unknown, and std::extent returns zero:
http://en.cppreference.com/w/cpp/types/extent
In fact, the error disappears if you change the condition to equal to zero:
static_assert( std::extent< T >::value == 0, "param is not zero" );
Nevertheless, as it has already been pointed out in other posts, std::extent won't work for std::array, only for built in arrays such as cArray
AFTER OP's EDIT: Now that you have modified foo to accept a reference, you'll have that std::extent reports 3 for cArray and 0 (zero) for stdArray. Hence, you'll carry on having the exception at compile time, because the dimension of stdArray is not 3.