1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template<InputIterator InIter1, InputIterator InIter2, typename OutIter>
12 // requires OutputIterator<OutIter, InIter1::reference>
13 // && OutputIterator<OutIter, InIter2::reference>
14 // && HasLess<InIter2::value_type, InIter1::value_type>
15 // && HasLess<InIter1::value_type, InIter2::value_type>
16 // constexpr OutIter // constexpr after C++17
17 // merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
23 #include "test_macros.h"
24 #include "test_iterators.h"
25 #include "../sortable_helpers.h"
27 template<class T
, class Iter1
, class Iter2
, class OutIter
>
28 TEST_CONSTEXPR_CXX20
void test4()
30 const T a
[] = {11, 33, 31, 41};
31 const T b
[] = {22, 32, 43, 42, 52};
34 T expected
[] = {11, 22, 33, 31, 32, 41, 43, 42, 52};
35 OutIter end
= std::merge(Iter1(a
), Iter1(a
+4), Iter2(b
), Iter2(b
+5), OutIter(result
));
36 assert(std::lexicographical_compare(result
, base(end
), expected
, expected
+9, T::less
) == 0);
37 for (const T
*it
= base(end
); it
!= result
+20; ++it
) {
38 assert(it
->value
== 0);
43 T expected
[] = {11, 22, 32, 33, 31, 43, 42, 41, 52};
44 OutIter end
= std::merge(Iter1(b
), Iter1(b
+5), Iter2(a
), Iter2(a
+4), OutIter(result
));
45 assert(std::lexicographical_compare(result
, base(end
), expected
, expected
+9, T::less
) == 0);
46 for (const T
*it
= base(end
); it
!= result
+20; ++it
) {
47 assert(it
->value
== 0);
52 template<class T
, class Iter1
, class Iter2
>
53 TEST_CONSTEXPR_CXX20
void test3()
55 test4
<T
, Iter1
, Iter2
, cpp17_output_iterator
<T
*> >();
56 test4
<T
, Iter1
, Iter2
, forward_iterator
<T
*> >();
57 test4
<T
, Iter1
, Iter2
, bidirectional_iterator
<T
*> >();
58 test4
<T
, Iter1
, Iter2
, random_access_iterator
<T
*> >();
59 test4
<T
, Iter1
, Iter2
, T
*>();
62 template<class T
, class Iter1
>
63 TEST_CONSTEXPR_CXX20
void test2()
65 test3
<T
, Iter1
, cpp17_input_iterator
<const T
*> >();
66 test3
<T
, Iter1
, forward_iterator
<const T
*> >();
67 test3
<T
, Iter1
, bidirectional_iterator
<const T
*> >();
68 test3
<T
, Iter1
, random_access_iterator
<const T
*> >();
69 test3
<T
, Iter1
, const T
*>();
73 TEST_CONSTEXPR_CXX20
void test1()
75 test2
<T
, cpp17_input_iterator
<const T
*> >();
76 test2
<T
, forward_iterator
<const T
*> >();
77 test2
<T
, bidirectional_iterator
<const T
*> >();
78 test2
<T
, random_access_iterator
<const T
*> >();
82 TEST_CONSTEXPR_CXX20
bool test()
84 test1
<TrivialSortable
>();
85 test1
<NonTrivialSortable
>();
93 static_assert(test());