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