Changeset 1203
- Timestamp:
- Oct 5, 2010, 2:33:57 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Functor.h
r1194 r1203 194 194 }; 195 195 196 197 template <typename Key, typename T> 198 struct PairValuePlusAssign : 199 public std::binary_function<T&, const std::pair<const Key, T>&, void> 200 { 201 T operator()(T& x, const std::pair<const Key, T>& p) 202 { 203 x += p.second; 204 } 205 }; 206 207 208 /** 209 T1 must be mutable 210 */ 211 template<typename T1, typename T2> 212 struct PlusAssign : public std::binary_function<T1, T2, void> 213 { 214 void operator()(T1 t1, T2 t2) const 215 { t1+=t2; } 216 }; 217 196 218 }} // end of namespace svndigest end of namespace theplu 197 219 -
trunk/lib/Stats.cc
r1201 r1203 372 372 // keys are equivalent 373 373 else { 374 first2->second = first1->second + first2->second;374 first2->second += first1->second; 375 375 ++first1; 376 376 ++first2; … … 474 474 vec_type::iterator j(i); 475 475 i+=authskip; 476 SumVector init; 477 SumVector others = 478 std::accumulate(j, i, init, PairValuePlus<std::string, SumVector>()); 476 SumVector others; 477 sum(j, i, others, PairValuePlusAssign<std::string, SumVector>()); 479 478 unsigned char r, g, b; 480 479 std::string label("others"); -
trunk/lib/Vector.h
r1196 r1203 201 201 }; 202 202 203 template<typename T, class Policy>204 Vector<T, Policy> operator+(const Vector<T, Policy>& lhs,205 const Vector<T, Policy>& rhs)206 {207 Vector<T, Policy> result(lhs);208 result+=rhs;209 assert(result.size()>=lhs.size());210 assert(result.size()>=rhs.size());211 return result;212 }213 214 215 203 template<typename T> 216 204 class SparsePolicy -
trunk/lib/utility.h
r1186 r1203 24 24 along with svndigest. If not, see <http://www.gnu.org/licenses/>. 25 25 */ 26 27 #include "Functor.h" 26 28 27 29 #include <algorithm> … … 212 214 time_t str2time(const std::string&); 213 215 216 /** 217 same as sum(3) but using binary(result, *first) rather than 218 result += *first 219 */ 220 template<typename InputIterator, typename T, typename BinaryOperation> 221 void sum(InputIterator first, InputIterator last, T& result, 222 BinaryOperation binary) 223 { 224 for (; first!=last; ++first) 225 binary(result, *first); 226 } 227 228 /** 229 Add all values of [first, last) to result 230 */ 231 template<typename InputIterator, typename T> 232 void sum(InputIterator first, InputIterator last, T& result) 233 { 234 typedef typename std::iterator_traits<InputIterator>::const_reference ref; 235 typedef PlusAssign<T&, ref> binary; 236 return sum(first, last, result, binary()); 237 } 238 214 239 /// 215 240 /// If file does not exist create empty file. -
trunk/test/vector.cc
r1196 r1203 65 65 } 66 66 67 suite.out() << "testing operator+\n";68 vec3 = vec + vec2;69 if (vec3.size()!=8) {70 suite.add(false);71 suite.out() << "incorrect size: " << vec3.size() << " expected: "72 << 8 << "\n";73 }74 for (size_t i=0; i<8; ++i)75 if (!suite.add(vec3[5]==vec[5]+vec2[5]))76 suite.out() << "operator+ failed: result: " << vec3[i]77 << " expected: " << vec[i] + vec2[i] << "\n";78 79 67 suite.out() << "testing back()\n"; 80 68 vec.resize(0);
Note: See TracChangeset
for help on using the changeset viewer.