From 52dabdd8c015a0d95c2da06b738627569cf5f99e Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Sat, 5 May 2012 09:25:28 -0600 Subject: [PATCH] added lambda example --- lambda.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lambda.cc diff --git a/lambda.cc b/lambda.cc new file mode 100644 index 0000000..06c7f6e --- /dev/null +++ b/lambda.cc @@ -0,0 +1,17 @@ +#include +#include +#include + +using namespace std; + +int main() { + vector ints = {1, 2, 3, 4, 5, 6}; + int total = 0; + for_each(begin(ints), end(ints), [&total](int x) { + total += x; + }); + cout << "total: " << total << endl; + auto my_lambda_doubling_func = [&](int x) -> int { return x * 2; }; + cout << my_lambda_doubling_func(total) << endl; + return 0; +}