Accumulate function in C++

You want to use the accumulate function of the <numeric> header in C++ to return the result of accumulating all the values in the range [first,last) to init.

Which of these code snippets is equivalent to the behaviour of the accumulate function?

Options
1.template <class InputIterator, class T>
 T accumulate (InputIterator first, InputIterator last, T init)
{
 while (first!=last) {
 init = init + *first; ++first;
 }
 return init;
}
2.template <class InputIterator, class T>
 T accumulate (InputIterator first, InputIterator last, T init)
{
 while (first!=last) {
 init=binary_op(init,*first)
 ++first;
 }
 return init;
}
3.Both 1 or 2

4.None of these

Related Posts

Close Bitnami banner
Bitnami