我有以下代码使用模板和数组维度作为模板非类型参数
template<int n> double f(double c[n]);
...
double c[5];
f<5>(c); // compiles
f(c); // does not compile
Run Code Online (Sandbox Code Playgroud)
编译器是否应该能够在没有显式模板参数的情况下实例化第二个f?我正在使用g ++ 4.1
我有一个模板化的功能,我想static_assert它的类型有三个大小.此代码说明了我正在尝试做什么,但不起作用:
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 );
}
Run Code Online (Sandbox Code Playgroud)