将 7x5 矩阵展平为 std::vector,我想使用 Eric Niebler 的 range-v3 库查看列和行。到目前为止,我设法(改进空间)获得了单行、单列和连接行的视图。
请参阅:https ://wandbox.org/permlink/8o4RgSucF3zSNuPN
std::vector<int> numbers = {
00, 01, 02, 03, 04,
10, 11, 12, 13, 14,
20, 21, 22, 23, 24,
30, 31, 32, 33, 34,
40, 41, 42, 43, 44,
50, 51, 52, 53, 54,
60, 61, 62, 63, 64,
};
const size_t n = 5;//number of columns
//Row_3 = {30, 31, 32, 33, 34}
auto Row_3 = numbers | GetRow(3, n);
std::cout << Row_3 << std::endl;
//Col_2 = {02, 12, 22, 32, 42, 52, 62}
auto Col_2 = numbers | GetColumn(2, n);
std::cout << Col_2 << std::endl;
//Row_2_3_4 = {{20, 21, 22, 23, 24},
// {30, 31, 32, 33, 34},
// {40, 41, 42, 43, 44}}
auto Rows_2_3_4 = numbers | GetConnectedRows(2, 4, n);
std::cout << Rows_2_3_4 << std::endl;
但是我怎样才能快速了解:
行列表:
auto a = numbers | GetRows({2,3,5}, n);
连接的列:
auto b = numbers | GetCols(2, 4, n);
列列表:
auto c = numbers | GetCols({1,2,4}, n);
行列表(“未排序”):
auto d = numbers | GetRows({5,2,3}, n);
列列表(“未排序”):
auto e = numbers | GetCols({4,1,2}, n);
?