Use Iter with array : template iterators « STL Algorithms Iterator « C++ Tutorial






#include <iostream>
#include <vector> 
using std::cout;
using std::endl;
using std::vector;

template <typename Iter> 
double vectorSum(Iter begin, Iter end) {
  double sum = 0.0;
  
  while( begin != end )
    sum += *begin++;
  return sum;        
} 

int main() {
  double temperature[] = { 10.5, 20.0, 8.5 }; 
  cout << "array vectorSum = " 
       << vectorSum(temperature,temperature+sizeof temperature/sizeof temperature[0]) 
       << endl;

  return 0;
}
array vectorSum = 39








30.7.template iterators
30.7.1.Computing the sum with template iterators
30.7.2.Use Iter with array