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<class Iter, IntegralLike Size, Callable Generator>
13 //   requires OutputIterator<Iter, Generator::result_type>
14 //         && CopyConstructible<Generator>
15 //   void
16 //   generate_n(Iter first, Size n, Generator gen);
17 
18 #include <algorithm>
19 #include <cassert>
20 
21 #include "test_iterators.h"
22 
23 struct gen_test
24 {
operator ()gen_test25     int operator()() const {return 2;}
26 };
27 
28 template <class Iter>
29 void
test()30 test()
31 {
32     const unsigned n = 4;
33     int ia[n] = {0};
34     assert(std::generate_n(Iter(ia), n, gen_test()) == Iter(ia+n));
35     assert(ia[0] == 2);
36     assert(ia[1] == 2);
37     assert(ia[2] == 2);
38     assert(ia[3] == 2);
39 }
40 
main()41 int main()
42 {
43     test<forward_iterator<int*> >();
44     test<bidirectional_iterator<int*> >();
45     test<random_access_iterator<int*> >();
46     test<int*>();
47 }
48