We need to start somewhere in our exploration of functional programming support in STL, and the header aptly named <functional> seems like a good start. This header defines the fundamental function<> type, which we can use for functions and have used a few times in this book for lambdas:
TEST_CASE("Identity function"){
function<int(int)> identity = [](int value) { return value;};
CHECK_EQ(1, identity(1));
}
We can use the function<> type to store any type of function, be it a free function, a member function, or a lambda. Let's look at an example of a free function:
TEST_CASE("Free function"){
function<int()> f = freeFunctionReturns2;
CHECK_EQ(2, f());
}
Here's an example of a member function:
class JustAClass{
public:
int functionReturns2() const { return 2; };
};
TEST_CASE...