#include <iostream>
#include <vector>
#include <string>
using namespace std;
template<typename Iterator>
typename std::iterator_traits<Iterator>::value_type Sum(Iterator beg, Iterator end)
{
typedef typename std::iterator_traits<Iterator>::value_type iter_traits_value;
iter_traits_value sum = iter_traits_value();
while(beg != end)
{
sum += *beg;
++beg;
}
return sum;
}
int main() {
int testArray[5] = {0,1,2,3,4};
vector<double> v = {0, 1, 2, 3, 4};
vector<string> s = {"hello", " ", "world"};
cout << Sum(v.begin(), v.end()), cout << endl;
cout << Sum(testArray, testArray + sizeof(testArray)/sizeof(testArray[0])), cout << endl;
cout << Sum(s.begin(), s.end()), cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8dHlwZW5hbWUgSXRlcmF0b3I+CnR5cGVuYW1lIHN0ZDo6aXRlcmF0b3JfdHJhaXRzPEl0ZXJhdG9yPjo6dmFsdWVfdHlwZSBTdW0oSXRlcmF0b3IgYmVnLCBJdGVyYXRvciBlbmQpCnsKCXR5cGVkZWYgdHlwZW5hbWUgc3RkOjppdGVyYXRvcl90cmFpdHM8SXRlcmF0b3I+Ojp2YWx1ZV90eXBlIGl0ZXJfdHJhaXRzX3ZhbHVlOwoJaXRlcl90cmFpdHNfdmFsdWUgc3VtID0gaXRlcl90cmFpdHNfdmFsdWUoKTsKCXdoaWxlKGJlZyAhPSBlbmQpCgl7CgkJc3VtICs9ICpiZWc7CgkJKytiZWc7Cgl9CglyZXR1cm4gc3VtOwp9CgppbnQgbWFpbigpIHsKCWludCB0ZXN0QXJyYXlbNV0gPSB7MCwxLDIsMyw0fTsKCXZlY3Rvcjxkb3VibGU+IHYgPSB7MCwgMSwgMiwgMywgNH07Cgl2ZWN0b3I8c3RyaW5nPiBzID0geyJoZWxsbyIsICIgIiwgIndvcmxkIn07CgkKCWNvdXQgPDwgU3VtKHYuYmVnaW4oKSwgdi5lbmQoKSksIGNvdXQgPDwgZW5kbDsKCWNvdXQgPDwgU3VtKHRlc3RBcnJheSwgdGVzdEFycmF5ICsgc2l6ZW9mKHRlc3RBcnJheSkvc2l6ZW9mKHRlc3RBcnJheVswXSkpLCBjb3V0IDw8IGVuZGw7Cgljb3V0IDw8IFN1bShzLmJlZ2luKCksIHMuZW5kKCkpLCBjb3V0IDw8IGVuZGw7CgkKCXJldHVybiAwOwp9