algorithm to add values of two ranges and place them into a third one

前端 未结 4 1987
说谎
说谎 2021-01-18 05:03

I was just wondering if there was anything (either in c++11 or boost) that could help me do something like this:

std::vector v1 = {1, 2, 3};
std::         


        
4条回答
  •  囚心锁ツ
    2021-01-18 05:54

    You can use the 5 parameter overload of std::transform for this. This takes a binary functor to operate on pairs of elements of two ranges:

    std::transform(v1.begin(), 
                   v1.end(), 
                   v2.begin(), 
                   back_inserter(res), 
                   std::plus());
    

提交回复
热议问题