| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 |
|
| 4 |
#include <cassert> |
| 5 |
#include <algorithm> |
| 6 |
|
| 7 |
template <typename F, typename A1> |
| 8 |
void call(F f, const A1& arg1) { |
| 9 |
f(arg1); |
| 10 |
} |
| 11 |
|
| 12 |
int main() { |
| 13 |
int i = 1; |
| 14 |
call( |
| 15 |
[&i] (int j) -> void { i = j; }, |
| 16 |
2 |
| 17 |
); |
| 18 |
assert(i == 2); |
| 19 |
|
| 20 |
int A[] = {1, 2, 3, 4}; |
| 21 |
int sum = 0; |
| 22 |
std::for_each(A, A+4, [&sum] (int n) -> void { sum += n; }); |
| 23 |
assert(sum == 10); |
| 24 |
|
| 25 |
return 0; |
| 26 |
} |
| 27 |
|