Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: Yechezkel Mett (ymett.on.boost_at_[hidden])
Date: 2011-03-27 09:34:57


On Sun, Mar 27, 2011 at 12:19 AM, Lorenzo Caminiti
<lorcaminiti_at_[hidden]> wrote:
> Hello all,
>
> I am updating Boost.Local docs and I could use a some help in getting
> the Alternatives section right
> http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Alternatives.html
> .
>
> How can I program the following code (its local function and `factor`
> constant binding) using Boost.Phoenix, Boost.Lambda, and C++0x lambda
> functions? If you know, can you please reply with the actual code?

C++0x lambdas:

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
   double sum = 0.0;
   int factor = 10;

   std::vector<double> v(3);
   v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
   std::for_each(v.begin(), v.end(), [&](double num){
       sum += factor * num;
       std::cout << "Summed: " << sum << std::endl;
   });
   return 0;
}

Yechezkel Mett


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk