如何进行自动阵列检测?

how to do automatic array detection?

本文关键字:检测 阵列 何进行      更新时间:2023-10-16

我有时会将这些数字与数组混淆并且无法计数,因为开头是从头开始而不是从头开始。 为了不让我感到困惑,我必须删除具有arr[4][4].大小的数字

我想找到一种方法来自动工作,更准确地说,它会自动确定数字。

我真的很困惑 对我来说arr[4][4].应该是arr[3][3].因为计数器从零开始0,1,2,3

int arr[][] // <--
{
{ 0,0,0,1 },
{ 1,0,0,0 },
{ 0,2,0,4 },
{ 1,1,0,1 }
};

您可能喜欢这样的辅助函数:

#include < array >
#include < iostream >
template < typename ... T  >
constexpr auto f( T ... args) 
{   
return std::array< std::tuple_element_t<0, std::tuple<T...>>, sizeof...(args)> { args...};
}   
int main()
{   
constexpr auto arr = 
f(
f( 0,0,0,1),
f( 1,0,0,0),
f( 0,2,0,4),
f( 1,1,0,1)
);  
for ( auto& x: arr ) { 
for ( auto y: x ) { 
std::cout << y << " " ;
}   
std::cout << std::endl;
}   
// or access via []
std::cout << arr[0][3] << std::endl;
std::cout << arr[2][3] << std::endl;
}