generate_n.pass.cpp 1.1 KB

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