
Hi all! I'm using the lambda library to compute the sum of squared differences, but I have encountered a puzzling problem. I would really appreciate if someone could explain it to me. This doesn't compile: std::inner_product(i1, i1+x, i2, 0.0, (_1 + _2), (_1*_1)(_1 - _2)); however, this does: std::inner_product(i1, i1+x, i2, 0.0, std::plus<double>(), (_1*_1)(_1 - _2)); The compiler message is very voluminous and hard to read. But I think this part might be of importance, the (double&, double) looks strange: /usr/include/c++/3.3/bits/stl_numeric.h:119: error: no match for call to `( boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambd a::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder <1>
, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >) (double&, double)' /usr/include/boost/lambda/detail/lambda_functors.hpp:142: error: candidates are: typename T::sig<boost::tuples::null_type>::type boost::lambda::lambda_functor<Base>::operator()() const [with T =
boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::la mbda::plus_action>, Many thanks in advance Anders Sundman

Anders Sundman <d00-asu@nada.kth.se> writes:
Hi all!
I'm using the lambda library to compute the sum of squared differences, but I have encountered a puzzling problem. I would really appreciate if someone could explain it to me.
This doesn't compile:
std::inner_product(i1, i1+x, i2, 0.0, (_1 + _2), (_1*_1)(_1 - _2));
however, this does:
std::inner_product(i1, i1+x, i2, 0.0, std::plus<double>(), (_1*_1)(_1 - _2)); ^^^^^^^^ ^
Doesn't seem right. Do you really mean to invoke the function call operator on the result of _1*_1 ?? -- Dave Abrahams Boost Consulting www.boost-consulting.com

On Tue, 30 Mar 2004, David Abrahams wrote:
Anders Sundman <d00-asu@nada.kth.se> writes:
Hi all!
I'm using the lambda library to compute the sum of squared differences, but I have encountered a puzzling problem. I would really appreciate if someone could explain it to me.
This doesn't compile:
std::inner_product(i1, i1+x, i2, 0.0, (_1 + _2), (_1*_1)(_1 - _2));
however, this does:
std::inner_product(i1, i1+x, i2, 0.0, std::plus<double>(), (_1*_1)(_1 - _2)); ^^^^^^^^ ^
Doesn't seem right. Do you really mean to invoke the function call operator on the result of _1*_1 ??
I might be missing something obvious, but i seems right to me. I'm trying to compute: sum((i1[i] - i2[i])^2). (_1*_1)(_1 - _2) computes the (i1[i] - i2[i])^2 part, and it seems to work fine. Then the first binary operator is applied to the result, so I think it's what I want. Here is a short program that demonstrates the problem: #include <iostream> #include <numeric> #include <boost/lambda/lambda.hpp> using namespace boost::lambda; int main(void) { double x1[] = {2.0, 1.0, 0.0, 3.0, 2.0}; double x2[] = {1.0, 2.0, 0.0, 1.0, -2.0}; /* double ssd = std::inner_product(x1, x1+5, x2, 0.0, std::plus<double>(), (_1*_1)(_1 - _2)); */ double ssd = std::inner_product(x1, x1+5, x2, 0.0, (_1 + _2), (_1*_1)(_1 - _2)); std::cout << "ssd: " << ssd << std::endl; return 0; } --- Best regards Anders Sundman
participants (2)
-
Anders Sundman
-
David Abrahams