The overload of std::transform
that takes a binary functor takes four iterators, not three, since it operates on two input ranges, and not one. For example:
#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
int fun2(int i,int j)
{
return i+j;
}
int main()
{
using namespace std::placeholders;
std::vector<int> v1={1,2,3,4,5,6,6,7};
std::vector<int> v2;
std::transform(v1.begin(), v1.end(), v1.begin(),
std::back_inserter(v2), std::bind(fun2,_1,_2));
for (const auto& i : v2)
std::cout << i << " ";
std::cout << std::endl;
}
Of course, in real life you wouldn't use std::bind
here.