本文整理汇总了C++中ranges::make_subrange方法的典型用法代码示例。如果您正苦于以下问题:C++ ranges::make_subrange方法的具体用法?C++ ranges::make_subrange怎么用?C++ ranges::make_subrange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ranges
的用法示例。
在下文中一共展示了ranges::make_subrange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
template<class InIter, class OutIter, class InSent = InIter> void test()
{
using ranges::partial_sum;
using ranges::make_subrange;
{ // iterator
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto r = partial_sum(InIter(ia), InSent(ia + s), OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output iterator
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto r = partial_sum(rng, OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output range
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = partial_sum(rng, orng);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, -1, -4, -8, -13};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = partial_sum(rng, orng, std::minus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
}
示例2: test
template<class InIter, class OutIter, class InSent = InIter> void test()
{
using ranges::adjacent_difference;
using ranges::make_subrange;
{ // iterator
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto r = adjacent_difference(InIter(ia), InSent(ia + s), OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output iterator
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto r = adjacent_difference(rng, OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output range
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = adjacent_difference(rng, orng);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = adjacent_difference(rng, orng, std::plus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
}