// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include #include #include #include #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION namespace { std::mt19937 gen; template void test_one_iter(unsigned N, unsigned M) { RANGES_ENSURE(M <= N); int* ia = new int[N]; for (unsigned i = 0; i < N; ++i) ia[i] = i; std::shuffle(ia, ia+N, gen); std::sort(ia, ia+M); std::sort(ia+M, ia+N); auto res = ranges::inplace_merge(Iter(ia), Iter(ia+M), Sent(ia+N)); CHECK(res == Iter(ia+N)); if(N > 0) { CHECK(ia[0] == 0); CHECK(ia[N-1] == (int)N-1); CHECK(std::is_sorted(ia, ia+N)); } delete [] ia; } template void test_one_rng(unsigned N, unsigned M) { RANGES_ENSURE(M <= N); int* ia = new int[N]; for (unsigned i = 0; i < N; ++i) ia[i] = i; std::shuffle(ia, ia+N, gen); std::sort(ia, ia+M); std::sort(ia+M, ia+N); auto res = ranges::inplace_merge(ranges::make_subrange(Iter(ia), Sent(ia+N)), Iter(ia+M)); CHECK(res == Iter(ia+N)); if(N > 0) { CHECK(ia[0] == 0); CHECK(ia[N-1] == (int)N-1); CHECK(std::is_sorted(ia, ia+N)); } std::shuffle(ia, ia+N, gen); std::sort(ia, ia+M); std::sort(ia+M, ia+N); auto res2 = ranges::inplace_merge(::MakeTestRange(Iter(ia), Sent(ia+N)), Iter(ia+M)); CHECK(::is_dangling(res2)); if(N > 0) { CHECK(ia[0] == 0); CHECK(ia[N-1] == (int)N-1); CHECK(std::is_sorted(ia, ia+N)); } delete [] ia; } template void test_one(unsigned N, unsigned M) { test_one_iter(N, M); test_one_iter::type>(N, M); test_one_rng(N, M); test_one_rng::type>(N, M); } template void test(unsigned N) { test_one(N, 0); test_one(N, N/4); test_one(N, N/2); test_one(N, 3*N/4); test_one(N, N); } template void test() { test_one(0, 0); test_one(1, 0); test_one(1, 1); test_one(2, 0); test_one(2, 1); test_one(2, 2); test_one(3, 0); test_one(3, 1); test_one(3, 2); test_one(3, 3); test(4); test(100); test(1000); } } int main() { // test >(); test >(); test >(); test(); return ::test_result(); }