Hi,

what you write looks great. You are definitely sending me back to the drawing board
here. I am going to need some time out in order to study your example and tie this up
with the doc. I will write again later.

What I have in mind is pretty much what I wrote. That example is a typical application.
When I wrote this, what I had in mind was defining an objective function for use in an
optimization problem. So there h and g would be constant functions of a vector.

Thanks for your help,
ChrisK

> Date: Sun, 29 Nov 2009 19:14:52 -0700
> From: overminddl1@gmail.com
> To: boost-users@lists.boost.org
> Subject: Re: [Boost-users] Two questions on boost::function
>
> On Sun, Nov 29, 2009 at 10:27 AM, CR Koudella <ckoudell@hotmail.com> wrote:
> > Thanks for your reply on this, too. Yes, I am beginning to look into
> > phoenix.
> > Here too, it would be of great help if you could indicate to me how you
> > would
> > handle my example with phoenix.
>
> Since you have code in this one I should be able to come up with a
> phoenix example:
>
> // Assume this line everywhere:
> using namespace boost::phoenix;
>
> // For doing h*(f-g)^2 generically in phoenix:
> auto func1 = _3*(_1-_2)*(_1-_2);
> // Or more 'optimized' as this (which the compiler may optimize the
> above just fine as well, but this demonstrates local vars):
> auto func1 = let(_a=(_1-_2))[_3*_a*_a];
>
> // Results in this:
> func1(3,2,1) -> 1
> func1(6,4,2) -> 8
> ... etc
>
> That barely demonstrates the surface of phoenix. Phoenix practically
> rewrites C++ in C++ in a lazy form, very powerful, but that should
> give you an example. As for your nasty binds in binds in binds in
> etc... Maybe this?
>
> // Supposing f, g, and h are static functions and there is only one
> variable passed in (phoenix cares not what type it is, as long as
> f/g/h can resolve it), you were not really clear on exactly what your
> code is supposed to do.
> auto bfoWRF = let(_a=(bind(&f, _1)-bind(&g, _1)))[bind(&h, _1)*_a*_a]
>
> // In which case if you have this:
> std::vector v = {...}
> // and you call this:
> auto value = bfoWRF(v);
> // then it does the same thing as this non-lazy code:
> auto a = f(v)-g(v);
> auto value = h(v)*a*a;
>
> And yes, you can combine different returns just fine as long as they
> obey the normal non-lazy C++ rules.
>
>
> P.S. If you want to assign bfoWRF to a boost function, it will be as
> you may think:
> boost::function<double(const std::vector<double> &)> bfoWRF =
> let(_a=(bind(&f, _1)-bind(&g, _1)))[bind(&h, _1)*_a*_a]
>
> However, if you leave it as auto (or use BOOST_AUTO for old compiler
> support) then it will work on any arbitrary type that would work in
> the non-lazy version of the code without requiring that everything be
> doubles.
>
> If you clarify your example some more then I can re-demonstrate as well.
> _______________________________________________
> Boost-users mailing list
> Boost-users@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/boost-users