Using std::extent on std::array

arrays, c++, static-assert, templates

Solution

This builds on iavr's solution.

template < typename T >
void foo( T& param )
{
    static_assert( 3 == ( std::is_array< T >::value ? std::extent< T >::value : std::tuple_size< T >::value ), "param must have a size of 3" );
}

Problem

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: ``` template < typename T > void foo( T& param ) { // This line is the one that I need to figure out how to write static_assert( 3 == std::extent< T >::value, "param must have a size of 3" ); } int main( void ) { int cArray[3]; std::array< int, 3 > stdArray; foo( cArray ); foo( stdArray ); } ```

Original source

Related problems