Boost logo

Boost Users :

Subject: Re: [Boost-users] Two questions on boost::function
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-11-10 15:32:43


AMDG

CHRISTOPHE KOUDELLA, CITADEL INVESTMENT G wrote:
> Hi, I am hopng to get some help from boost::function users on two questions I have.
>
> First, is it possible to extract the underlying functor out of a function? The reason for this is that it is useful to have the boost::function abstraction to move around functors in a generic fashion, but the interface is obviously limited to operator(), so being able to extract the underlying class out of a boost::function would be useful. I am thinking mostly about applied math applications in which functions are defined by more than an operator, whence the interface of boost::function is sometimes insufficient.
>

If you have to extract the underlying type, boost::function is probably
not appropriate.

> Second, I was looking to implement a "function algebra" for boost::function (of a given arity, for a start). This algebra would implement sum, difference, product, composition, etc... operations on a pair of like boost::functions. In a template implementation in order to implement the operator() of the result boost::function, I need to access the result type and the argument types of the boost::functions being operated on. So, suppose I want to implement a product operation on a pair of template functors, then in order to define the operator() of the product of the functors, I need the result and argument types. Does boost::function make these types available as some typedefs? Does what I say make at all sense or would you proceed entirely differently in order to define such operations on boost::function?
>

Something like this can be done using Boost.Lambda.

boost::function<int(int)> f1, f2, f3;
//...
using namespace boost::lambda;
// sum
f3 = bind(f1, _1) + bind(f2, _1);
// composition
f3 = bind(f1, bind(f2, _1));

In Christ,
Steven Watanabe


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