Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.fill / fill.pass.cpp
blobda56ec30f128b1b224bdc6ad67ca3efd32be1905
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, class T>
12 // requires OutputIterator<Iter, const T&>
13 // constexpr void // constexpr after C++17
14 // fill(Iter first, Iter last, const T& value);
16 #include <algorithm>
17 #include <cassert>
19 #include "test_macros.h"
20 #include "test_iterators.h"
22 #if TEST_STD_VER > 17
23 TEST_CONSTEXPR bool test_constexpr() {
24 int ia[] = {0, 1, 2, 3, 4};
26 std::fill(std::begin(ia), std::end(ia), 5);
28 return std::all_of(std::begin(ia), std::end(ia), [](int a) {return a == 5; })
31 #endif
33 template <class Iter>
34 void
35 test_char()
37 const unsigned n = 4;
38 char ca[n] = {0};
39 std::fill(Iter(ca), Iter(ca+n), char(1));
40 assert(ca[0] == 1);
41 assert(ca[1] == 1);
42 assert(ca[2] == 1);
43 assert(ca[3] == 1);
46 template <class Iter>
47 void
48 test_int()
50 const unsigned n = 4;
51 int ia[n] = {0};
52 std::fill(Iter(ia), Iter(ia+n), 1);
53 assert(ia[0] == 1);
54 assert(ia[1] == 1);
55 assert(ia[2] == 1);
56 assert(ia[3] == 1);
59 int main(int, char**)
61 test_char<forward_iterator<char*> >();
62 test_char<bidirectional_iterator<char*> >();
63 test_char<random_access_iterator<char*> >();
64 test_char<char*>();
66 test_int<forward_iterator<int*> >();
67 test_int<bidirectional_iterator<int*> >();
68 test_int<random_access_iterator<int*> >();
69 test_int<int*>();
71 #if TEST_STD_VER > 17
72 static_assert(test_constexpr());
73 #endif
75 return 0;