| 943 | typename T |
| 944 | > |
| 945 | T make_sparse_vector ( |
| 946 | const T& v |
| 947 | ) |
| 948 | { |
| 949 | // You must use unsigned integral key types in your sparse vectors |
| 950 | typedef typename T::value_type::first_type idx_type; |
| 951 | typedef typename T::value_type::second_type value_type; |
| 952 | COMPILE_TIME_ASSERT(is_unsigned_type<idx_type>::value); |
| 953 | std::map<idx_type,value_type> temp; |
| 954 | for (typename T::const_iterator i = v.begin(); i != v.end(); ++i) |
| 955 | { |
| 956 | temp[i->first] += i->second; |
| 957 | } |
| 958 | |
| 959 | return T(temp.begin(), temp.end()); |
| 960 | } |
| 961 | |
| 962 | // ---------------------------------------------------------------------------------------- |
| 963 | |