//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template // requires OutputIterator // && OutputIterator // && HasLess // OutIter // merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, OutIter result); #include #include #include "../../iterators.h" template 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; OutIter r = std::merge(InIter1(ia), InIter1(ia+N), InIter2(ib), InIter2(ib+N), OutIter(ic)); assert(base(r) == ic+2*N); assert(ic[0] == 0); assert(ic[2*N-1] == 2*N-1); assert(std::is_sorted(ic, ic+2*N)); 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::sort(ib, ib+N); OutIter r = std::merge(InIter1(ia), InIter1(ia+N), InIter2(ib), InIter2(ib+N), OutIter(ic)); assert(base(r) == ic+2*N); assert(ic[0] == 0); assert(ic[2*N-1] == 2*N-1); assert(std::is_sorted(ic, ic+2*N)); delete [] ic; delete [] ib; delete [] ia; } } int main() { test, input_iterator, output_iterator >(); test, input_iterator, forward_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, random_access_iterator >(); test, input_iterator, int*>(); test, forward_iterator, output_iterator >(); test, forward_iterator, forward_iterator >(); test, forward_iterator, bidirectional_iterator >(); test, forward_iterator, random_access_iterator >(); test, forward_iterator, int*>(); test, bidirectional_iterator, output_iterator >(); test, bidirectional_iterator, forward_iterator >(); test, bidirectional_iterator, bidirectional_iterator >(); test, bidirectional_iterator, random_access_iterator >(); test, bidirectional_iterator, int*>(); test, random_access_iterator, output_iterator >(); test, random_access_iterator, forward_iterator >(); test, random_access_iterator, bidirectional_iterator >(); test, random_access_iterator, random_access_iterator >(); test, random_access_iterator, int*>(); test, const int*, output_iterator >(); test, const int*, forward_iterator >(); test, const int*, bidirectional_iterator >(); test, const int*, random_access_iterator >(); test, const int*, int*>(); test, input_iterator, output_iterator >(); test, input_iterator, forward_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, random_access_iterator >(); test, input_iterator, int*>(); test, forward_iterator, output_iterator >(); test, forward_iterator, forward_iterator >(); test, forward_iterator, bidirectional_iterator >(); test, forward_iterator, random_access_iterator >(); test, forward_iterator, int*>(); test, bidirectional_iterator, output_iterator >(); test, bidirectional_iterator, forward_iterator >(); test, bidirectional_iterator, bidirectional_iterator >(); test, bidirectional_iterator, random_access_iterator >(); test, bidirectional_iterator, int*>(); test, random_access_iterator, output_iterator >(); test, random_access_iterator, forward_iterator >(); test, random_access_iterator, bidirectional_iterator >(); test, random_access_iterator, random_access_iterator >(); test, random_access_iterator, int*>(); test, const int*, output_iterator >(); test, const int*, forward_iterator >(); test, const int*, bidirectional_iterator >(); test, const int*, random_access_iterator >(); test, const int*, int*>(); test, input_iterator, output_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, random_access_iterator >(); test, input_iterator, int*>(); test, forward_iterator, output_iterator >(); test, forward_iterator, forward_iterator >(); test, forward_iterator, bidirectional_iterator >(); test, forward_iterator, random_access_iterator >(); test, forward_iterator, int*>(); test, bidirectional_iterator, output_iterator >(); test, bidirectional_iterator, forward_iterator >(); test, bidirectional_iterator, bidirectional_iterator >(); test, bidirectional_iterator, random_access_iterator >(); test, bidirectional_iterator, int*>(); test, random_access_iterator, output_iterator >(); test, random_access_iterator, forward_iterator >(); test, random_access_iterator, bidirectional_iterator >(); test, random_access_iterator, random_access_iterator >(); test, random_access_iterator, int*>(); test, const int*, output_iterator >(); test, const int*, forward_iterator >(); test, const int*, bidirectional_iterator >(); test, const int*, random_access_iterator >(); test, const int*, int*>(); test, input_iterator, output_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, bidirectional_iterator >(); test, input_iterator, random_access_iterator >(); test, input_iterator, int*>(); test, forward_iterator, output_iterator >(); test, forward_iterator, forward_iterator >(); test, forward_iterator, bidirectional_iterator >(); test, forward_iterator, random_access_iterator >(); test, forward_iterator, int*>(); test, bidirectional_iterator, output_iterator >(); test, bidirectional_iterator, forward_iterator >(); test, bidirectional_iterator, bidirectional_iterator >(); test, bidirectional_iterator, random_access_iterator >(); test, bidirectional_iterator, int*>(); test, random_access_iterator, output_iterator >(); test, random_access_iterator, forward_iterator >(); test, random_access_iterator, bidirectional_iterator >(); test, random_access_iterator, random_access_iterator >(); test, random_access_iterator, int*>(); test, const int*, output_iterator >(); test, const int*, forward_iterator >(); test, const int*, bidirectional_iterator >(); test, const int*, random_access_iterator >(); test, const int*, int*>(); test, output_iterator >(); test, bidirectional_iterator >(); test, bidirectional_iterator >(); test, random_access_iterator >(); test, int*>(); test, output_iterator >(); test, forward_iterator >(); test, bidirectional_iterator >(); test, random_access_iterator >(); test, int*>(); test, output_iterator >(); test, forward_iterator >(); test, bidirectional_iterator >(); test, random_access_iterator >(); test, int*>(); test, output_iterator >(); test, forward_iterator >(); test, bidirectional_iterator >(); test, random_access_iterator >(); test, int*>(); test >(); test >(); test >(); test >(); test(); }