Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda] Help figuring out variable substitution, lazy functions, etc.? Should I be looking at Phoenix
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-08-03 11:35:57


AMDG

Jesse Perla wrote:
> I have been trying to prevent variable substitution with boost::lambda and
> cannot figure out how to prevent variable substitution.
>
> Here is a (simplified) version:
> double first_moment(double x)
> {
> return x;
> }
>
> //And create a function
> auto myfunc = first_moment(_1);
> cout << myfunc(2.0);
>
> ... This doesn't compile, and every permutation I can think of using
> protect, etc. fails as well.
>
> Now I realize that this looks like a job for "bind" (which works fine of
> course) but this is a simplified pattern of the notation I want. Is there
> any way to do this with protect, unlambda, etc. around the _1?
>

No. There is no way to make this work by manipulating the _1.

> Are other libraries like Phoenix a better place to look for this kind of
> functionality? Do people see Phoenix as the evolution of boost lambda or
> are these likely to remain in parallel? Should I stick with C++0X lambdas?
>

Phoenix allows lazy functions like this

struct first_moment_type {
    typedef double result_type;
    double operator()(double arg) {
        return x;
    }
};

phoenix::function<first_moment_type> first_moment;

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