15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
35a83710eSEric Fiselier //                     The LLVM Compiler Infrastructure
45a83710eSEric Fiselier //
55a83710eSEric Fiselier // This file is dual licensed under the MIT and the University of Illinois Open
65a83710eSEric Fiselier // Source Licenses. See LICENSE.TXT for details.
75a83710eSEric Fiselier //
85a83710eSEric Fiselier //===----------------------------------------------------------------------===//
95a83710eSEric Fiselier 
105a83710eSEric Fiselier // <algorithm>
115a83710eSEric Fiselier 
125a83710eSEric Fiselier // template<ForwardIterator Iter, class T>
135a83710eSEric Fiselier //   requires OutputIterator<Iter, const T&>
14*4bfb9313SMarshall Clow //   constexpr void      // constexpr after C++17
155a83710eSEric Fiselier //   fill(Iter first, Iter last, const T& value);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <algorithm>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier 
20*4bfb9313SMarshall Clow #include "test_macros.h"
215a83710eSEric Fiselier #include "test_iterators.h"
225a83710eSEric Fiselier 
23*4bfb9313SMarshall Clow #if TEST_STD_VER > 17
24*4bfb9313SMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
25*4bfb9313SMarshall Clow     int ia[] = {0, 1, 2, 3, 4};
26*4bfb9313SMarshall Clow 
27*4bfb9313SMarshall Clow     std::fill(std::begin(ia), std::end(ia), 5);
28*4bfb9313SMarshall Clow 
29*4bfb9313SMarshall Clow     return std::all_of(std::begin(ia), std::end(ia), [](int a) {return a == 5; })
30*4bfb9313SMarshall Clow         ;
31*4bfb9313SMarshall Clow     }
32*4bfb9313SMarshall Clow #endif
33*4bfb9313SMarshall Clow 
345a83710eSEric Fiselier template <class Iter>
355a83710eSEric Fiselier void
365a83710eSEric Fiselier test_char()
375a83710eSEric Fiselier {
385a83710eSEric Fiselier     const unsigned n = 4;
395a83710eSEric Fiselier     char ca[n] = {0};
405a83710eSEric Fiselier     std::fill(Iter(ca), Iter(ca+n), char(1));
415a83710eSEric Fiselier     assert(ca[0] == 1);
425a83710eSEric Fiselier     assert(ca[1] == 1);
435a83710eSEric Fiselier     assert(ca[2] == 1);
445a83710eSEric Fiselier     assert(ca[3] == 1);
455a83710eSEric Fiselier }
465a83710eSEric Fiselier 
475a83710eSEric Fiselier template <class Iter>
485a83710eSEric Fiselier void
495a83710eSEric Fiselier test_int()
505a83710eSEric Fiselier {
515a83710eSEric Fiselier     const unsigned n = 4;
525a83710eSEric Fiselier     int ia[n] = {0};
535a83710eSEric Fiselier     std::fill(Iter(ia), Iter(ia+n), 1);
545a83710eSEric Fiselier     assert(ia[0] == 1);
555a83710eSEric Fiselier     assert(ia[1] == 1);
565a83710eSEric Fiselier     assert(ia[2] == 1);
575a83710eSEric Fiselier     assert(ia[3] == 1);
585a83710eSEric Fiselier }
595a83710eSEric Fiselier 
605a83710eSEric Fiselier int main()
615a83710eSEric Fiselier {
625a83710eSEric Fiselier     test_char<forward_iterator<char*> >();
635a83710eSEric Fiselier     test_char<bidirectional_iterator<char*> >();
645a83710eSEric Fiselier     test_char<random_access_iterator<char*> >();
655a83710eSEric Fiselier     test_char<char*>();
665a83710eSEric Fiselier 
675a83710eSEric Fiselier     test_int<forward_iterator<int*> >();
685a83710eSEric Fiselier     test_int<bidirectional_iterator<int*> >();
695a83710eSEric Fiselier     test_int<random_access_iterator<int*> >();
705a83710eSEric Fiselier     test_int<int*>();
71*4bfb9313SMarshall Clow 
72*4bfb9313SMarshall Clow #if TEST_STD_VER > 17
73*4bfb9313SMarshall Clow     static_assert(test_constexpr());
74*4bfb9313SMarshall Clow #endif
755a83710eSEric Fiselier }
76