Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.generate / generate.pass.cpp
blob29d32d715674276910680856d338cc0d8643b42e
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 // template<ForwardIterator Iter, Callable Generator>
12 // requires OutputIterator<Iter, Generator::result_type>
13 // && CopyConstructible<Generator>
14 // constexpr void // constexpr after c++17
15 // generate(Iter first, Iter last, Generator gen);
17 #include <algorithm>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "test_iterators.h"
23 struct gen_test
25 TEST_CONSTEXPR int operator()() const {return 1;}
29 #if TEST_STD_VER > 17
30 TEST_CONSTEXPR bool test_constexpr() {
31 int ia[] = {0, 1, 2, 3, 4};
33 std::generate(std::begin(ia), std::end(ia), gen_test());
35 return std::all_of(std::begin(ia), std::end(ia), [](int x) { return x == 1; })
38 #endif
41 template <class Iter>
42 void
43 test()
45 const unsigned n = 4;
46 int ia[n] = {0};
47 std::generate(Iter(ia), Iter(ia+n), gen_test());
48 assert(ia[0] == 1);
49 assert(ia[1] == 1);
50 assert(ia[2] == 1);
51 assert(ia[3] == 1);
54 int main(int, char**)
56 test<forward_iterator<int*> >();
57 test<bidirectional_iterator<int*> >();
58 test<random_access_iterator<int*> >();
59 test<int*>();
61 #if TEST_STD_VER > 17
62 static_assert(test_constexpr());
63 #endif
65 return 0;