The following code example is taken from the book
 
  C++ Templates - The Complete Guide
 by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002
 
  © Copyright David Vandevoorde and Nicolai M. Josuttis 2002
#ifndef LOOP1_HPP
#define LOOP1_HPP
template <typename T>
inline T dot_product (int dim, T* a, T* b)
{
    T result = T();
    for (int i=0; i<dim; ++i) { 
        result += a[i]*b[i];
    }
    return result;
}
#endif // LOOP1_HPP