Boost logo

Boost Users :

Subject: Re: [Boost-users] Help with a boost::lambda problem and boost::array?
From: loadcom_at_[hidden]
Date: 2009-01-22 21:35:55


> Is there a solution?
>
> > > Does anyone have an idea why the following doesn't compile:
> > > using lambda::_1;
> > > using lambda::_2;
> > > boost::function<double (const boost::array<double, 2>&)> f =
> > > lambda::ret<double>(_1[0] * _1[1]);
> >
> > It probably fails because Boost.Lambda doesn't know how to find the
> > return type of the subscript operator for boost::array.
> >
> > In Christ,
> > Steven Watanabe

Let me answer my question:

the 'bind' version that works well:

        typedef boost::array<double, 2> array_t;
        typedef array_t::const_reference
(array_t::*func_t)(array_t::size_type) const;
        func_t subscript_f = &array_t::operator[];

        boost::function<double (const array_t&)> f;
        f = lambda::bind(std::multiplies<double>(),
                        lambda::bind(subscript_f, lambda::_1, 0),
                        lambda::bind(subscript_f, lambda::_1, 1));

Thank you all for your inspiration. And still open for better solutions.

B/Rgds
Max


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