brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 9506044 Raw
57 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// UNSUPPORTED: c++03, c++11, c++1410 11// UNSUPPORTED: libcpp-has-no-incomplete-pstl12 13// template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>14//   ForwardIterator generate_n(ExecutionPolicy&& exec,15//                              ForwardIterator first, Size n, Generator gen);16 17#include <algorithm>18#include <cassert>19#include <vector>20 21#include "test_iterators.h"22#include "test_execution_policies.h"23#include "type_algorithms.h"24 25template <class Iter>26struct Test {27  template <class ExecutionPolicy>28  void operator()(ExecutionPolicy&& policy) {29    { // simple test30      int a[10];31      std::generate_n(policy, Iter(std::begin(a)), std::size(a), []() { return 1; });32      assert(std::all_of(std::begin(a), std::end(a), [](int i) { return i == 1; }));33    }34    { // empty range works35      int a[10] {3};36      std::generate_n(policy, Iter(std::begin(a)), 0, []() { return 1; });37      assert(a[0] == 3);38    }39    { // single-element range works40      int a[] {3};41      std::generate_n(policy, Iter(std::begin(a)), std::size(a), []() { return 5; });42      assert(a[0] == 5);43    }44    { // large range works45      std::vector<int> vec(150, 4);46      std::generate_n(policy, Iter(std::data(vec)), std::size(vec), []() { return 5; });47      assert(std::all_of(std::begin(vec), std::end(vec), [](int i) { return i == 5; }));48    }49  }50};51 52int main(int, char**) {53  types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});54 55  return 0;56}57