Lambdas are unnamed mini functions that allow developers to write more expressive and succinct code, especially when paired with the STL. Troy explains the goodness of lambdas in this video.
- [Instructor] A lambda expression…is an unnamed function object.…Use a lambda to write a local function of limited use.…You can also use lambdas for complex initializations.…Always prefer a lambda expression to an std::bind.…So in this sample, we have just a few things going on here.…First off, we have an enum that's giving us our…Battle Condition that's red, yellow, green.…We have a very small function called print_it…that's just going to take some output and print it out.…
Then we have a vector of ints,…just some random numbers,…and we're going to go through and do a for each on this,…and you notice, that if we're to use std::bind,…here's how we would use it as a function object generator…so that we could send print it to for each.…And it's a little bit clunky, a little bit overly bloated…and we have our function here and our use of it right here.…Now for the same thing, doing the exact same piece of code,…if we're going to do a lambda,…we could just put the lambda here in line in the function.…
Now this is perfect when you have a lambda…
- Major new C++ features
- Turning on modern C++
- Letting the compiler help
- Using the new features correctly
- Using auto type deduction
- Using lambdas
- Range-based for loops
- How C++ and the Standard Template Library name things
- Making the best of the filesystem library
- Managing objects
Skill Level Beginner
1. What Is Modern C++?
2. Tools That Improve Your Code
3. Using the New Features Correctly
4. Don't Reinvent the Wheel
5. Managing Objects
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.