]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.nonmodifying / alg.foreach / test.pass.cpp
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<InputIterator Iter, Callable<auto, Iter::reference> Function>
13 //   requires CopyConstructible<Function>
14 //   Function
15 //   for_each(Iter first, Iter last, Function f);
16
17 #include <algorithm>
18 #include <cassert>
19
20 #include "test_iterators.h"
21
22 struct for_each_test
23 {
24     for_each_test(int c) : count(c) {}
25     int count;
26     void operator()(int& i) {++i; ++count;}
27 };
28
29 int main()
30 {
31     int ia[] = {0, 1, 2, 3, 4, 5};
32     const unsigned s = sizeof(ia)/sizeof(ia[0]);
33     for_each_test f = std::for_each(input_iterator<int*>(ia),
34                                     input_iterator<int*>(ia+s),
35                                     for_each_test(0));
36     assert(f.count == s);
37     for (unsigned i = 0; i < s; ++i)
38         assert(ia[i] == static_cast<int>(i+1));
39 }