CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/FWCore/Utilities/interface/Algorithms.h

Go to the documentation of this file.
00001 #ifndef FWCore_Utilities_Algorithms_h
00002 #define FWCore_Utilities_Algorithms_h
00003 
00004 #include <algorithm>
00005 
00006 namespace edm {
00007 
00011 
00013   template <typename ForwardSequence, typename Func>
00014   inline
00015   Func
00016   for_all(ForwardSequence& s, Func f) {
00017     return std::for_each(s.begin(), s.end(), f);
00018   }
00019 
00021   template <typename ForwardSequence, typename Func>
00022   inline
00023   Func
00024   copy_all(ForwardSequence& s, Func f) {
00025     return std::copy(s.begin(), s.end(), f);
00026   }
00027 
00029   template <typename ForwardSequence, typename Datum>
00030   inline
00031   typename ForwardSequence::const_iterator
00032   find_in_all(ForwardSequence const& s, Datum const& d) {
00033     return std::find(s.begin(), s.end(), d);
00034   }
00035 
00036   template <typename ForwardSequence, typename Datum>
00037   inline
00038   typename ForwardSequence::iterator
00039   find_in_all(ForwardSequence& s, Datum const& d) {
00040     return std::find(s.begin(), s.end(), d);
00041   }
00042 
00043   template <typename ForwardSequence, typename Datum>
00044   inline
00045   bool
00046   search_all(ForwardSequence const& s, Datum const& d) {
00047     return std::find(s.begin(), s.end(), d) != s.end();
00048   }
00049 
00051   template <typename ForwardSequence, typename Predicate>
00052   inline
00053   typename ForwardSequence::const_iterator
00054   find_if_in_all(ForwardSequence const& s, Predicate const& p) {
00055     return std::find_if(s.begin(), s.end(), p);
00056   }
00057 
00058   template <typename ForwardSequence, typename Predicate>
00059   inline
00060   typename ForwardSequence::iterator
00061   find_if_in_all(ForwardSequence& s, Predicate const& p) {
00062     return std::find_if(s.begin(), s.end(), p);
00063   }
00064 
00065   template <typename ForwardSequence, typename Predicate>
00066   inline
00067   bool
00068   search_if_in_all(ForwardSequence const& s, Predicate const& p) {
00069     return std::find_if(s.begin(), s.end(), p) != s.end();
00070   }
00071 
00073   template <typename ForwardSequence, typename Datum>
00074   inline
00075   bool
00076   binary_search_all(ForwardSequence const& s, Datum const& d) {
00077     return std::binary_search(s.begin(), s.end(), d);
00078   }
00079 
00080   template <typename ForwardSequence, typename Datum, typename Predicate>
00081   inline
00082   bool
00083   binary_search_all(ForwardSequence const& s, Datum const& d, Predicate p) {
00084     return std::binary_search(s.begin(), s.end(), d, p);
00085   }
00086 
00088   template <typename ForwardSequence, typename Datum>
00089   inline
00090   typename ForwardSequence::const_iterator
00091   lower_bound_all(ForwardSequence const& s, Datum const& d) {
00092     return std::lower_bound(s.begin(), s.end(), d);
00093   }
00094 
00095   template <typename ForwardSequence, typename Datum>
00096   inline
00097   typename ForwardSequence::iterator
00098   lower_bound_all(ForwardSequence& s, Datum const& d) {
00099     return std::lower_bound(s.begin(), s.end(), d);
00100   }
00101 
00102   template <typename ForwardSequence, typename Datum, typename Predicate>
00103   inline
00104   typename ForwardSequence::const_iterator
00105   lower_bound_all(ForwardSequence const& s, Datum const& d, Predicate p) {
00106     return std::lower_bound(s.begin(), s.end(), d, p);
00107   }
00108 
00109   template <typename ForwardSequence, typename Datum, typename Predicate>
00110   inline
00111   typename ForwardSequence::iterator
00112   lower_bound_all(ForwardSequence& s, Datum const& d, Predicate p) {
00113     return std::lower_bound(s.begin(), s.end(), d, p);
00114   }
00115 
00117   template <typename RandomAccessSequence>
00118   inline
00119   void
00120   sort_all(RandomAccessSequence & s) {
00121     std::sort(s.begin(), s.end());
00122   }
00123 
00124   template <typename RandomAccessSequence, typename Predicate>
00125   inline
00126   void
00127   sort_all(RandomAccessSequence & s, Predicate p) {
00128     std::sort(s.begin(), s.end(), p);
00129   }
00130 
00132   template <typename RandomAccessSequence>
00133   inline
00134   void
00135   stable_sort_all(RandomAccessSequence & s) {
00136     std::stable_sort(s.begin(), s.end());
00137   }
00138 
00139   template <typename RandomAccessSequence, typename Predicate>
00140   inline
00141   void
00142   stable_sort_all(RandomAccessSequence & s, Predicate p) {
00143     std::stable_sort(s.begin(), s.end(), p);
00144   }
00145 }
00146 #endif