Home | History | Annotate | Download | only in alg.fill
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <algorithm>
     11 
     12 // template<ForwardIterator Iter, class T>
     13 //   requires OutputIterator<Iter, const T&>
     14 //   void
     15 //   fill(Iter first, Iter last, const T& value);
     16 
     17 #include <algorithm>
     18 #include <cassert>
     19 
     20 #include "test_iterators.h"
     21 
     22 template <class Iter>
     23 void
     24 test_char()
     25 {
     26     const unsigned n = 4;
     27     char ca[n] = {0};
     28     std::fill(Iter(ca), Iter(ca+n), char(1));
     29     assert(ca[0] == 1);
     30     assert(ca[1] == 1);
     31     assert(ca[2] == 1);
     32     assert(ca[3] == 1);
     33 }
     34 
     35 template <class Iter>
     36 void
     37 test_int()
     38 {
     39     const unsigned n = 4;
     40     int ia[n] = {0};
     41     std::fill(Iter(ia), Iter(ia+n), 1);
     42     assert(ia[0] == 1);
     43     assert(ia[1] == 1);
     44     assert(ia[2] == 1);
     45     assert(ia[3] == 1);
     46 }
     47 
     48 int main()
     49 {
     50     test_char<forward_iterator<char*> >();
     51     test_char<bidirectional_iterator<char*> >();
     52     test_char<random_access_iterator<char*> >();
     53     test_char<char*>();
     54 
     55     test_int<forward_iterator<int*> >();
     56     test_int<bidirectional_iterator<int*> >();
     57     test_int<random_access_iterator<int*> >();
     58     test_int<int*>();
     59 }
     60