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 can't think of a way to write a single function that handles both, but this is what overloading is for.
template
void check_array_size( T (&)[Bound] )
{
static_assert(Bound == N, "incorrect array size");
}
template
void check_array_size( const std::array& )
{
static_assert(Bound == N, "incorrect array size");
}
template
void check_array_size( ... )
{
static_assert(N<0, "argument is not an array");
}
template
void foo(T& param)
{
check_array_size<3>(param);
// actual function implementation...
}