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 #include "user_defined_integral.hpp"
23 
24 typedef UserDefinedIntegral<unsigned> UDI;
25 
26 struct gen_test
27 {
operator ()gen_test28     int operator()() const {return 2;}
29 };
30 
31 template <class Iter>
32 void
test()33 test()
34 {
35     const unsigned n = 4;
36     int ia[n] = {0};
37     assert(std::generate_n(Iter(ia), UDI(n), gen_test()) == Iter(ia+n));
38     assert(ia[0] == 2);
39     assert(ia[1] == 2);
40     assert(ia[2] == 2);
41     assert(ia[3] == 2);
42 }
43 
main()44 int main()
45 {
46     test<forward_iterator<int*> >();
47     test<bidirectional_iterator<int*> >();
48     test<random_access_iterator<int*> >();
49     test<int*>();
50 }
51