Say I have the following:
int a[] = { 1, 2, 3, 4, 5 };
int x = something;
It is possible to use for_each
to increment the elements of the array by x? I was thinking of something like:
for_each(a, a + 5, [](int& item) { item += x; });
But as far as I understand, the third parameter in for_each
is a unary function so there's no way to pass x into it.