Example #1
0
void test_iter_4()
{
    int i[3] = {1, 2, 3};
    int j[4] = {4, 5, 6, 7};
    std::pair<Iter1, Iter2> r = ranges::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j), Iter2(j+4));
    CHECK(base(r.first) == i+3);
    CHECK(base(r.second) == j+3);
    CHECK(i[0] == 4);
    CHECK(i[1] == 5);
    CHECK(i[2] == 6);
    CHECK(j[0] == 1);
    CHECK(j[1] == 2);
    CHECK(j[2] == 3);
    CHECK(j[3] == 7);

    using Sent1 = typename sentinel_type<Iter1>::type;
    using Sent2 = typename sentinel_type<Iter2>::type;
    r = ranges::swap_ranges(Iter1(j), Sent1(j+4), Iter2(i), Sent2(i+3));
    CHECK(base(r.first) == j+3);
    CHECK(base(r.second) == i+3);
    CHECK(i[0] == 1);
    CHECK(i[1] == 2);
    CHECK(i[2] == 3);
    CHECK(j[0] == 4);
    CHECK(j[1] == 5);
    CHECK(j[2] == 6);
    CHECK(j[3] == 7);
}
Example #2
0
void test_rng_4()
{
    int i[3] = {1, 2, 3};
    int j[4] = {4, 5, 6, 7};
    std::pair<Iter1, Iter2> r = ranges::swap_ranges(
        as_lvalue(ranges::make_iterator_range(Iter1(i), Iter1(i+3))),
        as_lvalue(ranges::make_iterator_range(Iter2(j), Iter2(j+4))));
    CHECK(base(r.first) == i+3);
    CHECK(base(r.second) == j+3);
    CHECK(i[0] == 4);
    CHECK(i[1] == 5);
    CHECK(i[2] == 6);
    CHECK(j[0] == 1);
    CHECK(j[1] == 2);
    CHECK(j[2] == 3);
    CHECK(j[3] == 7);

    using Sent1 = typename sentinel_type<Iter1>::type;
    using Sent2 = typename sentinel_type<Iter2>::type;
    r = ranges::swap_ranges(
        as_lvalue(ranges::make_iterator_range(Iter1(j), Sent1(j+4))),
        as_lvalue(ranges::make_iterator_range(Iter2(i), Sent2(i+3))));
    CHECK(base(r.first) == j+3);
    CHECK(base(r.second) == i+3);
    CHECK(i[0] == 1);
    CHECK(i[1] == 2);
    CHECK(i[2] == 3);
    CHECK(j[0] == 4);
    CHECK(j[1] == 5);
    CHECK(j[2] == 6);
    CHECK(j[3] == 7);

    auto r2 = ranges::swap_ranges(
        ranges::make_iterator_range(Iter1(j), Sent1(j+4)),
        ranges::make_iterator_range(Iter2(i), Sent2(i+3)));
    CHECK(base(r2.first.get_unsafe()) == j+3);
    CHECK(base(r2.second.get_unsafe()) == i+3);
    CHECK(i[0] == 4);
    CHECK(i[1] == 5);
    CHECK(i[2] == 6);
    CHECK(j[0] == 1);
    CHECK(j[1] == 2);
    CHECK(j[2] == 3);
    CHECK(j[3] == 7);
}
void
test_iter1()
{
    int ia[] = {1, 2, 3, 4};
    constexpr unsigned sa = ranges::size(ia);
    int ib[] = {1, 2, 3};
    CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+2)));
    CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+2), Iter2(ia), Sent2(ia+sa)));
    CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+3)));
    CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+3), Iter2(ia), Sent2(ia+sa)));
    CHECK(ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib+1), Sent2(ib+3)));
    CHECK(!ranges::lexicographical_compare(Iter1(ib+1), Sent1(ib+3), Iter2(ia), Sent2(ia+sa)));
}
void
test_iter_comp1()
{
    int ia[] = {1, 2, 3, 4};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {1, 2, 3};
    typedef std::greater<int> C;
    C c;
    CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+2), c));
    CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+2), Iter2(ia), Sent2(ia+sa), c));
    CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+3), c));
    CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+3), Iter2(ia), Sent2(ia+sa), c));
    CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib+1), Sent2(ib+3), c));
    CHECK(ranges::lexicographical_compare(Iter1(ib+1), Sent1(ib+3), Iter2(ia), Sent2(ia+sa), c));
}