- Timestamp:
- Oct 5, 2010, 2:42:30 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Functor.h
r1203 r1204 153 153 }; 154 154 155 /// 156 /// Calculating sum of two vectors. 157 /// 158 /// @return resulting vector 159 /// 160 template <typename T > 161 struct VectorPlus : 162 public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> > 163 { 164 std::vector<T> operator()(const std::vector<T>& u, 165 const std::vector<T>& v) const 166 { 167 std::vector<T> res; 168 res.reserve(std::max(u.size(), v.size())); 169 std::back_insert_iterator<std::vector<T> > inserter(res); 170 if ( u.size() > v.size() ){ 171 std::transform(v.begin(), v.end(), u.begin(), inserter, std::plus<T>()); 172 std::copy(u.begin()+v.size(), u.end(), inserter); 173 } 174 else { 175 std::transform(u.begin(), u.end(), v.begin(), inserter, std::plus<T>()); 176 std::copy(v.begin()+u.size(), v.end(), inserter); 177 } 178 return res; 179 } 155 /** 156 Functor perfoming plus assignment on first argument using second argument 180 157 181 }; 182 183 /// 184 /// @return resulting vector 185 /// 186 template <typename Key, typename T> 187 struct PairValuePlus : 188 public std::binary_function<T, std::pair<const Key, T>, T> 189 { 190 T operator()(const T& sum, const std::pair<const Key, T>& p) 191 { 192 return sum + p.second; 193 } 194 }; 195 196 158 arg1 += arg2.second 159 */ 197 160 template <typename Key, typename T> 198 161 struct PairValuePlusAssign :
Note: See TracChangeset
for help on using the changeset viewer.