有没有办法返回一个我可以迭代列的视图,就像行一样。
对于行:
typedef boost::multi_array_types::index_range range;
boost::multi_array<int, 2> card(boost::extents[5][5]);
card[0][1] = 0;
card[0][2] = 0;
card[0][3] = 0;
card[0][4] = 0;
bool win = true;
// Check for row for 0
for(auto row : card) {
// win is true for first row
win = std::all_of(row.begin(), row.end(), [](auto i) { return i == 0; });
}
这适用于列,但不是经典for循环,我觉得必须有一个更优雅的C ++ 11样式for()循环,如果我只能检索到一组列的迭代器。
card[0][1] = 0;
card[1][1] = 0;
card[2][1] = 0;
card[3][1] = 0;
card[4][1] = 0;
for (auto j = 0U; j < card.shape()[1]; j++) {
auto col = card[boost::indices[range()][j]];
// Win = true for 2nd column
win = std::all_of(col.begin(), col.end(), [](auto i) { return i == 0; });
}