性病使用的std ::程度::阵列 [英] Using std::extent on std::array
本文介绍了性病使用的std ::程度::阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模板化的功能,我想 static_assert
,它的类型有大小三个。这code说明了什么,我试图做的,但不工作:
模板<类型名T>
无效美孚(T&安培;参数)
{
//这行是我需要弄清楚如何写一
static_assert(3 ==的std ::程度< T> ::值,参数必须有一个大小为3);
}INT主要(无效)
{
INT CARRAY [3];
的std ::阵列<整型,3 GT; stdArray; 富(CARRAY);
富(stdArray);
}
解决方案
此基础上 iavr 的解决方案。
模板<类型名T>
无效美孚(T&安培;参数)
{
?static_assert(3 ==(STD :: is_array< T> ::值的std ::程度< T> ::值:性病:: tuple_size< T> ::值),参数必须有一个尺寸3);
}
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 );
}
解决方案
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" );
}
这篇关于性病使用的std ::程度::阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文