我有一個模板化函數,我想static_assert
它的類型大小爲3。此代碼說明了什麼,我試圖做的,但不工作:在std :: array上使用std :: extent
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);
}
嘗試通過參考?我不認爲C數組喜歡按照這樣的價值傳遞。 –
你應該解釋它如何「不起作用」。你有錯誤嗎?哪個? – sth
我認爲他/她在編譯時得到「參數必須是3的大小」。 – DrD