1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // UNSUPPORTED: c++03, c++11, c++14
13 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
15 // template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
16 // ForwardIterator fill_n(ExecutionPolicy&& exec,
17 // ForwardIterator first, Size n, const T& value);
23 #include "test_macros.h"
24 #include "test_execution_policies.h"
25 #include "test_iterators.h"
27 EXECUTION_POLICY_SFINAE_TEST(fill_n
);
29 static_assert(sfinae_test_fill_n
<int, int*, int*, bool (*)(int)>);
30 static_assert(!sfinae_test_fill_n
<std::execution::parallel_policy
, int*, int*, int>);
34 template <class Policy
>
35 void operator()(Policy
&& policy
) {
38 std::fill_n(policy
, Iter(std::begin(a
)), std::size(a
), 33);
39 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 33; }));
41 { // check that an empty range works
43 std::fill_n(policy
, Iter(std::begin(a
)), 0, 33);
46 { // check that a one-element range works
48 std::fill_n(policy
, Iter(std::begin(a
)), std::size(a
), 33);
49 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 33; }));
51 { // check that a two-element range works
53 std::fill_n(policy
, Iter(std::begin(a
)), std::size(a
), 33);
54 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 33; }));
56 { // check that a large range works
57 std::vector
<int> a(234, 2);
58 std::fill_n(policy
, Iter(std::data(a
)), std::size(a
), 33);
59 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 33; }));
64 int main(int, char**) {
65 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});