2 //===-- fill.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 It
, typename T
>
25 check(It first
, It last
, const T
& value
)
27 for (; first
!= last
; ++first
)
33 template <typename Policy
, typename Iterator
, typename T
>
35 operator()(Policy
&& exec
, Iterator first
, Iterator last
, const T
& value
)
37 fill(first
, last
, T(value
+ 1)); // initialize memory with different value
39 fill(exec
, first
, last
, value
);
40 EXPECT_TRUE(check(first
, last
, value
), "fill wrong result");
46 template <typename It
, typename Size
, typename T
>
48 check(It first
, Size n
, const T
& value
)
50 for (Size i
= 0; i
< n
; ++i
, ++first
)
56 template <typename Policy
, typename Iterator
, typename Size
, typename T
>
58 operator()(Policy
&& exec
, Iterator first
, Size n
, const T
& value
)
60 fill_n(first
, n
, T(value
+ 1)); // initialize memory with different value
62 const Iterator one_past_last
= fill_n(exec
, first
, n
, value
);
63 const Iterator expected_return
= std::next(first
, n
);
65 EXPECT_TRUE(expected_return
== one_past_last
, "fill_n should return Iterator to one past the element assigned");
66 EXPECT_TRUE(check(first
, n
, value
), "fill_n wrong result");
69 const Iterator res
= fill_n(exec
, first
, -1, value
);
70 EXPECT_TRUE(res
== first
, "fill_n wrong result for n == -1");
76 test_fill_by_type(std::size_t n
)
78 Sequence
<T
> in(n
, [](std::size_t) -> T
{ return T(0); }); //fill with zeros
81 invoke_on_all_policies(test_fill(), in
.begin(), in
.end(), value
);
82 invoke_on_all_policies(test_fill_n(), in
.begin(), n
, value
);
89 const std::size_t N
= 100000;
91 for (std::size_t n
= 0; n
< N
; n
= n
< 16 ? n
+ 1 : size_t(3.1415 * n
))
93 test_fill_by_type
<int32_t>(n
);
94 test_fill_by_type
<float64_t
>(n
);
97 std::cout
<< done() << std::endl
;