void iterate_second_slice(span<int, dynamic_range, dynamic_range, dynamic_range> av) { int expected[6] = { 2,3,10,11,18,19 }; auto section = av.section({ 0,1,0 }, { 3,1,2 }); for (auto i = 0; i < section.extent<0>(); ++i) { for (auto j = 0; j < section.extent<1>(); ++j) for (auto k = 0; k < section.extent<2>(); ++k) { auto idx = index<3>{ i,j,k }; // avoid braces in the CHECK macro CHECK(section[idx] == expected[2 * i + 2 * j + k]); } } for (auto i = 0; i < section.extent<0>(); ++i) { for (auto j = 0; j < section.extent<1>(); ++j) for (auto k = 0; k < section.extent<2>(); ++k) CHECK(section[i][j][k] == expected[2 * i + 2 * j + k]); } int i = 0; for (auto num : section) { CHECK(num == expected[i]); i++; } }
void iterate_second_column(span<int, dynamic_range, dynamic_range> av) { auto length = av.size() / 2; // view to the second column auto section = av.section({ 0,1 }, { length,1 }); CHECK(section.size() == length); for (auto i = 0; i < section.size(); ++i) { CHECK(section[i][0] == av[i][1]); } for (auto i = 0; i < section.size(); ++i) { auto idx = index<2>{ i,0 }; // avoid braces inside the CHECK macro CHECK(section[idx] == av[i][1]); } CHECK(section.bounds().index_bounds()[0] == length); CHECK(section.bounds().index_bounds()[1] == 1); for (auto i = 0; i < section.bounds().index_bounds()[0]; ++i) { for (auto j = 0; j < section.bounds().index_bounds()[1]; ++j) { auto idx = index<2>{ i,j }; // avoid braces inside the CHECK macro CHECK(section[idx] == av[i][1]); } } size_t check_sum = 0; for (auto i = 0; i < length; ++i) { check_sum += av[i][1]; } { auto idx = 0; size_t sum = 0; for (auto num : section) { CHECK(num == av[idx][1]); sum += num; idx++; } CHECK(sum == check_sum); } { size_t idx = length - 1; size_t sum = 0; for (auto iter = section.rbegin(); iter != section.rend(); ++iter) { CHECK(*iter == av[idx][1]); sum += *iter; idx--; } CHECK(sum == check_sum); } }