It seems you need an inner_product algorithm.
#include <vector>
#include <functional>
#include <numeric>
#include <iostream>
struct my_plus
{
double operator()(int i, double d)
{
return d + i;
}
};
struct my_multiplies
{
double operator()(int i, double d)
{
return d * i;
}
};
int main()
{
std::vector<double> dubVec;
std::vector<int> intVec;
double result = 0;
dubVec.push_back(3.14);
intVec.push_back(1);
result = std::inner_product(intVec.begin(),
intVec.end(),
dubVec.begin(),
0.0,
my_plus(),
my_multiplies());
std::cout << result << std::endl;
}
I used my own functors, because I suspect the standard multiplies and plus expect both operands to be of similar type, but I might be wrong.