Boost logo

Boost Users :

From: me22 (me22.ca_at_[hidden])
Date: 2006-03-02 23:13:08


On 3/2/06, Meryl Silverburgh <silverburgh.meryl_at_[hidden]> wrote:
> Hi,
>
> I would like to know if I can use transform and lambda to add 2 int
> vector and save the result into a third int vector
>
> vector<int> src1;
> vector<int> src2;
>
> vector<int> result // put the value of src1 and src2
>

You could, but that's simple enough that you don't even need lambda:

assert( src1.size() == src2.size() );
result.resize( src1.size() );
std::transform( src1.begin(), src1.end(),
                src2.begin(),
                std::add<int>() );

The only thing lambda would do for you would be to let you say _1 + _2
instead of add<int>().

~ Scott


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