1 /* 2 * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 */ 4 5 #include <algorithm> 6 #include <iostream> 7 8 using namespace std; 9 lamda_test(void)10void lamda_test(void) 11 { 12 int total = 0; 13 int a[5] = {1, 2, 3, 4, 5}; 14 15 cout << "lamda test start" << endl; 16 17 for_each(a, &a[5], [&total](int &x) { total += x; }); 18 if (total != 15) { 19 cout << "lamda test error, total is " << total << endl; 20 } else { 21 cout << "lamda test ok" << endl; 22 } 23 } 24