[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / pstl / test / std / algorithms / alg.modifying.operations / fill.pass.cpp
blobd44a1a483c1975116351ccabbeea8f5f5ac72c0d
1 // -*- C++ -*-
2 //===-- fill.pass.cpp -----------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 #include "support/pstl_test_config.h"
14 #include <execution>
15 #include <algorithm>
17 #include "support/utils.h"
19 using namespace TestUtils;
21 struct test_fill
23 template <typename It, typename T>
24 bool
25 check(It first, It last, const T& value)
27 for (; first != last; ++first)
28 if (*first != value)
29 return false;
30 return true;
33 template <typename Policy, typename Iterator, typename T>
34 void
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");
44 struct test_fill_n
46 template <typename It, typename Size, typename T>
47 bool
48 check(It first, Size n, const T& value)
50 for (Size i = 0; i < n; ++i, ++first)
51 if (*first != value)
52 return false;
53 return true;
56 template <typename Policy, typename Iterator, typename Size, typename T>
57 void
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");
68 //n == -1
69 const Iterator res = fill_n(exec, first, -1, value);
70 EXPECT_TRUE(res == first, "fill_n wrong result for n == -1");
74 template <typename T>
75 void
76 test_fill_by_type(std::size_t n)
78 Sequence<T> in(n, [](std::size_t) -> T { return T(0); }); //fill with zeros
79 T value = -1;
81 invoke_on_all_policies(test_fill(), in.begin(), in.end(), value);
82 invoke_on_all_policies(test_fill_n(), in.begin(), n, value);
85 int
86 main()
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;
99 return 0;