2 //===-- search_n.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
;
21 struct test_one_policy
23 #if defined(_PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) || \
24 defined(_PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) //dummy specialization by policy type, in case of broken configuration
25 template <typename Iterator
, typename Size
, typename T
, typename Predicate
>
27 operator()(pstl::execution::unsequenced_policy
, Iterator b
, Iterator e
, Size count
, const T
& value
, Predicate pred
)
30 template <typename Iterator
, typename Size
, typename T
, typename Predicate
>
32 operator()(pstl::execution::parallel_unsequenced_policy
, Iterator b
, Iterator e
, Size count
, const T
& value
,
38 template <typename ExecutionPolicy
, typename Iterator
, typename Size
, typename T
, typename Predicate
>
40 operator()(ExecutionPolicy
&& exec
, Iterator b
, Iterator e
, Size count
, const T
& value
, Predicate pred
)
43 auto expected
= search_n(b
, e
, count
, value
, pred
);
44 auto actual
= search_n(exec
, b
, e
, count
, value
);
45 EXPECT_TRUE(actual
== expected
, "wrong return result from search_n");
47 actual
= search_n(exec
, b
, e
, count
, value
, pred
);
48 EXPECT_TRUE(actual
== expected
, "wrong return result from search_n with a predicate");
57 const std::size_t max_n1
= 100000;
59 for (std::size_t n1
= 0; n1
<= max_n1
; n1
= n1
<= 16 ? n1
+ 1 : size_t(3.1415 * n1
))
61 std::size_t sub_n
[] = {0, 1, 3, n1
, (n1
* 10) / 8};
62 std::size_t res
[] = {0, 1, n1
/ 2, n1
};
65 // Some of standard libraries return "first" in this case. We return "last" according to the standard
72 Sequence
<T
> in(n1
, [](std::size_t) { return T(0); });
73 std::size_t i
= r
, isub
= 0;
74 for (; i
< n1
&& isub
< n2
; ++i
, ++isub
)
77 invoke_on_all_policies(test_one_policy(), in
.begin(), in
.begin() + n1
, n2
, value
, std::equal_to
<T
>());
78 invoke_on_all_policies(test_one_policy(), in
.cbegin(), in
.cbegin() + n1
, n2
, value
, std::equal_to
<T
>());
87 template <typename Policy
, typename Iterator
>
89 operator()(Policy
&& exec
, Iterator iter
)
91 invoke_if(exec
, [&]() { search_n(exec
, iter
, iter
, 0, T(0), non_const(std::equal_to
<T
>())); });
101 #if !defined(_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN)
105 test_algo_basic_single
<int32_t>(run_for_rnd_fw
<test_non_const
<int32_t>>());
107 std::cout
<< done() << std::endl
;