Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda] Can I use lambda::bind to a functor with a parametric return type?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-08-28 13:49:14


AMDG

Jesse Perla wrote:
> Thanks for the rapid response on the previous question. Now for my real
> question:
>
> I am using an autodifferentiation library and want to use lambda's bind, but
> still return a generic type. Is this possible?
>
> Here is the function I wrote :
>
> struct test_function_impl
> {
> //result_of supprt
> template<typename Sig>
> struct result;
> template<typename This, typename Arg1, typename Arg2>
> struct result<This(Arg1, Arg2)> {
> typedef typename boost::remove_reference<Arg1>::type::value_type
> type;
> };
>
>
> template<typename Vector, typename IntT>
> typename Vector::value_type //The type in the vector... can be a double
> or AD type
> operator()(const Vector& x, IntT y) const{
> return x[0] * x[0] + y;
> }
> };
>
>
> The function works on its own, and now std::tr1::result_of seems to work as
> well.
>
> However, I cannot bind to this:
> using namespace boost::lambda;
> ublas::bounded_vector<double, 1> x;
> x[0] = 1.0;
> int int_value = 1;
>
> //THIS FAILS! Not sure if lambda's bind is using result_of? Obviously,
> can't use the ret<> approach here.
> auto f = bind(test_function_impl(), _1, int_value);
>
>
> Does lambda support this usage, or should I turn to Phoenix (if so, I am
> recognizing a trend here).
>

Boost.Lambda uses its own protocol.

struct test_function_impl {
    template<class Args>
    struct sig {
        typedef typename boost::tuples::element<Args,
1>::type::value_type type;
    };
};

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