本文整理汇总了C++中ranges类的典型用法代码示例。如果您正苦于以下问题:C++ ranges类的具体用法?C++ ranges怎么用?C++ ranges使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ranges类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
int intersect(ranges possible,ranges hint)
{
int intersections = 0;
for(int i=0;i < possible.size(); i++)
{
for(int j=0;j<hint.size();j++) intersections+=intersect(possible[i],hint[j]);
}
return intersections > 0;
}
示例2: add
void add(ranges &mylist, ranges myranges )
{
for(int i=0;i<myranges.size();i++)
{
add(mylist,myranges[i]);
}
}
示例3: printranges
void printranges(ranges mylist)
{
for(int i=0;i<mylist.size();i++)
{
cout<<mylist[i].start<<"-"<<mylist[i].end<<" <"<<mylist[i].score<<">| ";
}
cout<<endl;
}
示例4: findBestDoor
int findBestDoor(ranges myranges)
{
int ret = 0;
int bestScore = 0;
for(int i=0;i<myranges.size();i++)
{
if(myranges[i].score > bestScore)
{
bestScore = myranges[i].score;
ret = myranges[i].start;
}
}
return ret;
}
示例5: test
void test(const bool result,
const int* first1, const int* last1,
const int* first2, const int* last2)
{
using ranges::is_permutation;
using ranges::subrange;
using I = forward_iterator<const int*>;
using S = sentinel<const int*>;
CHECK(is_permutation(I{first1}, I{last1}, I{first2}, I{last2}) == result);
CHECK(is_permutation(I{first1}, S{last1}, I{first2}, S{last2}) == result);
CHECK(is_permutation(I{first1}, I{last1}, I{first2}, I{last2}, std::equal_to<int>{}) == result);
CHECK(is_permutation(I{first1}, S{last1}, I{first2}, S{last2}, std::equal_to<int>{}) == result);
CHECK(is_permutation(subrange{I{first1}, I{last1}}, subrange{I{first2}, I{last2}}) == result);
CHECK(is_permutation(subrange{I{first1}, S{last1}}, subrange{I{first2}, S{last2}}) == result);
CHECK(is_permutation(subrange{I{first1}, I{last1}}, subrange{I{first2}, I{last2}}, std::equal_to<int>{}) == result);
CHECK(is_permutation(subrange{I{first1}, S{last1}}, subrange{I{first2}, S{last2}}, std::equal_to<int>{}) == result);
}
示例6: test
void test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
constexpr auto sc = ranges::size(ia);
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 0) == 0);
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 10) == 10);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 0) == 1);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 10) == 11);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 0) == 3);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 10) == 13);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 0) == 21);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 10) == 31);
using ranges::make_iterator_range;
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia)), 0) == 0);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia)), 10) == 10);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+1)), 0) == 1);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+1)), 10) == 11);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+2)), 0) == 3);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+2)), 10) == 13);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+sc)), 0) == 21);
CHECK(ranges::accumulate(make_iterator_range(Iter(ia), Sent(ia+sc)), 10) == 31);
}
示例7: main
int main()
{
test<input_iterator<const int *>, input_iterator<int *>>();
test<input_iterator<const int *>, forward_iterator<int *>>();
test<input_iterator<const int *>, bidirectional_iterator<int *>>();
test<input_iterator<const int *>, random_access_iterator<int *>>();
test<input_iterator<const int *>, int *>();
test<forward_iterator<const int *>, input_iterator<int *>>();
test<forward_iterator<const int *>, forward_iterator<int *>>();
test<forward_iterator<const int *>, bidirectional_iterator<int *>>();
test<forward_iterator<const int *>, random_access_iterator<int *>>();
test<forward_iterator<const int *>, int *>();
test<bidirectional_iterator<const int *>, input_iterator<int *>>();
test<bidirectional_iterator<const int *>, forward_iterator<int *>>();
test<bidirectional_iterator<const int *>, bidirectional_iterator<int *>>();
test<bidirectional_iterator<const int *>, random_access_iterator<int *>>();
test<bidirectional_iterator<const int *>, int *>();
test<random_access_iterator<const int *>, input_iterator<int *>>();
test<random_access_iterator<const int *>, forward_iterator<int *>>();
test<random_access_iterator<const int *>, bidirectional_iterator<int *>>();
test<random_access_iterator<const int *>, random_access_iterator<int *>>();
test<random_access_iterator<const int *>, int *>();
test<const int *, input_iterator<int *>>();
test<const int *, forward_iterator<int *>>();
test<const int *, bidirectional_iterator<int *>>();
test<const int *, random_access_iterator<int *>>();
test<const int *, int *>();
using ranges::adjacent_difference;
{ // Test projections
S ia[] = {{15}, {10}, {6}, {3}, {1}};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ranges::begin(ia), ranges::begin(ia) + s,
ranges::begin(ib), std::minus<int>(), &S::i);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test BinaryOp
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ia, ranges::begin(ib), 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]);
}
}
{ // Test calling it with an array
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ia, ib, 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]);
}
}
return ::test_result();
}
示例8: 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]);
}
}
}
示例9: main
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
std::pair<int, int> const a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
static_assert(size(a) == 6, "");
std::pair<int, int> out[size(a)] = {};
auto res = ranges::copy_backward(begin(a), end(a), end(out));
CHECK(res.first == end(a));
CHECK(res.second == begin(out));
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
CHECK(!std::equal(a, a + size(a), out));
res = ranges::copy_backward(a, end(out));
CHECK(res.first == end(a));
CHECK(res.second == begin(out));
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
auto res2 = ranges::copy_backward(ranges::move(a), end(out));
CHECK(res2.first.get_unsafe() == end(a));
CHECK(res2.second == begin(out));
CHECK(std::equal(a, a + size(a), out));
test_repeat_view();
test_initializer_list();
return test_result();
}
示例10: main
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
std::pair<int, int> const a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
static_assert(size(a) == 6, "");
std::pair<int, int> out[size(a)] = {};
auto res = ranges::copy(begin(a), end(a), out);
CHECK(res.first == end(a));
CHECK(res.second == out + size(out));
CHECK(&res.first == &res.in());
CHECK(&res.second == &res.out());
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
CHECK(!std::equal(a, a + size(a), out));
res = ranges::copy(a, out);
CHECK(res.first == a + size(a));
CHECK(res.second == out + size(out));
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
using ranges::view::delimit;
{
char const *sz = "hello world";
char buf[50];
auto str = delimit(sz, '\0');
auto res3 = ranges::copy(str, buf);
*res3.second = '\0';
CHECK(res3.first == std::next(begin(str), static_cast<std::ptrdiff_t>(std::strlen(sz))));
CHECK(res3.second == buf + std::strlen(sz));
CHECK(std::strcmp(sz, buf) == 0);
}
{
char const *sz = "hello world";
char buf[50];
auto str = delimit(sz, '\0');
auto res3 = ranges::copy(std::move(str), buf);
*res3.second = '\0';
CHECK(res3.first.get_unsafe() == std::next(begin(str), static_cast<std::ptrdiff_t>(std::strlen(sz))));
CHECK(res3.second == buf + std::strlen(sz));
CHECK(std::strcmp(sz, buf) == 0);
}
return test_result();
}
示例11: nextrange
//intersect(currentHint,possibleRanges[j])
//modifies rangelist
range nextrange(ranges &rangelist, range &myrange)
{
if(rangelist.empty())
{
range retRange = myrange;
myrange.start = myrange.end+1;
return retRange;
}
else
{
if(myrange.start > rangelist[0].end)
{
//rangelist[0] is the next range for sure.
range retRange = rangelist[0];
rangelist.erase(rangelist.begin());
return retRange;
}
else if(myrange.start == rangelist[0].end)
{
if(rangelist[0].start == rangelist[0].end )
{
rangelist[0].score++;
range retRange = rangelist[0];
rangelist.erase(rangelist.begin());
myrange.start++;
return retRange;
}
else
{
range retRange = rangelist[0];
retRange.end--;
rangelist[0].start = rangelist[0].end;
rangelist[0].score++;
myrange.start++;
return retRange;
}
}
else if(myrange.start >rangelist[0].start)
{
//we have an intersection here. rangelist[0] <=> myrange.start-1
//update rangelist first element accordingly
range retRange = range(rangelist[0].start,myrange.start-1,rangelist[0].score);
rangelist[0].start = myrange.start;
return retRange;
}
else if(myrange.start == rangelist[0].start)
{
if(myrange.end < rangelist[0].end)
{
// myrange.start to myrange.end is the next range.
// We add 1 to score of rangelist[0] score
range retRange = range(myrange.start,myrange.end,rangelist[0].score+1);
rangelist[0].start = myrange.end+1;
myrange.start = myrange.end+1;
return retRange;
}
else
{
//takes care of myrange.end = rl[0].end also
// rangelist[0] with inc score is the nextrange. Remove it from the list.
// update myrange accordingly
range retRange = range(rangelist[0].start,rangelist[0].end,rangelist[0].score+1);
myrange.start = rangelist[0].end+1;
rangelist.erase(rangelist.begin());
return retRange;
}
}
else
{
//myrange.start < rangelist[0].start
int end = MIN(myrange.end,rangelist[0].start-1);
range retRange = range(myrange.start,end,1);
myrange.start = end+1;
return retRange;
}
}
}
示例12: main
int main()
{
test<input_iterator<const int *>, input_iterator<int *>>();
test<input_iterator<const int *>, forward_iterator<int *>>();
test<input_iterator<const int *>, bidirectional_iterator<int *>>();
test<input_iterator<const int *>, random_access_iterator<int *>>();
test<input_iterator<const int *>, int *>();
test<forward_iterator<const int *>, input_iterator<int *>>();
test<forward_iterator<const int *>, forward_iterator<int *>>();
test<forward_iterator<const int *>, bidirectional_iterator<int *>>();
test<forward_iterator<const int *>, random_access_iterator<int *>>();
test<forward_iterator<const int *>, int *>();
test<bidirectional_iterator<const int *>, input_iterator<int *>>();
test<bidirectional_iterator<const int *>, forward_iterator<int *>>();
test<bidirectional_iterator<const int *>, bidirectional_iterator<int *>>();
test<bidirectional_iterator<const int *>, random_access_iterator<int *>>();
test<bidirectional_iterator<const int *>, int *>();
test<random_access_iterator<const int *>, input_iterator<int *>>();
test<random_access_iterator<const int *>, forward_iterator<int *>>();
test<random_access_iterator<const int *>, bidirectional_iterator<int *>>();
test<random_access_iterator<const int *>, random_access_iterator<int *>>();
test<random_access_iterator<const int *>, int *>();
test<const int *, input_iterator<int *>>();
test<const int *, forward_iterator<int *>>();
test<const int *, bidirectional_iterator<int *>>();
test<const int *, random_access_iterator<int *>>();
test<const int *, int *>();
using ranges::partial_sum;
{ // Test projections
S ia[] = {{1}, {2}, {3}, {4}, {5}};
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ranges::begin(ia), ranges::begin(ia) + s, ranges::begin(ib),
std::plus<int>(), &S::i);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test BinaryOp
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ia, ranges::begin(ib), std::multiplies<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]);
}
}
{ // Test calling it with an array
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ia, ib, std::multiplies<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]);
}
}
{ // Test calling it with proxy iterators
using namespace ranges;
int ia[] = {1, 2, 3, 4, 5};
int ib[] = {99, 99, 99, 99, 99};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ic[s] = {0};
auto rng = view::zip(ia, ib);
using CR = iter_common_reference_t<iterator_t<decltype(rng)>>;
auto r = partial_sum(rng, ic, std::multiplies<int>(), [](CR p) {return p.first;});
CHECK(base(r.in) == ranges::begin(rng) + s);
CHECK(base(r.out) == ic + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ic[i] == ir[i]);
}
}
return ::test_result();
}
示例13: 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]);
}
}
}
示例14: main
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
using ranges::less;
using P = std::pair<int, int>;
P a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
P const c[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), a[0]) == &a[1]);
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), a[1], less()) == &a[2]);
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(begin(a), end(a), a[0]) == &a[1]);
CHECK(ranges::upper_bound(begin(a), end(a), a[1], less()) == &a[2]);
CHECK(ranges::upper_bound(begin(a), end(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(a, a[2]) == &a[3]);
CHECK(ranges::upper_bound(c, c[3]) == &c[4]);
CHECK(ranges::upper_bound(a, a[4], less()) == &a[5]);
CHECK(ranges::upper_bound(c, c[5], less()) == &c[6]);
CHECK(ranges::upper_bound(a, 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(c, 1, less(), &std::pair<int, int>::first) == &c[4]);
std::vector<P> vec_a(ranges::begin(a), ranges::end(a));
std::vector<P> const vec_c(ranges::begin(c), ranges::end(c));
CHECK(ranges::upper_bound(ranges::view::all(a), a[2]) == &a[3]);
CHECK(ranges::upper_bound(ranges::view::all(c), c[3]) == &c[4]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), a[2])));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), c[3])));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), vec_a[2])));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), vec_c[3])));
CHECK(ranges::upper_bound(ranges::view::all(a), a[4], less()) == &a[5]);
CHECK(ranges::upper_bound(ranges::view::all(c), c[5], less()) == &c[6]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), a[4], less())));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), c[5], less())));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), vec_a[4], less())));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), vec_c[5], less())));
CHECK(ranges::upper_bound(ranges::view::all(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(ranges::view::all(c), 1, less(), &std::pair<int, int>::first) == &c[4]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), 1, less(), &std::pair<int, int>::first)));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), 1, less(), &std::pair<int, int>::first)));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), 1, less(), &std::pair<int, int>::first)));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), 1, less(), &std::pair<int, int>::first)));
return test_result();
}
示例15: test_case_from_pointer_pointer_constructor
void test_case_from_pointer_pointer_constructor()
{
int arr[4] = {1, 2, 3, 4};
{
span<int> s{&arr[0], &arr[2]};
CHECK((s.size() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
span<int, 2> s{&arr[0], &arr[2]};
CHECK((s.size() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
span<int> s{&arr[0], &arr[0]};
CHECK((s.size() == 0 && s.data() == &arr[0]));
}
{
span<int, 0> s{&arr[0], &arr[0]};
CHECK((s.size() == 0 && s.data() == &arr[0]));
}
{
int* p = nullptr;
span<int> s{p, p};
CHECK((s.size() == 0 && s.data() == nullptr));
}
{
int* p = nullptr;
span<int, 0> s{p, p};
CHECK((s.size() == 0 && s.data() == nullptr));
}
{
auto s = make_span(&arr[0], &arr[2]);
CHECK((s.size() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
auto s = make_span(&arr[0], &arr[0]);
CHECK((s.size() == 0 && s.data() == &arr[0]));
}
{
int* p = nullptr;
auto s = make_span(p, p);
CHECK((s.size() == 0 && s.data() == nullptr));
}
}