[lld][WebAssembly] Add `--table-base` setting
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.fill / pstl.fill.pass.cpp
bloba341816b10b6ee70e51feea4d5edba6534f475e4
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <algorithm>
11 // UNSUPPORTED: c++03, c++11, c++14
13 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
15 // template<class ExecutionPolicy, class ForwardIterator, class T>
16 // void fill(ExecutionPolicy&& exec,
17 // ForwardIterator first, ForwardIterator last, const T& value);
19 #include <algorithm>
20 #include <cassert>
21 #include <vector>
23 #include "test_macros.h"
24 #include "test_execution_policies.h"
25 #include "test_iterators.h"
27 EXECUTION_POLICY_SFINAE_TEST(fill);
29 static_assert(sfinae_test_fill<int, int*, int*, bool (*)(int)>);
30 static_assert(!sfinae_test_fill<std::execution::parallel_policy, int*, int*, int>);
32 template <class Iter>
33 struct Test {
34 template <class Policy>
35 void operator()(Policy&& policy) {
36 { // simple test
37 int a[4];
38 std::fill(policy, Iter(std::begin(a)), Iter(std::end(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
42 int a[1] = {2};
43 std::fill(policy, Iter(std::begin(a)), Iter(std::begin(a)), 33);
44 assert(a[0] == 2);
46 { // check that a one-element range works
47 int a[1];
48 std::fill(policy, Iter(std::begin(a)), Iter(std::end(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
52 int a[2];
53 std::fill(policy, Iter(std::begin(a)), Iter(std::end(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(policy, Iter(std::data(a)), 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 #ifndef TEST_HAS_NO_EXCEPTIONS
65 struct ThrowOnCopy {
66 ThrowOnCopy& operator=(const ThrowOnCopy&) { throw int{}; }
68 #endif
70 int main(int, char**) {
71 types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});
73 #ifndef TEST_HAS_NO_EXCEPTIONS
74 std::set_terminate(terminate_successful);
75 ThrowOnCopy a[2];
76 try {
77 (void)std::fill(std::execution::par, std::begin(a), std::end(a), ThrowOnCopy{});
78 } catch (int) {
79 assert(false);
81 #endif
83 return 0;