Suppose the following two functions:
#include <iostream>
#include <cstdlib> // atoi
#include <cstring> // strcmp
#include <boost/bind.hpp>
bool match1(const char* a, const char* b) {
return (strcmp(a, b) == 0);
}
bool match2(int a, const char* b) {
return (atoi(b) == a);
}
Each of these functions takes two arguments, but can be transformed into a callable object that takes only one argument by using (std/boost)bind. Something along the lines of:
boost::bind(match1, "a test");
boost::bind(match2, 42);
I want to be able to obtain, from two functions like these that take one argument and return bool, a callable object that takes two arguments and returns the && of the bools. The type of the arguments is arbitrary.
Something like an operator&& for functions that return bool.
The return type of
boost::bindoverloadsoperator &&(as well as many others). So you can writeIf you want to store this value, use
boost::function. In this case, the type would beNote that this isn’t the return type of
boost::bind(that is unspecified), but any functor with the right signature is convertible to aboost::function.