[lambda] Help figuring out variable substitution, lazy functions, etc.? Should I be looking at Phoenix
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? 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? Thanks, Jesse
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
On Aug 3, 11:35 am, Steven Watanabe
AMDG Phoenixallows lazy functions like this
struct first_moment_type { typedef double result_type; double operator()(double arg) { return x; }
};
phoenix::function
first_moment;
Thanks as always Steven,
What is the general thinking on lambda vs. phoenix 2 vs. phoenix 3?
Do we expect phoenix 3 to be the main lambda library in boost
(eventually)? Should I start getting comfortable with Phoenix 2 to
prepare for it or might Phoenix 3 be radically different?
Also, I can't figure out in phoenix how I would have lazy operator()
on already constructed functors. Is this possible?
The main use case of this is to use an expectation operator over an
interpolator:
--------------------------------------------
template
Jesse Perla schrieb:
Thanks as always Steven, What is the general thinking on lambda vs. phoenix 2 vs. phoenix 3? Do we expect phoenix 3 to be the main lambda library in boost (eventually)? Should I start getting comfortable with Phoenix 2 to prepare for it or might Phoenix 3 be radically different?
Also, I can't figure out in phoenix how I would have lazy operator() on already constructed functors. Is this possible?
Not sure, what you want. If you want to bind functor this is possible
with phoenix.
Hre is a code to illustrate this.
#include <vector>
#include <algorithm>
#include <cmath>
#include
cout << expectation( f( g(_x) ), dist);
Thanks, -Jesse _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Jesse Perla
-
Kim Kuen Tang
-
Steven Watanabe