I have a function which takes another function as an argument:
T reduce(T* pBegin, T* pEnd, T(*operate)(T, T))
{
T temp = *pBegin;
for (T* p = pBegin + 1; p < pEnd; p++)
temp = operate(temp, *p);
return temp;
}
This is the way it is used:
int vec[] = { 12,14,6,-8 };
cout << reduce<int>(vec, vec + 4,
[](int x, int y){ return (x > y) ? x : y; }
);
Why is the function name []
? Is it because of the vec
array? Could it be something else?