brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · e456fa8 Raw
70 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <algorithm>10 11// UNSUPPORTED: c++03, c++11, c++1412 13// UNSUPPORTED: libcpp-has-no-incomplete-pstl14 15// template<class ExecutionPolicy, class ForwardIterator, class T>16//   void fill(ExecutionPolicy&& exec,17//             ForwardIterator first, ForwardIterator last, const T& value);18 19#include <algorithm>20#include <cassert>21#include <vector>22 23#include "test_macros.h"24#include "test_execution_policies.h"25#include "test_iterators.h"26#include "type_algorithms.h"27 28EXECUTION_POLICY_SFINAE_TEST(fill);29 30static_assert(sfinae_test_fill<int, int*, int*, bool (*)(int)>);31static_assert(!sfinae_test_fill<std::execution::parallel_policy, int*, int*, int>);32 33template <class Iter>34struct Test {35  template <class Policy>36  void operator()(Policy&& policy) {37    { // simple test38      int a[4];39      std::fill(policy, Iter(std::begin(a)), Iter(std::end(a)), 33);40      assert(std::all_of(std::begin(a), std::end(a), [](int i) { return i == 33; }));41    }42    { // check that an empty range works43      int a[1] = {2};44      std::fill(policy, Iter(std::begin(a)), Iter(std::begin(a)), 33);45      assert(a[0] == 2);46    }47    { // check that a one-element range works48      int a[1];49      std::fill(policy, Iter(std::begin(a)), Iter(std::end(a)), 33);50      assert(std::all_of(std::begin(a), std::end(a), [](int i) { return i == 33; }));51    }52    { // check that a two-element range works53      int a[2];54      std::fill(policy, Iter(std::begin(a)), Iter(std::end(a)), 33);55      assert(std::all_of(std::begin(a), std::end(a), [](int i) { return i == 33; }));56    }57    { // check that a large range works58      std::vector<int> a(234, 2);59      std::fill(policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), 33);60      assert(std::all_of(std::begin(a), std::end(a), [](int i) { return i == 33; }));61    }62  }63};64 65int main(int, char**) {66  types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});67 68  return 0;69}70