15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 3*57b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*57b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*57b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 95a83710eSEric Fiselier // <algorithm> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // template<ForwardIterator Iter, class T> 125a83710eSEric Fiselier // requires OutputIterator<Iter, const T&> 134bfb9313SMarshall Clow // constexpr void // constexpr after C++17 145a83710eSEric Fiselier // fill(Iter first, Iter last, const T& value); 155a83710eSEric Fiselier 165a83710eSEric Fiselier #include <algorithm> 175a83710eSEric Fiselier #include <cassert> 185a83710eSEric Fiselier 194bfb9313SMarshall Clow #include "test_macros.h" 205a83710eSEric Fiselier #include "test_iterators.h" 215a83710eSEric Fiselier 224bfb9313SMarshall Clow #if TEST_STD_VER > 17 234bfb9313SMarshall Clow TEST_CONSTEXPR bool test_constexpr() { 244bfb9313SMarshall Clow int ia[] = {0, 1, 2, 3, 4}; 254bfb9313SMarshall Clow 264bfb9313SMarshall Clow std::fill(std::begin(ia), std::end(ia), 5); 274bfb9313SMarshall Clow 284bfb9313SMarshall Clow return std::all_of(std::begin(ia), std::end(ia), [](int a) {return a == 5; }) 294bfb9313SMarshall Clow ; 304bfb9313SMarshall Clow } 314bfb9313SMarshall Clow #endif 324bfb9313SMarshall Clow 335a83710eSEric Fiselier template <class Iter> 345a83710eSEric Fiselier void 355a83710eSEric Fiselier test_char() 365a83710eSEric Fiselier { 375a83710eSEric Fiselier const unsigned n = 4; 385a83710eSEric Fiselier char ca[n] = {0}; 395a83710eSEric Fiselier std::fill(Iter(ca), Iter(ca+n), char(1)); 405a83710eSEric Fiselier assert(ca[0] == 1); 415a83710eSEric Fiselier assert(ca[1] == 1); 425a83710eSEric Fiselier assert(ca[2] == 1); 435a83710eSEric Fiselier assert(ca[3] == 1); 445a83710eSEric Fiselier } 455a83710eSEric Fiselier 465a83710eSEric Fiselier template <class Iter> 475a83710eSEric Fiselier void 485a83710eSEric Fiselier test_int() 495a83710eSEric Fiselier { 505a83710eSEric Fiselier const unsigned n = 4; 515a83710eSEric Fiselier int ia[n] = {0}; 525a83710eSEric Fiselier std::fill(Iter(ia), Iter(ia+n), 1); 535a83710eSEric Fiselier assert(ia[0] == 1); 545a83710eSEric Fiselier assert(ia[1] == 1); 555a83710eSEric Fiselier assert(ia[2] == 1); 565a83710eSEric Fiselier assert(ia[3] == 1); 575a83710eSEric Fiselier } 585a83710eSEric Fiselier 595a83710eSEric Fiselier int main() 605a83710eSEric Fiselier { 615a83710eSEric Fiselier test_char<forward_iterator<char*> >(); 625a83710eSEric Fiselier test_char<bidirectional_iterator<char*> >(); 635a83710eSEric Fiselier test_char<random_access_iterator<char*> >(); 645a83710eSEric Fiselier test_char<char*>(); 655a83710eSEric Fiselier 665a83710eSEric Fiselier test_int<forward_iterator<int*> >(); 675a83710eSEric Fiselier test_int<bidirectional_iterator<int*> >(); 685a83710eSEric Fiselier test_int<random_access_iterator<int*> >(); 695a83710eSEric Fiselier test_int<int*>(); 704bfb9313SMarshall Clow 714bfb9313SMarshall Clow #if TEST_STD_VER > 17 724bfb9313SMarshall Clow static_assert(test_constexpr()); 734bfb9313SMarshall Clow #endif 745a83710eSEric Fiselier } 75