//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // template // requires OutputIterator // && OutputIterator // && HasLess // && HasLess // constexpr OutIter // constexpr after C++17 // merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, // OutIter result); #include #include #include "test_macros.h" #include "test_iterators.h" #include "../sortable_helpers.h" template TEST_CONSTEXPR_CXX20 void test4() { const T a[] = {11, 33, 31, 41}; const T b[] = {22, 32, 43, 42, 52}; { T result[20] = {}; T expected[] = {11, 22, 33, 31, 32, 41, 43, 42, 52}; OutIter end = std::merge(Iter1(a), Iter1(a+4), Iter2(b), Iter2(b+5), OutIter(result)); assert(std::lexicographical_compare(result, base(end), expected, expected+9, T::less) == 0); for (const T *it = base(end); it != result+20; ++it) { assert(it->value == 0); } } { T result[20] = {}; T expected[] = {11, 22, 32, 33, 31, 43, 42, 41, 52}; OutIter end = std::merge(Iter1(b), Iter1(b+5), Iter2(a), Iter2(a+4), OutIter(result)); assert(std::lexicographical_compare(result, base(end), expected, expected+9, T::less) == 0); for (const T *it = base(end); it != result+20; ++it) { assert(it->value == 0); } } } template TEST_CONSTEXPR_CXX20 void test3() { test4 >(); test4 >(); test4 >(); test4 >(); test4(); } template TEST_CONSTEXPR_CXX20 void test2() { test3 >(); test3 >(); test3 >(); test3 >(); test3(); } template TEST_CONSTEXPR_CXX20 void test1() { test2 >(); test2 >(); test2 >(); test2 >(); test2(); } TEST_CONSTEXPR_CXX20 bool test() { test1(); test1(); return true; } int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); #endif return 0; }