test.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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<InputIterator Iter, Callable<auto, Iter::reference> Function>
  11. // requires CopyConstructible<Function>
  12. // Function
  13. // for_each(Iter first, Iter last, Function f);
  14. #include <algorithm>
  15. #include <cassert>
  16. #include "test_iterators.h"
  17. struct for_each_test
  18. {
  19. for_each_test(int c) : count(c) {}
  20. int count;
  21. void operator()(int& i) {++i; ++count;}
  22. };
  23. int main()
  24. {
  25. int ia[] = {0, 1, 2, 3, 4, 5};
  26. const unsigned s = sizeof(ia)/sizeof(ia[0]);
  27. for_each_test f = std::for_each(input_iterator<int*>(ia),
  28. input_iterator<int*>(ia+s),
  29. for_each_test(0));
  30. assert(f.count == s);
  31. for (unsigned i = 0; i < s; ++i)
  32. assert(ia[i] == i+1);
  33. }