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.
Functions - C++ Tutorial
From the course: Introducing Functional Programming in C++
Functions
- [Instructor] Std::function also comes from the functional header. It is a wrapper for invokable objects which includes functions, function objects, also known as functors, and lambdas. We can also store wrapped invokable objects in a vector of function objects. Let's take a look at some code to see how. Again, we're going to start off with a file that already includes our header. So we've got functional, iostream, string, and vector. We're using a namespace std. And we're going to start up here, and we need to create a few helper functions to get ourselves going. So the first one's going to be a void, and it's going to be called demoFunction. It doesn't take any parameters. And the only thing this function does is call cout, and it let's us know that demoFunction was called. And then we do an endl, and that's the end of that. The next function that we have here is we're going to say void and call this function adder. And it's going to take an int a and an int b. And once again it's…
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)
-
-
-