Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <algorithm> |
| 11 | |
Howard Hinnant | 664ae81 | 2010-08-22 00:08:10 +0000 | [diff] [blame^] | 12 | // template<ForwardIterator Iter, Callable Generator> |
| 13 | // requires OutputIterator<Iter, Generator::result_type> |
| 14 | // && CopyConstructible<Generator> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | // void |
| 16 | // generate(Iter first, Iter last, Generator gen); |
| 17 | |
| 18 | #include <algorithm> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "../../iterators.h" |
| 22 | |
| 23 | struct gen_test |
| 24 | { |
| 25 | int operator()() const {return 1;} |
| 26 | }; |
| 27 | |
| 28 | template <class Iter> |
| 29 | void |
| 30 | test() |
| 31 | { |
| 32 | const unsigned n = 4; |
| 33 | int ia[n] = {0}; |
| 34 | std::generate(Iter(ia), Iter(ia+n), gen_test()); |
| 35 | assert(ia[0] == 1); |
| 36 | assert(ia[1] == 1); |
| 37 | assert(ia[2] == 1); |
| 38 | assert(ia[3] == 1); |
| 39 | } |
| 40 | |
| 41 | int main() |
| 42 | { |
| 43 | test<forward_iterator<int*> >(); |
| 44 | test<bidirectional_iterator<int*> >(); |
| 45 | test<random_access_iterator<int*> >(); |
| 46 | test<int*>(); |
| 47 | } |