Compose Function Object Adapters |
The C++ Standard Template Library STL as part of the C++ Standard Library provides several function objects. Unfortunately, it doesn't provide the ability to compose these function objects. For example, it is not possible to combine the result of two unary operations to formulate a criterion such as "this and that". But this would be important for building software components out of other components, which leads to the concept of functional composition. So, here are some adapters that close this gap.
In fact, these adapters provide to compose
function objects as follows:
Functionality | Boost Name | SGI STL's Name |
f(g(value)) | compose_f_gx | compose1 |
f(g(value),h(value)) | compose_f_gx_hx | compose2 |
f(g(value1),h(value2)) | compose_f_gx_hy | |
f(g(value1,value2)) | compose_f_gxy | |
f(g()) | compose_f_g |
As you can see, two of these adapters are part of the SGI STL already. However, we changed the names according to a consistent naming scheme for all adapters.
In addition, this code also defines a type nullary_function for function objects that have no argument (as supplement to unary_function and binary_function) and overloads ptr_fun for functions that take no arguments.
The code is provided "as is" without expressed or implied warranty.
compose.hpp:
Note that this library was part of Boost, but is deprecated right now. You might consider to use Boost.Bind, instead.