In this first example, we see how to create a function object referring to a function, and how to use it:
#include <functional> // std::function
#include "boost/function.hpp" // boost::function
bool check(int i, double d)
return i > d;
boost::function<bool (int, double)> fb = ✓
function<bool (int, double)> fs = ✓
cout << "Boost function works as expected" << endl;
cout << "std function works as expected" << endl;
In boost and in C++0x the class function looks just the same. In the template parameters we put the return type and, in round brackets, the parameter types.
The code is based on an example provided by "Beyond the C++ Standard Library: An Introduction to Boost", by Björn Karlsson, an Addison Wesley Professional book. An interesting reading indeed.