]>
Commit | Line | Data |
---|---|---|
ed920373 JW |
1 | // { dg-options "-std=gnu++17" } |
2 | // { dg-do run { target c++17 } } | |
3 | ||
4 | // Copyright (C) 2019 Free Software Foundation, Inc. | |
5 | // | |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <algorithm> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_iterators.h> | |
24 | ||
25 | void test01() | |
26 | { | |
27 | using __gnu_test::test_container; | |
28 | using __gnu_test::input_iterator_wrapper; | |
29 | int array[5] = { 1, 2, 3, 4, 5 }; | |
30 | test_container<int, input_iterator_wrapper> con(array); | |
31 | ||
32 | int sum = 0; | |
33 | struct Func | |
34 | { | |
35 | Func(int& i) : i(i) { } | |
36 | Func(Func&&) = default; | |
37 | Func& operator=(Func&&) = delete; | |
38 | void operator()(int n) const { i += n; } | |
39 | int& i; | |
40 | }; | |
41 | ||
42 | struct Size | |
43 | { | |
44 | Size(short v) : val(v) { } | |
45 | operator short() const { return val; } | |
46 | short val; | |
47 | }; | |
48 | auto res = std::for_each_n(con.begin(), Size(con.size()), Func(sum)); | |
49 | ||
50 | VERIFY( res.ptr == con.end().ptr ); | |
51 | VERIFY( sum == 15 ); | |
52 | } | |
53 | ||
54 | int main() | |
55 | { | |
56 | test01(); | |
57 | } |