Using std::extent on std::array

后端 未结 4 1742
名媛妹妹
名媛妹妹 2021-01-13 08:21

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:<

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 08:55

    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" );
    }
    

提交回复
热议问题