From the course: Introducing Functional Programming in C++
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Lambda functions: Curry - C++ Tutorial
From the course: Introducing Functional Programming in C++
Lambda functions: Curry
- [Instructor] Lambdas were introduced to the language with C++11, they are unnamed function objects which can create a closure over the invoking scope. Let's write some code to learn more about lambdas. We already have this file set up, we have some code down here inside of our main function, and this is just going to render the results once we're ready for it. We have our include and using already set up, and we're going to create an auto variable called addCurry, and we're going to set this equal to auto a, and this is going to be our lambda. And then it is going to return, and right here in our capture list, we're going to put the a, and this means that we want to be able to access a from our inner lambda, and then we're going to have a parameter list, and that's going to be b. Then b is also going to return, and what it's going to return is another lambda, and so inside of the capture list for the b, we're going to put a and b, 'cause we're want them both. Then we're going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Enabling C++ 174m 24s
-
(Locked)
transform instead of map5m 30s
-
(Locked)
copy_if instead of filter2m 59s
-
(Locked)
accumulate instead of reduce2m 51s
-
(Locked)
bind4m 56s
-
(Locked)
Functions6m 54s
-
(Locked)
Lambda functions: Curry3m 38s
-
(Locked)
Lambda functions: Closures2m 20s
-
(Locked)
Challenge: Factorial continuous add33s
-
(Locked)
Solution: Factorial continuous add3m 15s
-
(Locked)
-
-
-