コード例 #1
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);
}
コード例 #2
0
ファイル: merge_comp.pass.cpp プロジェクト: themiwi/libcxx
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;
    }
}