]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
488d2837 PC |
2 | |
3 | // 2010-02-19 Paolo Carlini <paolo.carlini@oracle.com> | |
4 | ||
818ab71a | 5 | // Copyright (C) 2010-2016 Free Software Foundation, Inc. |
488d2837 PC |
6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | ||
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | // XXX FIXME: parallel-mode should deal correctly with moveable-only types | |
23 | // per C++0x, at minimum smoothly fall back to serial. | |
24 | #undef _GLIBCXX_PARALLEL | |
25 | ||
26 | #include <algorithm> | |
27 | #include <testsuite_hooks.h> | |
28 | #include <testsuite_iterators.h> | |
29 | ||
30 | struct Function | |
31 | { | |
32 | Function() : tot(0) { } | |
33 | Function(Function&& f) : tot(f.tot) { f.tot = 0; } | |
34 | ||
35 | Function(const Function&) = delete; | |
36 | ||
37 | void operator()(int num) | |
38 | { tot += num; } | |
39 | ||
40 | int get() { return tot; } | |
41 | ||
42 | private: | |
43 | int tot; | |
44 | }; | |
45 | ||
46 | void test01() | |
47 | { | |
48 | bool test __attribute__((unused)) = true; | |
49 | using __gnu_test::test_container; | |
50 | using __gnu_test::input_iterator_wrapper; | |
51 | ||
52 | typedef test_container<int, input_iterator_wrapper> Container; | |
53 | ||
54 | int array[5] = { 1, 2, 3, 4, 5 }; | |
55 | Container con(array, array + 5); | |
56 | ||
57 | Function f; | |
58 | Function f_res = std::for_each(con.begin(), con.end(), std::move(f)); | |
59 | ||
60 | VERIFY( f_res.get() == 15 ); | |
61 | } | |
62 | ||
63 | int main() | |
64 | { | |
65 | test01(); | |
66 | return 0; | |
67 | } |