Unfortunately, I didn't have time to prepare my own notes for this topic this semester. Instead, I read for hours looking for the best and most gentle introductions to the topic I could find on the Internet.
I believe you should start with either this one from the University of Michigan or this one from BogoToBogo. (See here for more on what a bogo is in computing.)
To get yourself up to speed on the C++14 aspects of lambda programming, you'll sadly have to step over to Microsoft's blogs here. (Sorry, I couldn't find a gentler intro to generic lambdas and initializing capture.) But, while you're slumming, you might take in the linked article on lambda expressions vs. function objects.
Finally, keep in mind that, you can also use the std function as_const to initialize your reference capture as a constant to get the effect of a const& capture. as_const can be found in the utility library. (All the pages that explain that are quite intractable! But see here about two-thirds of the way down for a decent example. It's in a little "since C++14" box and is the first occurance of as_const on the page, so...)
Having read all of those links above and maybe practiced some of it on your own programs, here is a practical side-by-side example of how lambda functions can improve your programming experience. First look back at this example involving templated function objects. There was a Total_c class to add up a sequence of elements into a total and report it. Now take a look at this example involving lambda functions to do the same thing. I've put in several comments to help clarify parts of the code, but as always, feel free to ask any questions that come to mind via email or in office hours.
Last modified 05/12/2022 01:21:41.
It is now 3/15/2025, 2:04:11 AM.
Date you last viewed this page: That's for you to know and ...well, that's for you to know.
© 1993-2025 Jason James (email — craie@acm.org — for permissions &/or details)