Boost logo

Boost Users :

Subject: Re: [Boost-users] How to use boost::function with boost::phoenix?
From: Joel de Guzman (joel_at_[hidden])
Date: 2010-05-01 19:02:14


On 5/1/2010 5:18 PM, Jens Mueller wrote:
> Hi,
>
> I'm trying out boost:phoenix. Until now I used boost::lambda. I have code
> written using boost::lambda that returns a boost::function. E.g.
>
> boost::function<float(float)> flog() {
> using namespace boost::lambda;
> return bind(static_cast<float(*)(float)>(std::log), _1);
> }
>
> And with boost::lambda I can reuse the boost::function like this
>
> boost::function<float(float)> func = -bind(flog(), _1);
>
> to build bigger blocks.
>
> But I cannot make it work with boost::phoenix.
>
> boost::function<float(float)> func = -bind(flog(), arg1);
>
> does not compile.
>
> How do I use a boost::function within phoenix? Or what do I need to return
> instead of a boost::function to reuse it in phoenix? Basically I want to
> build more complex functions out of simple ones which are returned by some
> function to hide the internals of the function.
> I'm using Boost version 1.41.0 and g++ (Debian 4.3.2-1.1) 4.3.2.

It is a known deficiency with phoenix that it does not work well
with boost::function the way you are doing it, due to result_of
protocol incompatibility. This has been bugging me for some time
now. Let me think about an easy fix. In the meantime, I suggest
wrapping the boost function call in a generic phoenix::function.
Please see this thread:

     http://tinyurl.com/232t7yk

Such a wrapper should work any boost function if you make it generic.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net
http://www.facebook.com/djowel
Meet me at BoostCon
http://www.boostcon.com/home
http://www.facebook.com/boostcon

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