]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc
libstdc++: Set dg-timeout-factor for more slow tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / pstl / alg_nonmodifying / search_n.cc
CommitLineData
061f4578
TR
1// -*- C++ -*-
2// { dg-options "-std=gnu++17 -ltbb" }
3// { dg-do run { target c++17 } }
b6a8e347 4// { dg-timeout-factor 3 }
061f4578
TR
5// { dg-require-effective-target tbb-backend }
6
7//===-- search_n.pass.cpp -------------------------------------------------===//
8//
9// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10// See https://llvm.org/LICENSE.txt for license information.
11// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12//
13//===----------------------------------------------------------------------===//
14
15#include "pstl/pstl_test_config.h"
16
17#ifdef PSTL_STANDALONE_TESTS
18#include "pstl/execution"
19#include "pstl/algorithm"
20#else
21#include <execution>
22#include <algorithm>
23#endif // PSTL_STANDALONE_TESTS
24
25#include "pstl/test_utils.h"
26
27using namespace TestUtils;
28
29struct test_one_policy
30{
f32ee8a2
TR
31#if _PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN || \
32 _PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN //dummy specialization by policy type, in case of broken configuration
061f4578
TR
33 template <typename Iterator, typename Size, typename T, typename Predicate>
34 void
35 operator()(pstl::execution::unsequenced_policy, Iterator b, Iterator e, Size count, const T& value, Predicate pred)
36 {
37 }
38 template <typename Iterator, typename Size, typename T, typename Predicate>
39 void
40 operator()(pstl::execution::parallel_unsequenced_policy, Iterator b, Iterator e, Size count, const T& value,
41 Predicate pred)
42 {
43 }
44#endif
45
46 template <typename ExecutionPolicy, typename Iterator, typename Size, typename T, typename Predicate>
47 void
48 operator()(ExecutionPolicy&& exec, Iterator b, Iterator e, Size count, const T& value, Predicate pred)
49 {
50 using namespace std;
51 auto expected = search_n(b, e, count, value, pred);
52 auto actual = search_n(exec, b, e, count, value);
53 EXPECT_TRUE(actual == expected, "wrong return result from search_n");
54
55 actual = search_n(exec, b, e, count, value, pred);
56 EXPECT_TRUE(actual == expected, "wrong return result from search_n with a predicate");
57 }
58};
59
60template <typename T>
61void
62test()
63{
64
65 const std::size_t max_n1 = 100000;
66 const T value = T(1);
67 for (std::size_t n1 = 0; n1 <= max_n1; n1 = n1 <= 16 ? n1 + 1 : size_t(3.1415 * n1))
68 {
69 std::size_t sub_n[] = {0, 1, 3, n1, (n1 * 10) / 8};
70 std::size_t res[] = {0, 1, n1 / 2, n1};
71 for (auto n2 : sub_n)
72 {
73 // Some of standard libraries return "first" in this case. We return "last" according to the standard
74 if (n2 == 0)
75 {
76 continue;
77 }
78 for (auto r : res)
79 {
80 Sequence<T> in(n1, [n1](std::size_t k) { return T(0); });
81 std::size_t i = r, isub = 0;
82 for (; i < n1 & isub < n2; ++i, ++isub)
83 in[i] = value;
84
85 invoke_on_all_policies(test_one_policy(), in.begin(), in.begin() + n1, n2, value, std::equal_to<T>());
86 invoke_on_all_policies(test_one_policy(), in.cbegin(), in.cbegin() + n1, n2, value, std::equal_to<T>());
87 }
88 }
89 }
90}
91
92template <typename T>
93struct test_non_const
94{
95 template <typename Policy, typename Iterator>
96 void
97 operator()(Policy&& exec, Iterator iter)
98 {
99 invoke_if(exec, [&]() { search_n(exec, iter, iter, 0, T(0), non_const(std::equal_to<T>())); });
100 }
101};
102
103int32_t
104main()
105{
106 test<int32_t>();
107 test<uint16_t>();
108 test<float64_t>();
f32ee8a2 109#if !_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN
061f4578
TR
110 test<bool>();
111#endif
112
113 test_algo_basic_single<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
114
115 std::cout << done() << std::endl;
116 return 0;
117}