yo/classtemplates/examples/genlambda.cc
raw| 1 | #include <iostream> |
| 2 | #include <algorithm> |
| 3 | #include <vector> |
| 4 | #include <string> |
| 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | //code |
| 9 | int main() |
| 10 | { |
| 11 | auto lambda = [](auto lhs, auto rhs) |
| 12 | { |
| 13 | return lhs + rhs; |
| 14 | }; |
| 15 | |
| 16 | vector<int> values {1, 2, 3, 4, 5}; |
| 17 | vector<string> text {"a", "b", "c", "d", "e"}; |
| 18 | |
| 19 | cout << |
| 20 | accumulate(values.begin(), values.end(), 0, lambda) << '\n' << |
| 21 | accumulate(text.begin(), text.end(), string{}, lambda) << '\n'; |
| 22 | } |
| 23 | //= |