Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda] Help figuring out variable substitution, lazy functions, etc.? Should I be looking at Phoenix
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2009-08-06 14:46:58


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 <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_function.hpp>

using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
using namespace std;

struct exp__
{
    template<typename Arg>
    struct result{typedef Arg type;};

    template<typename Arg>
    Arg
    operator()(Arg arg) const
    {
        return std::exp(arg);
    }
};

struct sin__
{
    template<typename Arg>
    struct result{typedef Arg type;};

    template<typename Arg>
    Arg
    operator()(Arg arg) const
    {
        return std::sin(arg);
    }
};

function<sin__> const sin_=sin__();
function<exp__> const exp_=exp__();

int
main()
{
    double init[] = { 2, 10, 4, 5, 1, 6, 8, 3, 9, 7 };
    vector<double> c(init, init + 10);

    std::transform(init,init+10,c.begin(), exp_(sin_(arg1)) );
    return 0;
}

> cout << expectation( f( g(_x) ), dist);
>
> Thanks,
> -Jesse
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

>
>


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