• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ranges类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ranges的典型用法代码示例。如果您正苦于以下问题:C++ ranges类的具体用法?C++ ranges怎么用?C++ ranges使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ranges类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:woodstok,项目名称:tc,代码行数:9,代码来源:doors.c


示例2: add

void add(ranges &mylist, ranges myranges )
{
   for(int i=0;i<myranges.size();i++)
   {
      add(mylist,myranges[i]);
   }
}
开发者ID:woodstok,项目名称:tc,代码行数:7,代码来源:doors.c


示例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;
}
开发者ID:woodstok,项目名称:tc,代码行数:8,代码来源:doors.c


示例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;
}
开发者ID:woodstok,项目名称:tc,代码行数:14,代码来源:doors.c


示例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);
}
开发者ID:CaseyCarter,项目名称:cmcstl2,代码行数:18,代码来源:is_permutation.cpp


示例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);
}
开发者ID:CaseyCarter,项目名称:range-v3,代码行数:23,代码来源:accumulate.cpp


示例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();
}
开发者ID:ericniebler,项目名称:range-v3,代码行数:79,代码来源:adjacent_difference.cpp


示例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]);
        }
    }
}
开发者ID:ericniebler,项目名称:range-v3,代码行数:65,代码来源:adjacent_difference.cpp


示例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();
}
开发者ID:mitsutaka-takeda,项目名称:cmcstl2,代码行数:34,代码来源:copy_backward.cpp


示例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();
}
开发者ID:OhGameKillers,项目名称:range-v3,代码行数:52,代码来源:copy.cpp


示例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;
      }
   }
}
开发者ID:woodstok,项目名称:tc,代码行数:81,代码来源:doors.c


示例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();
}
开发者ID:ericniebler,项目名称:range-v3,代码行数:97,代码来源:partial_sum.cpp


示例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]);
        }
    }
}
开发者ID:ericniebler,项目名称:range-v3,代码行数:65,代码来源:partial_sum.cpp


示例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();
}
开发者ID:ericniebler,项目名称:range-v3,代码行数:61,代码来源:upper_bound.cpp


示例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));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:55,代码来源:span.cpp


示例16: test_case_from_array_constructor

void test_case_from_array_constructor()
{
    int arr[5] = {1, 2, 3, 4, 5};

    {
        span<int> s{arr};
        CHECK((s.size() == 5 && s.data() == &arr[0]));
    }

    {
        span<int, 5> s{arr};
        CHECK((s.size() == 5 && s.data() == &arr[0]));
    }

    int arr2d[2][3] = {1, 2, 3, 4, 5, 6};

    CONCEPT_ASSERT(!std::is_constructible<span<int, 6>, int(&)[5]>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 0>, int(&)[5]>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int>, decltype((arr2d))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 0>, decltype((arr2d))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 6>, decltype((arr2d))>::value);

    {
        span<int[3]> s{&(arr2d[0]), 1};
        CHECK((s.size() == 1 && s.data() == &arr2d[0]));
    }

    int arr3d[2][3][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

    CONCEPT_ASSERT(!std::is_constructible<span<int>, decltype((arr3d))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 0>, decltype((arr3d))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 11>, decltype((arr3d))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 12>, decltype((arr3d))>::value);

    {
        span<int[3][2]> s{&arr3d[0], 1};
        CHECK((s.size() == 1 && s.data() == &arr3d[0]));
    }

    {
        auto s = make_span(arr);
        CHECK((s.size() == 5 && s.data() == &arr[0]));
    }

    {
        auto s = make_span(&(arr2d[0]), 1);
        CHECK((s.size() == 1 && s.data() == &arr2d[0]));
    }

    {
        auto s = make_span(&arr3d[0], 1);
        CHECK((s.size() == 1 && s.data() == &arr3d[0]));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:54,代码来源:span.cpp


示例17: test_case_from_const_std_array_constructor

void test_case_from_const_std_array_constructor()
{
    const std::array<int, 4> arr = {1, 2, 3, 4};

    {
        span<const int> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    {
        span<const int, 4> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    CONCEPT_ASSERT(!std::is_constructible<span<const int, 2>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 0>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 5>, decltype((arr))>::value);

    {
        auto get_an_array = []() -> const std::array<int, 4> { return {1, 2, 3, 4}; };
        auto take_a_span = [](span<const int>) {};
        take_a_span(get_an_array());
    }

    {
        auto s = make_span(arr);
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:29,代码来源:span.cpp


示例18: test_case_from_pointer_size_constructor

void test_case_from_pointer_size_constructor()
{
    int arr[4] = {1, 2, 3, 4};

    {
        span<int> s{&arr[0], 2};
        CHECK((s.size() == 2 && s.data() == &arr[0]));
        CHECK((s[0] == 1 && s[1] == 2));
    }

    {
        span<int, 2> s{&arr[0], 2};
        CHECK((s.size() == 2 && s.data() == &arr[0]));
        CHECK((s[0] == 1 && s[1] == 2));
    }

    {
        int* p = nullptr;
        span<int> s{p, static_cast<span<int>::index_type>(0)};
        CHECK((s.size() == 0 && s.data() == nullptr));
    }

    {
        auto s = make_span(&arr[0], 2);
        CHECK((s.size() == 2 && s.data() == &arr[0]));
        CHECK((s[0] == 1 && s[1] == 2));
    }

    {
        int* p = nullptr;
        auto s = make_span(p, static_cast<span<int>::index_type>(0));
        CHECK((s.size() == 0 && s.data() == nullptr));
    }

    {
        int i = 42;
        span<int> s{&i, 0};
        CHECK((s.size() == 0 && s.data() == &i));

        span<const int> cs{&i, 0};
        CHECK((s.size() == 0 && s.data() == &i));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:43,代码来源:span.cpp


示例19: test_case_from_std_array_const_constructor

void test_case_from_std_array_const_constructor()
{
    std::array<const int, 4> arr = {1, 2, 3, 4};

    {
        span<const int> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    {
        span<const int, 4> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    CONCEPT_ASSERT(!std::is_constructible<span<const int, 2>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 0>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 5>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<int, 4>, decltype((arr))>::value);

    {
        auto s = make_span(arr);
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:24,代码来源:span.cpp


示例20: test_case_from_container_constructor

void test_case_from_container_constructor()
{
    std::vector<int> v = {1, 2, 3};
    const std::vector<int> cv = v;

    {
        span<int> s{v};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(v.size()) && s.data() == v.data()));

        span<const int> cs{v};
        CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(v.size()) && cs.data() == v.data()));
    }

    std::string str = "hello";
    const std::string cstr = "hello";

    {
        span<char> s{str};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(str.size()) && s.data() == str.data()));
    }

    {
        auto get_temp_string = []() -> std::string { return {}; };
        auto use_span = [](span<char>) {};
        use_span(get_temp_string());
    }

    {
        span<const char> cs{str};
        CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(str.size()) && cs.data() == str.data()));
    }

    {
        auto get_temp_string = []() -> std::string { return {}; };
        auto use_span = [](span<const char>) {};
        use_span(get_temp_string());
    }

    {
        CONCEPT_ASSERT(!std::is_constructible<span<char>, decltype((cstr))>::value);
        span<const char> cs{cstr};
        CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
              cs.data() == cstr.data()));
    }

    {
        auto get_temp_vector = []() -> std::vector<int> { return {}; };
        auto use_span = [](span<int>) {};
        use_span(get_temp_vector());
    }

    {
        auto get_temp_vector = []() -> std::vector<int> { return {}; };
        auto use_span = [](span<const int>) {};
        use_span(get_temp_vector());
    }

    CONCEPT_ASSERT(!std::is_convertible<const std::vector<int>, span<const char>>::value);

    {
        auto get_temp_string = []() -> const std::string { return {}; };
        auto use_span = [](span<const char> s) { static_cast<void>(s); };
        use_span(get_temp_string());
    }

    CONCEPT_ASSERT(!std::is_constructible<span<int>, std::map<int, int>&>::value);

    {
        auto s = make_span(v);
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(v.size()) && s.data() == v.data()));

        auto cs = make_span(cv);
        CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(cv.size()) && cs.data() == cv.data()));
    }
}
开发者ID:gnzlbg,项目名称:range-v3,代码行数:75,代码来源:span.cpp



注:本文中的ranges类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rank_support_type类代码示例发布时间:2022-05-31
下一篇:
C++ range_t类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap