Changeset 23 for trunk/lib/utility.h
 Timestamp:
 Jan 2, 2006, 9:14:57 AM (17 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/utility.h
r14 r23 6 6 #include <algorithm> 7 7 #include <functional> 8 #include <string> 8 9 #include <utility> 9 10 #include <vector> … … 12 13 namespace svnstat{ 13 14 14 15 16 17 18 19 20 21 22 23 24 const std::vector<T>& v) const25 26 if ( u.size() > v.size() ){27 28 29 30 31 }15 /// 16 /// Calculating sum of two vectors. 17 /// 18 /// @return resulting vector 19 /// 20 template <class T > 21 struct VectorPlus : 22 public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> > 23 { 24 std::vector<T> operator()(const std::vector<T>& u, 25 const std::vector<T>& v) const 26 { 27 if ( u.size() > v.size() ){ 28 std::vector<T> res(u.size()); 29 transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>()); 30 copy(u.begin()+v.size(), u.end(), res.begin()+v.size()); 31 return res; 32 } 32 33 33 std::vector<T> res(v.size());34 transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());35 if ( v.size() > u.size() )36 copy(u.begin()+v.size(), u.end(), res.begin()+v.size());37 return res;38 34 std::vector<T> res(v.size()); 35 transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>()); 36 if ( v.size() > u.size() ) 37 copy(v.begin()+u.size(), v.end(), res.begin()+u.size()); 38 return res; 39 } 39 40 40 41 }; 41 42 42 43 /// … … 44 45 /// 45 46 template <class Key, class T> 46 struct PairValuePlus : 47 public std::binary_function<std::vector<T>, 48 std::pair<const Key, std::vector<T> >, 49 std::vector<T> > 50 { 51 std::vector<T> operator()(const std::vector<T>& sum, 52 const std::pair<const Key,std::vector<T> >& p) 53 { 54 return VectorPlus<T>()(sum, p.second); 55 } 56 }; 47 struct PairValuePlus : 48 public std::binary_function<std::vector<T>, 49 std::pair<const Key, std::vector<T> >, 50 std::vector<T> > 51 { 52 std::vector<T> operator()(const std::vector<T>& sum, 53 const std::pair<const Key,std::vector<T> >& p) 54 { 55 return VectorPlus<T>()(sum, p.second); 56 } 57 }; 58 59 /// 60 struct CodingMore : 61 public std::binary_function<std::pair<std::string,std::vector<u_int> >, 62 std::pair<std::string,std::vector<u_int> >, 63 bool > 64 { 65 inline bool operator() 66 (const std::pair<std::string,std::vector<u_int> >& a, 67 const std::pair<std::string,std::vector<u_int> >& b) 68 { 69 if (a.second.back() > b.second.back()) 70 return true; 71 else if (a.second.back() < b.second.back()) 72 return false; 73 return a.first < b.first; 74 } 75 }; 76 57 77 }} 58 78 59 #endif // end of namespace svnstat end of namespace theplu 79 // end of namespace svnstat end of namespace theplu 80 #endif
Note: See TracChangeset
for help on using the changeset viewer.