Boost logo

Boost Users :

From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2006-10-01 09:43:58


On Sep 30, 2006, at 1:01 PM, Jason House wrote:

> I'm trying to convert the input argument to a function object using a
> small helper function object. The code below looks relatively simple,
> but it doesn't seem to compile. Any ideas what could be wrong?
>
> template<typename inputType, typename outputType>
> boost::function<outputType (int)>
> convert(boost::function<outputType (inputType)> &object_to_convert){
> boost::function<intputType (int)> input_converter(...);
>
> // The following fails to compile
> boost::function<outputType (int)> converted_function
> (boost::lambda::bind(object_to_convert, input_converter));

The bind expression is going to result in a function object that
calls object_to_convert(input_converter). What you really want is a
function object that takes one parameter ("arg1") and call
object_to_object with the result of input_converter(arg1). To do so,
you will need a nested bind expression that will look something like
this:

   boost::function<outputType (int)> converted_function
    (boost::lambda::bind(object_to_convert, boost::lambda::bind
(input_converter, arg1)));

        Cheers,
        Doug


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