Well, the stl is full of surprises!
I've changed all my code so that it uses transform instead of my overloaded operators:
Code:
transform(v2.begin(), v2.end(), v1.begin() + 1, v1.begin() +1, plus<int>());
That solves the problem of the two vectors not being equal in length as well.
A new question. I would like to multiply a vector by a number, e.g. 0.3 * (1, 2, 3, 4) would be (0.3, 0.6, 0.9, 1.2). If that 0.3 were a constant, I wouldn't have any problem but it has to change with every iteration. So the standard invocation is:
Code:
void multiply(float& elem)
{
return elem *= 0.3;
}
...
for_each(v1.begin(), v1.end(), multiply);
I tried changing it so that the 0.3 would actually be a variable, which the compiler just spit back out with relish:
Code:
void multiply(float& elem, float f_arg)
{
return elem *= f_arg;
}
...
for_each(v1.begin(), v2.end(), multiply(??????????)); //so how is this taken care of.
If neither for_each nor transform is the solution, could you point me to one?