| 976 | typename T |
| 977 | > |
| 978 | T make_sparse_vector ( |
| 979 | const T& v |
| 980 | ) |
| 981 | { |
| 982 | // You must use unsigned integral key types in your sparse vectors |
| 983 | typedef typename T::value_type::first_type idx_type; |
| 984 | typedef typename T::value_type::second_type value_type; |
| 985 | COMPILE_TIME_ASSERT(is_unsigned_type<idx_type>::value); |
| 986 | std::map<idx_type,value_type> temp; |
| 987 | for (typename T::const_iterator i = v.begin(); i != v.end(); ++i) |
| 988 | { |
| 989 | temp[i->first] += i->second; |
| 990 | } |
| 991 | |
| 992 | return T(temp.begin(), temp.end()); |
| 993 | } |
| 994 | |
| 995 | // ---------------------------------------------------------------------------------------- |
| 996 | |