本文整理汇总了C++中span::section方法的典型用法代码示例。如果您正苦于以下问题:C++ span::section方法的具体用法?C++ span::section怎么用?C++ span::section使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类span
的用法示例。
在下文中一共展示了span::section方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: iterate_second_slice
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++;
}
}
示例2: iterate_second_column
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);
}
}