2 // { dg-options "-std=gnu++17 -ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-require-effective-target tbb-backend }
6 //===-- remove.pass.cpp ---------------------------------------------------===//
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //===----------------------------------------------------------------------===//
14 // Test for remove, remove_if
15 #include "pstl/pstl_test_config.h"
17 #ifdef PSTL_STANDALONE_TESTS
18 #include "pstl/execution"
19 #include "pstl/algorithm"
23 #endif // PSTL_STANDALONE_TESTS
25 #include "pstl/test_utils.h"
27 using namespace TestUtils
;
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
33 template <typename InputIterator
, typename OutputIterator
, typename Size
, typename T
>
35 operator()(pstl::execution::unsequenced_policy
, InputIterator first
, InputIterator last
, OutputIterator out_first
,
36 OutputIterator out_last
, OutputIterator expected_first
, OutputIterator expected_last
, Size n
,
40 template <typename InputIterator
, typename OutputIterator
, typename Size
, typename T
>
42 operator()(pstl::execution::parallel_unsequenced_policy
, InputIterator first
, InputIterator last
,
43 OutputIterator out_first
, OutputIterator out_last
, OutputIterator expected_first
,
44 OutputIterator expected_last
, Size n
, const T
& value
)
49 template <typename Policy
, typename InputIterator
, typename OutputIterator
, typename Size
, typename T
>
51 operator()(Policy
&& exec
, InputIterator first
, InputIterator last
, OutputIterator out_first
,
52 OutputIterator out_last
, OutputIterator expected_first
, OutputIterator expected_last
, Size
,
56 std::copy(first
, last
, expected_first
);
57 std::copy(first
, last
, out_first
);
60 OutputIterator i
= remove(expected_first
, expected_last
, value
);
61 OutputIterator k
= remove(exec
, out_first
, out_last
, value
);
62 EXPECT_TRUE(std::distance(expected_first
, i
) == std::distance(out_first
, k
), "wrong return value from remove");
63 EXPECT_EQ_N(expected_first
, out_first
, std::distance(expected_first
, i
), "wrong remove effect");
69 #if _PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN || \
70 _PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN //dummy specialization by policy type, in case of broken configuration
71 template <typename InputIterator
, typename OutputIterator
, typename Size
, typename Predicate
>
73 operator()(pstl::execution::unsequenced_policy
, InputIterator first
, InputIterator last
, OutputIterator out_first
,
74 OutputIterator out_last
, OutputIterator expected_first
, OutputIterator expected_last
, Size n
,
78 template <typename InputIterator
, typename OutputIterator
, typename Size
, typename Predicate
>
80 operator()(pstl::execution::parallel_unsequenced_policy
, InputIterator first
, InputIterator last
,
81 OutputIterator out_first
, OutputIterator out_last
, OutputIterator expected_first
,
82 OutputIterator expected_last
, Size n
, Predicate pred
)
87 template <typename Policy
, typename InputIterator
, typename OutputIterator
, typename Size
, typename Predicate
>
89 operator()(Policy
&& exec
, InputIterator first
, InputIterator last
, OutputIterator out_first
,
90 OutputIterator out_last
, OutputIterator expected_first
, OutputIterator expected_last
, Size
,
94 std::copy(first
, last
, expected_first
);
95 std::copy(first
, last
, out_first
);
98 OutputIterator i
= remove_if(expected_first
, expected_last
, pred
);
99 OutputIterator k
= remove_if(exec
, out_first
, out_last
, pred
);
100 EXPECT_TRUE(std::distance(expected_first
, i
) == std::distance(out_first
, k
),
101 "wrong return value from remove_if");
102 EXPECT_EQ_N(expected_first
, out_first
, std::distance(expected_first
, i
), "wrong remove_if effect");
106 template <typename T
, typename Predicate
, typename Convert
>
108 test(T trash
, const T
& value
, Predicate pred
, Convert convert
)
110 const std::size_t max_size
= 100000;
111 Sequence
<T
> out(max_size
, [trash
](size_t) { return trash
; });
112 Sequence
<T
> expected(max_size
, [trash
](size_t) { return trash
; });
114 for (size_t n
= 0; n
<= max_size
; n
= n
<= 16 ? n
+ 1 : size_t(3.1415 * n
))
116 Sequence
<T
> data(n
, [&](size_t k
) -> T
{ return convert(k
); });
118 invoke_on_all_policies(run_remove(), data
.begin(), data
.end(), out
.begin(), out
.begin() + n
, expected
.begin(),
119 expected
.begin() + n
, n
, value
);
120 invoke_on_all_policies(run_remove_if(), data
.begin(), data
.end(), out
.begin(), out
.begin() + n
,
121 expected
.begin(), expected
.begin() + n
, n
, pred
);
125 struct test_non_const
127 template <typename Policy
, typename Iterator
>
129 operator()(Policy
&& exec
, Iterator iter
)
131 auto is_even
= [&](float64_t v
) {
132 uint32_t i
= (uint32_t)v
;
136 invoke_if(exec
, [&]() { remove_if(exec
, iter
, iter
, non_const(is_even
)); });
143 #if !_PSTL_ICC_18_TEST_EARLY_EXIT_MONOTONIC_RELEASE_BROKEN
144 test
<int32_t>(666, 42, [](int32_t val
) { return true; }, [](size_t j
) { return j
; });
147 test
<int32_t>(666, 2001, [](const int32_t& val
) { return val
!= 2001; },
148 [](size_t j
) { return ((j
+ 1) % 5 & 2) != 0 ? 2001 : -1 - int32_t(j
); });
149 test
<float64_t
>(-666.0, 8.5, [](const float64_t
& val
) { return val
!= 8.5; },
150 [](size_t j
) { return ((j
+ 1) % 7 & 2) != 0 ? 8.5 : float64_t(j
% 32 + j
); });
152 #if !_PSTL_ICC_17_TEST_MAC_RELEASE_32_BROKEN
153 test
<Number
>(Number(-666, OddTag()), Number(42, OddTag()), IsMultiple(3, OddTag()),
154 [](int32_t j
) { return Number(j
, OddTag()); });
157 test_algo_basic_single
<int32_t>(run_for_rnd_fw
<test_non_const
>());
159 std::cout
<< done() << std::endl
;