2 //===-- transform_unary.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 template <typename InputIterator
, typename OutputIterator
>
23 check_and_reset(InputIterator first
, InputIterator last
, OutputIterator out_first
)
25 typedef typename
std::iterator_traits
<OutputIterator
>::value_type Out
;
26 typename
std::iterator_traits
<OutputIterator
>::difference_type k
= 0;
27 for (; first
!= last
; ++first
, ++out_first
, ++k
)
30 Out expected
= 1 - *first
;
31 Out actual
= *out_first
;
32 EXPECT_EQ(expected
, actual
, "wrong value in output sequence");
34 *out_first
= k
% 7 != 4 ? 7 * k
- 5 : 0;
38 struct test_one_policy
40 template <typename Policy
, typename InputIterator
, typename OutputIterator
, typename UnaryOp
>
42 operator()(Policy
&& exec
, InputIterator first
, InputIterator last
, OutputIterator out_first
,
43 OutputIterator out_last
, UnaryOp op
)
45 auto orr
= std::transform(exec
, first
, last
, out_first
, op
);
46 EXPECT_TRUE(out_last
== orr
, "transform returned wrong iterator");
47 check_and_reset(first
, last
, out_first
);
51 template <typename Tin
, typename Tout
>
55 for (size_t n
= 0; n
<= 100000; n
= n
<= 16 ? n
+ 1 : size_t(3.1415 * n
))
57 Sequence
<Tin
> in(n
, [](int32_t k
) { return k
% 5 != 1 ? 3 * k
- 7 : 0; });
59 Sequence
<Tout
> out(n
);
61 const auto flip
= Complement
<Tin
, Tout
>(1);
62 invoke_on_all_policies(test_one_policy(), in
.begin(), in
.end(), out
.begin(), out
.end(), flip
);
63 invoke_on_all_policies(test_one_policy(), in
.cbegin(), in
.cend(), out
.begin(), out
.end(), flip
);
70 template <typename Policy
, typename InputIterator
, typename OutputInterator
>
72 operator()(Policy
&& exec
, InputIterator input_iter
, OutputInterator out_iter
)
74 invoke_if(exec
, [&]() { transform(exec
, input_iter
, input_iter
, out_iter
, non_const(std::negate
<T
>())); });
81 test
<int32_t, int32_t>();
82 test
<int32_t, float32_t
>();
83 test
<uint16_t, float32_t
>();
84 test
<float32_t
, float64_t
>();
85 test
<float64_t
, float64_t
>();
87 test_algo_basic_double
<int32_t>(run_for_rnd_fw
<test_non_const
<int32_t>>());
89 std::cout
<< done() << std::endl
;