void iterate_every_other_element(multi_span<int, dynamic_range> av) { // pick every other element auto length = av.size() / 2; #if _MSC_VER > 1800 auto bounds = strided_bounds<1>({length}, {2}); #else auto bounds = strided_bounds<1>(index<1>{ length }, index<1>{ 2 }); #endif strided_span<int, 1> strided(&av.data()[1], av.size() - 1, bounds); CHECK(strided.size() == length); CHECK(strided.bounds().index_bounds()[0] == length); for (auto i = 0; i < strided.size(); ++i) { CHECK(strided[i] == av[2 * i + 1]); } int idx = 0; for (auto num : strided) { CHECK(num == av[2 * idx + 1]); idx++; } }
void iterate_second_slice(multi_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++; } }
using namespace gsl; namespace { struct BaseClass { }; struct DerivedClass : BaseClass { }; } TEST_CASE("default_constructor") { { multi_span<int> s; CHECK((s.length() == 0 && s.data() == nullptr)); multi_span<const int> cs; CHECK((cs.length() == 0 && cs.data() == nullptr)); } { multi_span<int, 0> s; CHECK((s.length() == 0 && s.data() == nullptr)); multi_span<const int, 0> cs; CHECK((cs.length() == 0 && cs.data() == nullptr)); } {