Ejemplo n.º 1
0
void
test()
{
    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
    const int sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {2, 4, 4, 6};
    const int sb = sizeof(ib)/sizeof(ib[0]);
    int ic[20];
    int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6};
    const int sr = sizeof(ir)/sizeof(ir[0]);

    using R = std::tuple<Iter1, Iter2, OutIter>;
    auto set_union = make_testable_2(ranges::set_union);

    auto checker = [&](R res)
    {
        CHECK((base(std::get<2>(res)) - ic) == sr);
        CHECK(std::lexicographical_compare(ic, base(std::get<2>(res)), ir, ir+sr) == false);
        ranges::fill(ic, 0);
    };

    set_union(Iter1(ia), Iter1(ia+sa),
        Iter2(ib), Iter2(ib+sb), OutIter(ic)).check(checker);
    set_union(Iter1(ib), Iter1(ib+sb),
        Iter2(ia), Iter2(ia+sa), OutIter(ic)).check(checker);

    set_union(Iter1(ia), Iter1(ia+sa),
        Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).check(checker);
    set_union(Iter1(ib), Iter1(ib+sb),
        Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).check(checker);
}
Ejemplo n.º 2
0
void test_comp() {
	int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
	const int sa = sizeof(ia)/sizeof(ia[0]);
	int ib[] = {2, 4, 4, 6};
	const int sb = sizeof(ib)/sizeof(ib[0]);
	int ic[20];
	int ir[] = {1, 2, 3, 3, 3, 4, 4};
	const int sr = sizeof(ir)/sizeof(ir[0]);

	auto set_difference = ::make_testable_2<false, true>([](auto&&... args) {
		return ranges::set_difference(std::forward<decltype(args)>(args)...);
	});

	set_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).
		check([&](ranges::set_difference_result<Iter1, OutIter> res)
		{
			CHECK(bool((base(res.in) - ia) == sa));
			CHECK(bool((base(res.out) - ic) == sr));
			CHECK(!std::lexicographical_compare(ic, base(res.out), ir, ir+sr));
			ranges::fill(ic, 0);
		}
	);
	int irr[] = {6};
	const int srr = sizeof(irr)/sizeof(irr[0]);
	set_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).
		check([&](ranges::set_difference_result<Iter1, OutIter> res)
		{
			CHECK(bool((base(res.in) - ib) == sb));
			CHECK(bool((base(res.out) - ic) == srr));
			CHECK(!std::lexicographical_compare(ic, base(res.out), irr, irr+srr));
			ranges::fill(ic, 0);
		}
	);
}
Ejemplo n.º 3
0
void
test_comp()
{
    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
    const int sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {2, 4, 4, 6};
    const int sb = sizeof(ib)/sizeof(ib[0]);
    int ic[20];
    int ir[] = {1, 2, 3, 3, 3, 4, 4};
    const int sr = sizeof(ir)/sizeof(ir[0]);

    auto set_difference = ::make_testable_2<false, true>(ranges::set_difference);

    set_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).
        check([&](std::pair<Iter1, OutIter> res)
        {
            CHECK((base(res.first) - ia) == sa);
            CHECK((base(res.second) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(res.second), ir, ir+sr) == 0);
            ranges::fill(ic, 0);
        }
    );
    int irr[] = {6};
    const int srr = sizeof(irr)/sizeof(irr[0]);
    set_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).
        check([&](std::pair<Iter1, OutIter> res)
        {
            CHECK((base(res.first) - ib) == sb);
            CHECK((base(res.second) - ic) == srr);
            CHECK(std::lexicographical_compare(ic, base(res.second), irr, irr+srr) == 0);
            ranges::fill(ic, 0);
        }
    );
}
Ejemplo n.º 4
0
void
test1()
{
    {
        const int N = 100;
        std::unique_ptr<int> ia[N];
        for(int i = 0; i < N; ++i)
            ia[i].reset(new int(i));
        std::unique_ptr<int> ib[N];

        std::pair<InIter, OutIter> r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib+N);
        for(int i = 0; i < N; ++i)
        {
            CHECK(ia[i].get() == nullptr);
            CHECK(*ib[i] == i);
        }
    }

    {
        const int N = 100;
        std::unique_ptr<int> ia[N];
        for(int i = 0; i < N; ++i)
            ia[i].reset(new int(i));
        std::unique_ptr<int> ib[N];

        std::pair<InIter, OutIter> r = ranges::move(as_lvalue(ranges::make_iterator_range(InIter(ia), Sent(ia+N))), OutIter(ib));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib+N);
        for(int i = 0; i < N; ++i)
        {
            CHECK(ia[i].get() == nullptr);
            CHECK(*ib[i] == i);
        }

        ranges::move(ib, ib+N, ia);

        auto r2 = ranges::move(ranges::make_iterator_range(InIter(ia), Sent(ia+N)), OutIter(ib));
        CHECK(base(r2.first.get_unsafe()) == ia+N);
        CHECK(base(r2.second) == ib+N);
        for(int i = 0; i < N; ++i)
        {
            CHECK(ia[i].get() == nullptr);
            CHECK(*ib[i] == i);
        }
    }
}
Ejemplo n.º 5
0
void
test()
{
    {
        const int N = 1000;
        int ia[N];
        for(int i = 0; i < N; ++i)
            ia[i] = i;
        int ib[N] = {0};

        std::pair<InIter, OutIter> r = stl2::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib);
        for(int i = 0; i < N; ++i)
            CHECK(ia[i] == ib[i]);
    }

    {
        const int N = 1000;
        int ia[N];
        for(int i = 0; i < N; ++i)
            ia[i] = i;
        int ib[N] = {0};

        std::pair<InIter, OutIter> r = stl2::move_backward(as_lvalue(stl2::ext::make_range(InIter(ia), InIter(ia+N))), OutIter(ib+N));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib);
        for(int i = 0; i < N; ++i)
            CHECK(ia[i] == ib[i]);
    }
}
Ejemplo n.º 6
0
void
test()
{
    {
        const int N = 1000;
        int ia[N];
        for(int i = 0; i < N; ++i)
            ia[i] = i;
        int ib[N] = {0};

        std::pair<InIter, OutIter> r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib+N);
        for(int i = 0; i < N; ++i)
            CHECK(ia[i] == ib[i]);
    }

    {
        const int N = 1000;
        int ia[N];
        for(int i = 0; i < N; ++i)
            ia[i] = i;
        int ib[N] = {0};

        std::pair<InIter, OutIter> r = ranges::move(as_lvalue(ranges::make_iterator_range(InIter(ia), Sent(ia+N))), OutIter(ib));
        CHECK(base(r.first) == ia+N);
        CHECK(base(r.second) == ib+N);
        for(int i = 0; i < N; ++i)
            CHECK(ia[i] == ib[i]);
    }
}
Ejemplo n.º 7
0
void
test()
{
    {
    unsigned N = 100000;
    int* ia = new int[N];
    int* ib = new int[N];
    int* ic = new int[2*N];
    for (unsigned i = 0; i < N; ++i)
        ia[i] = 2*i;
    for (unsigned i = 0; i < N; ++i)
        ib[i] = 2*i+1;
    std::reverse(ia, ia+N);
    std::reverse(ib, ib+N);
    OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
                           InIter2(ib), InIter2(ib+N), OutIter(ic), std::greater<int>());
    assert(base(r) == ic+2*N);
    assert(ic[0] == 2*N-1);
    assert(ic[2*N-1] == 0);
    assert(std::is_sorted(ic, ic+2*N, std::greater<int>()));
    delete [] ic;
    delete [] ib;
    delete [] ia;
    }
    {
    unsigned N = 100;
    int* ia = new int[N];
    int* ib = new int[N];
    int* ic = new int[2*N];
    for (unsigned i = 0; i < 2*N; ++i)
        ic[i] = i;
    std::random_shuffle(ic, ic+2*N);
    std::copy(ic, ic+N, ia);
    std::copy(ic+N, ic+2*N, ib);
    std::sort(ia, ia+N, std::greater<int>());
    std::sort(ib, ib+N, std::greater<int>());
    OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
                           InIter2(ib), InIter2(ib+N), OutIter(ic), std::greater<int>());
    assert(base(r) == ic+2*N);
    assert(ic[0] == 2*N-1);
    assert(ic[2*N-1] == 0);
    assert(std::is_sorted(ic, ic+2*N, std::greater<int>()));
    delete [] ic;
    delete [] ib;
    delete [] ia;
    }
}
Ejemplo n.º 8
0
void
test()
{
    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
    const int sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {2, 4, 4, 6};
    const int sb = sizeof(ib)/sizeof(ib[0]);
    int ic[20];
    int ir[] = {2, 4, 4};
    const int sr = sizeof(ir)/sizeof(ir[0]);

    auto set_intersection = ::make_testable_2<true, true>([](auto&&...args) {
        return stl2::set_intersection(stl2::forward<decltype(args)>(args)...);
    });

    set_intersection(Iter1(ia), Iter1(ia+sa),
                     Iter2(ib), Iter2(ib+sb), OutIter(ic)).check([&](OutIter ce)
        {
            CHECK((base(ce) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
            stl2::fill(ic, 0);
        });
    set_intersection(Iter1(ib), Iter1(ib+sb),
                     Iter2(ia), Iter2(ia+sa), OutIter(ic)).check([&](OutIter ce)
        {
            CHECK((base(ce) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
            stl2::fill(ic, 0);
        });


    set_intersection(Iter1(ia), Iter1(ia+sa),
                     Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).check([&](OutIter ce)
        {
            CHECK((base(ce) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
            stl2::fill(ic, 0);
        });
    set_intersection(Iter1(ib), Iter1(ib+sb),
                     Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).check([&](OutIter ce)
        {
            CHECK((base(ce) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
            stl2::fill(ic, 0);
        });
}
void
test()
{
    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
    const int sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {2, 4, 4, 6};
    const int sb = sizeof(ib)/sizeof(ib[0]);
    int ic[20];
    int ir[] = {1, 2, 3, 3, 3, 4, 4, 6};
    const int sr = sizeof(ir)/sizeof(ir[0]);
    OutIter ce = std::set_symmetric_difference(Iter1(ia), Iter1(ia+sa),
                                               Iter2(ib), Iter2(ib+sb), OutIter(ic));
    assert(base(ce) - ic == sr);
    assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
    ce = std::set_symmetric_difference(Iter1(ib), Iter1(ib+sb),
                                       Iter2(ia), Iter2(ia+sa), OutIter(ic));
    assert(base(ce) - ic == sr);
    assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
}
Ejemplo n.º 10
0
void
test()
{
    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};
    OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib));
    assert(base(r) == ib + s);
    for (unsigned i = 0; i < s; ++i)
        assert(ib[i] == ir[i]);
}
Ejemplo n.º 11
0
void
test1()
{
    const unsigned N = 100;
    std::unique_ptr<int> ia[N];
    for (unsigned i = 0; i < N; ++i)
        ia[i].reset(new int(i));
    std::unique_ptr<int> ib[N];

    OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
    assert(base(r) == ib);
    for (unsigned i = 0; i < N; ++i)
        assert(*ib[i] == i);
}
Ejemplo n.º 12
0
void test_iter()
{
    int ia[] = {0, 1, 2, 3, 4};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa] = {0};
    std::pair<InIter, OutIter> r = ranges::replace_copy(InIter(ia), Sent(ia+sa), OutIter(ib), 2, 5);
    CHECK(base(r.first) == ia + sa);
    CHECK(base(r.second) == ib + sa);
    CHECK(ib[0] == 0);
    CHECK(ib[1] == 1);
    CHECK(ib[2] == 5);
    CHECK(ib[3] == 3);
    CHECK(ib[4] == 4);
}
Ejemplo n.º 13
0
void
test()
{
    int ia[] = {0, 1, 2, 3, 4};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa] = {0};
    OutIter r = std::replace_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2, 5);
    assert(base(r) == ib + sa);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 5);
    assert(ib[3] == 3);
    assert(ib[4] == 4);
}
Ejemplo n.º 14
0
void
test()
{
    const unsigned N = 1000;
    int ia[N];
    for (unsigned i = 0; i < N; ++i)
        ia[i] = i;
    int ib[N] = {0};

    OutIter r = std::copy_if(InIter(ia), InIter(ia+N), OutIter(ib), Pred());
    assert(base(r) == ib+N/3+1);
    for (unsigned i = 0; i < N/3+1; ++i)
        assert(ib[i] % 3 == 0);
}
Ejemplo n.º 15
0
void
test()
{
    const unsigned N = 1000;
    int ia[N];
    for (unsigned i = 0; i < N; ++i)
        ia[i] = i;
    int ib[N] = {0};

    OutIter r = std::copy_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
    assert(base(r) == ib);
    for (unsigned i = 0; i < N; ++i)
        assert(ia[i] == ib[i]);
}
Ejemplo n.º 16
0
void
test()
{
    int ia[] = {0, 1, 2, 3, 4};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa] = {1, 2, 3, 4, 5};
    OutIter r = std::transform(InIter1(ib), InIter1(ib+sa), InIter2(ia),
                               OutIter(ib), std::minus<int>());
    assert(base(r) == ib + sa);
    assert(ib[0] == 1);
    assert(ib[1] == 1);
    assert(ib[2] == 1);
    assert(ib[3] == 1);
    assert(ib[4] == 1);
}
Ejemplo n.º 17
0
void
test_iter()
{
    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
    const int sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {2, 4, 4, 6};
    const int sb = sizeof(ib)/sizeof(ib[0]);
    int ic[20];
    int ir[] = {1, 2, 3, 3, 3, 4, 4};
    const int sr = sizeof(ir)/sizeof(ir[0]);

    auto set_difference = ::make_testable_2<false, true>([](auto&&...args) {
        return stl2::set_difference(stl2::forward<decltype(args)>(args)...);
    });

    set_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)).
        check([&](std::pair<Iter1, OutIter> res)
        {
            CHECK((base(res.first) - ia) == sa);
            CHECK((base(res.second) - ic) == sr);
            CHECK(std::lexicographical_compare(ic, base(res.second), ir, ir+sr) == 0);
            stl2::fill(ic, 0);
        }
    );
    int irr[] = {6};
    const int srr = sizeof(irr)/sizeof(irr[0]);
    set_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)).
        check([&](std::pair<Iter1, OutIter> res)
        {
            CHECK((base(res.first) - ib) == sb);
            CHECK((base(res.second) - ic) == srr);
            CHECK(std::lexicographical_compare(ic, base(res.second), irr, irr+srr) == 0);
            stl2::fill(ic, 0);
        }
    );
}
Ejemplo n.º 18
0
void test_rng()
{
    int ia[] = {0, 1, 2, 3, 4};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa] = {0};
    auto rng = ranges::make_iterator_range(InIter(ia), Sent(ia+sa));
    std::pair<InIter, OutIter> r = ranges::replace_copy_if(rng, OutIter(ib),
        [](int i){return 2==i;}, 5);
    CHECK(base(r.first) == ia + sa);
    CHECK(base(r.second) == ib + sa);
    CHECK(ib[0] == 0);
    CHECK(ib[1] == 1);
    CHECK(ib[2] == 5);
    CHECK(ib[3] == 3);
    CHECK(ib[4] == 4);
}
Ejemplo n.º 19
0
void
test()
{
    int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa];
    OutIter r = std::remove_copy_if(InIter(ia), InIter(ia+sa),
                                    OutIter(ib), equalToTwo);
    assert(base(r) == ib + sa-3);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 3);
    assert(ib[3] == 4);
    assert(ib[4] == 3);
    assert(ib[5] == 4);
}
Ejemplo n.º 20
0
void
test_iter()
{
    int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
    constexpr unsigned sa = ranges::size(ia);
    int ib[sa];
    std::pair<InIter, OutIter> r = ranges::remove_copy_if(InIter(ia), Sent(ia+sa), OutIter(ib), [](int i){return i == 2;});
    CHECK(base(r.first) == ia + sa);
    CHECK(base(r.second) == ib + sa-3);
    CHECK(ib[0] == 0);
    CHECK(ib[1] == 1);
    CHECK(ib[2] == 3);
    CHECK(ib[3] == 4);
    CHECK(ib[4] == 3);
    CHECK(ib[5] == 4);
}
Ejemplo n.º 21
0
void test_iter() {
	const int ia[] = {0};
	const unsigned sa = sizeof(ia)/sizeof(ia[0]);
	int ja[sa] = {-1};
	count_equal::count = 0;
	ranges::unique_copy_result<InIter, OutIter> r =
		ranges::unique_copy(InIter(ia), Sent(ia+sa), OutIter(ja), count_equal());
	CHECK(base(r.in) == ia + sa);
	CHECK(base(r.out) == ja + sa);
	CHECK(ja[0] == 0);
	CHECK(count_equal::count == sa - 1);

	const int ib[] = {0, 1};
	const unsigned sb = sizeof(ib)/sizeof(ib[0]);
	int jb[sb] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ib), Sent(ib+sb), OutIter(jb), count_equal());
	CHECK(base(r.in) == ib + sb);
	CHECK(base(r.out) == jb + sb);
	CHECK(jb[0] == 0);
	CHECK(jb[1] == 1);
	CHECK(count_equal::count == sb - 1);

	const int ic[] = {0, 0};
	const unsigned sc = sizeof(ic)/sizeof(ic[0]);
	int jc[sc] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ic), Sent(ic+sc), OutIter(jc), count_equal());
	CHECK(base(r.in) == ic + sc);
	CHECK(base(r.out) == jc + 1);
	CHECK(jc[0] == 0);
	CHECK(count_equal::count == sc - 1);

	const int id[] = {0, 0, 1};
	const unsigned sd = sizeof(id)/sizeof(id[0]);
	int jd[sd] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(id), Sent(id+sd), OutIter(jd), count_equal());
	CHECK(base(r.in) == id + sd);
	CHECK(base(r.out) == jd + 2);
	CHECK(jd[0] == 0);
	CHECK(jd[1] == 1);
	CHECK(count_equal::count == sd - 1);

	const int ie[] = {0, 0, 1, 0};
	const unsigned se = sizeof(ie)/sizeof(ie[0]);
	int je[se] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ie), Sent(ie+se), OutIter(je), count_equal());
	CHECK(base(r.in) == ie + se);
	CHECK(base(r.out) == je + 3);
	CHECK(je[0] == 0);
	CHECK(je[1] == 1);
	CHECK(je[2] == 0);
	CHECK(count_equal::count == se - 1);

	const int ig[] = {0, 0, 1, 1};
	const unsigned sg = sizeof(ig)/sizeof(ig[0]);
	int jg[sg] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ig), Sent(ig+sg), OutIter(jg), count_equal());
	CHECK(base(r.in) == ig + sg);
	CHECK(base(r.out) == jg + 2);
	CHECK(jg[0] == 0);
	CHECK(jg[1] == 1);
	CHECK(count_equal::count == sg - 1);

	const int ih[] = {0, 1, 1};
	const unsigned sh = sizeof(ih)/sizeof(ih[0]);
	int jh[sh] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ih), Sent(ih+sh), OutIter(jh), count_equal());
	CHECK(base(r.in) == ih + sh);
	CHECK(base(r.out) == jh + 2);
	CHECK(jh[0] == 0);
	CHECK(jh[1] == 1);
	CHECK(count_equal::count == sh - 1);

	const int ii[] = {0, 1, 1, 1, 2, 2, 2};
	const unsigned si = sizeof(ii)/sizeof(ii[0]);
	int ji[si] = {-1};
	count_equal::count = 0;
	r = ranges::unique_copy(InIter(ii), Sent(ii+si), OutIter(ji), count_equal());
	CHECK(base(r.in) == ii + si);
	CHECK(base(r.out) == ji + 3);
	CHECK(ji[0] == 0);
	CHECK(ji[1] == 1);
	CHECK(ji[2] == 2);
	CHECK(count_equal::count == si - 1);
}
Ejemplo n.º 22
0
void test()
{
    using P = std::pair<Iter, OutIter>;
    // iterators
    {
        const int ia[] = {0};
        const unsigned sa = sizeof(ia)/sizeof(ia[0]);
        int ja[sa] = {-1};
        P p0 = ranges::reverse_copy(Iter(ia), Sent(ia), OutIter(ja));
        ::check_equal(ja, {-1});
        CHECK(p0.first == Iter(ia));
        CHECK(base(p0.second) == ja);
        P p1 = ranges::reverse_copy(Iter(ia), Sent(ia+sa), OutIter(ja));
        ::check_equal(ja, {0});
        CHECK(p1.first == Iter(ia+sa));
        CHECK(base(p1.second) == ja+sa);

        const int ib[] = {0, 1};
        const unsigned sb = sizeof(ib)/sizeof(ib[0]);
        int jb[sb] = {-1};
        P p2 = ranges::reverse_copy(Iter(ib), Sent(ib+sb), OutIter(jb));
        ::check_equal(jb, {1, 0});
        CHECK(p2.first == Iter(ib+sb));
        CHECK(base(p2.second) == jb+sb);

        const int ic[] = {0, 1, 2};
        const unsigned sc = sizeof(ic)/sizeof(ic[0]);
        int jc[sc] = {-1};
        P p3 = ranges::reverse_copy(Iter(ic), Sent(ic+sc), OutIter(jc));
        ::check_equal(jc, {2, 1, 0});
        CHECK(p3.first == Iter(ic+sc));
        CHECK(base(p3.second) == jc+sc);

        const int id[] = {0, 1, 2, 3};
        const unsigned sd = sizeof(id)/sizeof(id[0]);
        int jd[sd] = {-1};
        P p4 = ranges::reverse_copy(Iter(id), Sent(id+sd), OutIter(jd));
        ::check_equal(jd, {3, 2, 1, 0});
        CHECK(p4.first == Iter(id+sd));
        CHECK(base(p4.second) == jd+sd);
    }

    // ranges
    {
        const int ia[] = {0};
        const unsigned sa = sizeof(ia)/sizeof(ia[0]);
        int ja[sa] = {-1};
        P p0 = ranges::reverse_copy(::as_lvalue(ranges::make_range(Iter(ia), Sent(ia))), OutIter(ja));
        ::check_equal(ja, {-1});
        CHECK(p0.first == Iter(ia));
        CHECK(base(p0.second) == ja);
        P p1 = ranges::reverse_copy(::as_lvalue(ranges::make_range(Iter(ia), Sent(ia+sa))), OutIter(ja));
        ::check_equal(ja, {0});
        CHECK(p1.first == Iter(ia+sa));
        CHECK(base(p1.second) == ja+sa);

        const int ib[] = {0, 1};
        const unsigned sb = sizeof(ib)/sizeof(ib[0]);
        int jb[sb] = {-1};
        P p2 = ranges::reverse_copy(::as_lvalue(ranges::make_range(Iter(ib), Sent(ib+sb))), OutIter(jb));
        ::check_equal(jb, {1, 0});
        CHECK(p2.first == Iter(ib+sb));
        CHECK(base(p2.second) == jb+sb);

        const int ic[] = {0, 1, 2};
        const unsigned sc = sizeof(ic)/sizeof(ic[0]);
        int jc[sc] = {-1};
        P p3 = ranges::reverse_copy(::as_lvalue(ranges::make_range(Iter(ic), Sent(ic+sc))), OutIter(jc));
        ::check_equal(jc, {2, 1, 0});
        CHECK(p3.first == Iter(ic+sc));
        CHECK(base(p3.second) == jc+sc);

        const int id[] = {0, 1, 2, 3};
        const unsigned sd = sizeof(id)/sizeof(id[0]);
        int jd[sd] = {-1};
        P p4 = ranges::reverse_copy(::as_lvalue(ranges::make_range(Iter(id), Sent(id+sd))), OutIter(jd));
        ::check_equal(jd, {3, 2, 1, 0});
        CHECK(p4.first == Iter(id+sd));
        CHECK(base(p4.second) == jd+sd);

        // test rvalue ranges
        std::memset(jd, 0, sizeof(jd));
        auto p5 = ranges::reverse_copy(ranges::make_range(Iter(id), Sent(id+sd)), OutIter(jd));
        ::check_equal(jd, {3, 2, 1, 0});
        CHECK(p5.first.get_unsafe() == Iter(id+sd));
        CHECK(base(p4.second) == jd+sd);
    }
}
Ejemplo n.º 23
0
void
test()
{
    int ia[] = {0, 1, 2, 3};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[sa] = {0};

    OutIter r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia), OutIter(ib));
    assert(base(r) == ib);

    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+1), OutIter(ib));
    assert(base(r) == ib+1);
    assert(ib[0] == 0);

    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+1), OutIter(ib));
    assert(base(r) == ib+1);
    assert(ib[0] == 0);

    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+2), OutIter(ib));
    assert(base(r) == ib+2);
    assert(ib[0] == 0);
    assert(ib[1] == 1);

    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+2), OutIter(ib));
    assert(base(r) == ib+2);
    assert(ib[0] == 1);
    assert(ib[1] == 0);

    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+2), OutIter(ib));
    assert(base(r) == ib+2);
    assert(ib[0] == 0);
    assert(ib[1] == 1);

    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+3), OutIter(ib));
    assert(base(r) == ib+3);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 2);

    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+3), OutIter(ib));
    assert(base(r) == ib+3);
    assert(ib[0] == 1);
    assert(ib[1] == 2);
    assert(ib[2] == 0);

    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+3), OutIter(ib));
    assert(base(r) == ib+3);
    assert(ib[0] == 2);
    assert(ib[1] == 0);
    assert(ib[2] == 1);

    r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+3), OutIter(ib));
    assert(base(r) == ib+3);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 2);

    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+4), OutIter(ib));
    assert(base(r) == ib+4);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 2);
    assert(ib[3] == 3);

    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+4), OutIter(ib));
    assert(base(r) == ib+4);
    assert(ib[0] == 1);
    assert(ib[1] == 2);
    assert(ib[2] == 3);
    assert(ib[3] == 0);

    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+4), OutIter(ib));
    assert(base(r) == ib+4);
    assert(ib[0] == 2);
    assert(ib[1] == 3);
    assert(ib[2] == 0);
    assert(ib[3] == 1);

    r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+4), OutIter(ib));
    assert(base(r) == ib+4);
    assert(ib[0] == 3);
    assert(ib[1] == 0);
    assert(ib[2] == 1);
    assert(ib[3] == 2);

    r = std::rotate_copy(InIter(ia), InIter(ia+4), InIter(ia+4), OutIter(ib));
    assert(base(r) == ib+4);
    assert(ib[0] == 0);
    assert(ib[1] == 1);
    assert(ib[2] == 2);
    assert(ib[3] == 3);
}