|
Boost Users : |
Subject: Re: [Boost-users] [lambda] newbie: lambda to help in std::accumulate
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-01-25 08:51:51
2009/1/25 Micha³ Nowotka <mmmnow_at_[hidden]>:
> I want to compute sum of logarithms so i wrote:
>
> #include <cmath>
>
> double evaluate(const vector<double>& win_probabls)
> {
> return accumulate (win_probabls.begin(), win_probabls.end(), 0,
> lambda::_1 + log(lambda::_2) );
> }
>
> but this code doesn't compile. Does anyone know why?
>
> --
>
> Micha³ Nowotka
'log' is a function, so a call to it in a lambda expression has to be
within a bind expression:
double evaluate(const std::vector<double>& win_probabls)
{
using namespace boost::lambda;
return accumulate (win_probabls.begin(), win_probabls.end(), 0,
_1 + bind(log, _2) );
}
Stuart Dootson
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