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 //===----------------------------------------------------------------------===//
8 
9 // <algorithm>
10 
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);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 #if TEST_STD_VER > 17
test_constexpr()23 TEST_CONSTEXPR bool test_constexpr() {
24     int ia[] = {0, 1, 2, 3, 4};
25 
26     std::fill(std::begin(ia), std::end(ia), 5);
27 
28     return std::all_of(std::begin(ia), std::end(ia), [](int a) {return a == 5; })
29         ;
30     }
31 #endif
32 
33 template <class Iter>
34 void
test_char()35 test_char()
36 {
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);
44 }
45 
46 template <class Iter>
47 void
test_int()48 test_int()
49 {
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);
57 }
58 
main(int,char **)59 int main(int, char**)
60 {
61     test_char<forward_iterator<char*> >();
62     test_char<bidirectional_iterator<char*> >();
63     test_char<random_access_iterator<char*> >();
64     test_char<char*>();
65 
66     test_int<forward_iterator<int*> >();
67     test_int<bidirectional_iterator<int*> >();
68     test_int<random_access_iterator<int*> >();
69     test_int<int*>();
70 
71 #if TEST_STD_VER > 17
72     static_assert(test_constexpr());
73 #endif
74 
75   return 0;
76 }
77