Which yields the trivial implementation:
#include <iostream>
#include <vector>
template<class Iterator, typename T, typename func_t>
typename Iterator::value_type reduce(Iterator start, Iterator end, T
init, func_t op )
{
typename Iterator::value_type answer = init;
for (; start != end; ++start)
{
answer = op(answer, *start);
}
return answer;
}
template<class Iterator, typename func_t>
typename Iterator::value_type reduce(Iterator start, Iterator end,
func_t op )
{
return reduce(start, end, typename Iterator::value_type{}, op);
}
int main()
{
const std::vector<double> array = { 1, 2, 3, 4};
double v = reduce(array.begin(), array.end(),
[](double a, double b){return a < b ? a : b;});
std::cout << "Result " << v << "\n";
return 0;
}
>>