// sample reduction function for a sum T sum_reduce(T a, T b) { return (b + a); } struct P { TAG tag; T value; }; vector

vect_scalar_sum(vector

v) { map sum; sum.reset(); for (int i=0; i < v.length(); i++) { sum[v[i].tag] = sum_reduce(v[i].value, sum[v[i].tag]); } vector

sum_vect; sum_vect.reset(); for (map::iterator it = sum.begin(); it != sum.end(); it++) { P tmp; tmp.tag = (*it).first; // STL map keeps the tag in a field called first tmp.value = (*it).second; // STL map keeps the value in a field called second sum_vect.push_back(tmp); } return sum_vect; }