2 //===-- mismatch.pass.cpp -------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 #include "support/pstl_test_config.h"
17 #include "support/utils.h"
19 using namespace TestUtils
;
23 template <typename Policy
, typename Iterator1
, typename Iterator2
>
25 operator()(Policy
&& exec
, Iterator1 first1
, Iterator1 last1
, Iterator2 first2
)
28 typedef typename iterator_traits
<Iterator1
>::value_type T
;
30 const auto expected
= std::mismatch(first1
, last1
, first2
, std::equal_to
<T
>());
31 const auto res3
= mismatch(exec
, first1
, last1
, first2
, std::equal_to
<T
>());
32 EXPECT_TRUE(expected
== res3
, "wrong return result from mismatch");
33 const auto res4
= mismatch(exec
, first1
, last1
, first2
);
34 EXPECT_TRUE(expected
== res4
, "wrong return result from mismatch");
37 template <typename Policy
, typename Iterator1
, typename Iterator2
>
39 operator()(Policy
&& exec
, Iterator1 first1
, Iterator1 last1
, Iterator2 first2
, Iterator2 last2
)
42 typedef typename iterator_traits
<Iterator1
>::value_type T
;
44 const auto expected
= mismatch(std::execution::seq
, first1
, last1
, first2
, last2
, std::equal_to
<T
>());
45 const auto res1
= mismatch(exec
, first1
, last1
, first2
, last2
, std::equal_to
<T
>());
46 EXPECT_TRUE(expected
== res1
, "wrong return result from mismatch");
47 const auto res2
= mismatch(exec
, first1
, last1
, first2
, last2
);
48 EXPECT_TRUE(expected
== res2
, "wrong return result from mismatch");
55 test_mismatch_by_type()
58 for (size_t size
= 0; size
<= 100000; size
= size
<= 16 ? size
+ 1 : size_t(3.1415 * size
))
61 Sequence
<T
> in(size
, [](size_t v
) -> T
{ return T(v
% 100); });
64 invoke_on_all_policies(test_mismatch(), in
.begin(), in
.end(), in2
.begin(), in2
.end());
65 invoke_on_all_policies(test_mismatch(), in
.begin(), in
.end(), in2
.begin());
67 const size_t min_size
= 3;
70 const size_t idx_for_1
= size
/ min_size
;
71 in
[idx_for_1
] = val
, in
[idx_for_1
+ 1] = val
, in
[idx_for_1
+ 2] = val
;
72 invoke_on_all_policies(test_mismatch(), in
.begin(), in
.end(), in2
.begin(), in2
.end());
73 invoke_on_all_policies(test_mismatch(), in
.begin(), in
.end(), in2
.begin());
76 const size_t idx_for_2
= 500;
77 if (size
>= idx_for_2
- 1)
79 in2
[size
/ idx_for_2
] = val
;
80 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin(), in2
.cend());
81 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin());
85 Sequence
<T
> in2(100, [](size_t v
) -> T
{ return T(v
); });
86 invoke_on_all_policies(test_mismatch(), in2
.begin(), in2
.end(), in
.begin(), in
.end());
87 // We can't call std::mismatch with semantic below when size of second sequence less than size of first sequence
88 if (in2
.size() <= in
.size())
89 invoke_on_all_policies(test_mismatch(), in2
.begin(), in2
.end(), in
.begin());
91 const size_t idx
= 97;
94 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin(), in2
.cend());
95 if (in
.size() <= in2
.size())
96 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin());
100 invoke_on_all_policies(test_mismatch(), in2
.begin(), in2
.end(), in
.begin(), in
.end());
102 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin(), in2
.cend());
104 invoke_on_all_policies(test_mismatch(), in
.cbegin(), in
.cend(), in2
.cbegin());
109 template <typename T
>
110 struct test_non_const
112 template <typename Policy
, typename FirstIterator
, typename SecondInterator
>
114 operator()(Policy
&& exec
, FirstIterator first_iter
, SecondInterator second_iter
)
116 mismatch(exec
, first_iter
, first_iter
, second_iter
, second_iter
, non_const(std::less
<T
>()));
124 test_mismatch_by_type
<int32_t>();
125 test_mismatch_by_type
<float64_t
>();
126 test_mismatch_by_type
<Wrapper
<int32_t>>();
128 test_algo_basic_double
<int32_t>(run_for_rnd_fw
<test_non_const
<int32_t>>());
130 std::cout
<< done() << std::endl
;