Boost logo

Boost Users :

Subject: Re: [Boost-users] [Bind] Retrun-type of bind expressions (SOLVED)
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-12-01 07:51:49


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_objects)

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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net