Re: [Boost-users] [Bind] Retrun-type of bind expressions (SOLVED)
Hi, I found out how to specify the return type using boost::function and boost::bind, basically thanks to http://stackoverflow.com/questions/1044703/how-do-you-pass-boostbind-objects... to-a-function/1044732#1044732 Say we are given two function objects (DefaultConstructible, CopyConstructible and only having "bool operator()"). As a little side note, it might be necessary to include "typedef bool return_type" in the definition of the functions objects (struct, class) (s. http://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html#with_function_objec...) Then the return type can be declared as follows: typedef boost::function< bool( ARG-TYPE ) > CombinedPred; CombinedPred combined_pred = boost::bind(functor1, _1) && boost::bind(functor2, _1) where ARG-TYPE is the input paramter type the operator() was defined for in the functors (e.g. int, if operator() is working on ints). The basic idea is that functors that "return" bool and have the same input argument type will also have the same type(s) when being combined, e.g. by logical operators. Other combinations are of course also possible as boost::bind provides several overloaded operators like "&&", "||", "!" etc. Best, Cedric
participants (1)
-
Cedric Laczny