Help with a boost::lambda problem and boost::array?
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]); But the following does as a double-check: using lambda::_1; using lambda::_2; boost::function<double (const double&, const double&)> f2 = lambda::ret<double>(_1 * _2); Thanks, Jesse
On Wed, Jan 21, 2009 at 9:34 PM, <jesseperla@gmail.com> wrote:
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]);
I'm not sure about this, but you might try boost::function<double (const boost::array<double, 2>&)> f = lambda::ret<double>( var(_1)[0]*var(_1)[1] ); Also, I don't know if you need the ret<double> bit. Cheers Rob.
Hello Rob, Without testing, I don't think your version will get things better. B/Rgds Max From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Jones Sent: Thursday, January 22, 2009 6:20 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Help with a boost::lambda problem and boost::array? On Wed, Jan 21, 2009 at 9:34 PM, <jesseperla@gmail.com> wrote: 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]); I'm not sure about this, but you might try boost::function<double (const boost::array<double, 2>&)> f = lambda::ret<double>( var(_1)[0]*var(_1)[1] ); Also, I don't know if you need the ret<double> bit. Cheers Rob.
Hello jesse I've tested with this, but didn't work, neither. typedef boost::array<double, 2> array_t; boost::function<double (const array_t&)> f = lambda::bind(std::multiplies<double>(), lambda::bind(&array_t::operator[] const, lambda::_1, 0), lambda::bind(&array_t::operator[] const, lambda::_1, 1)); why? B/Rgds Max From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of jesseperla@gmail.com Sent: Thursday, January 22, 2009 5:35 AM To: Boost Users Mailing List Subject: [Boost-users] Help with a boost::lambda problem and boost::array? 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]); But the following does as a double-check: using lambda::_1; using lambda::_2; boost::function<double (const double&, const double&)> f2 = lambda::ret<double>(_1 * _2); Thanks, Jesse
AMDG Max wrote:
Hello jesse
I've tested with this, but didn't work, neither.
typedef boost::array<double, 2> array_t; boost::function<double (const array_t&)> f = lambda::bind(std::multiplies<double>(), lambda::bind(&array_t::operator[] const, lambda::_1, 0), lambda::bind(&array_t::operator[] const, lambda::_1, 1));
why?
Because this: &array_t::operator[] const is not legal syntax. In Christ, Steven Watanabe
I've tested with this, but didn't work, neither.
typedef boost::array<double, 2> array_t; boost::function<double (const array_t&)> f = lambda::bind(std::multiplies<double>(), lambda::bind(&array_t::operator[] const, lambda::_1, 0), lambda::bind(&array_t::operator[] const, lambda::_1, 1));
why?
Because this:
&array_t::operator[] const
is not legal syntax.
In Christ, Steven Watanabe
Thanks. Then how about typedef boost::array<double, 2> array_t; boost::function<double (const array_t&)> f = lambda::bind(std::multiplies<double>(), lambda::bind(&array_t::operator[], lambda::_1, 0), lambda::bind(&array_t::operator[], lambda::_1, 1)); ?
AMDG jesseperla@gmail.com wrote:
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
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
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
participants (5)
-
jesseperla@gmail.com
-
loadcom@sina.com
-
Max
-
Robert Jones
-
Steven Watanabe