00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_algorithm_H
00010 #define ThePEG_algorithm_H
00011
00019 #include "ThePEG/Config/ThePEG.h"
00020 #include <algorithm>
00021
00022 namespace ThePEG {
00023
00028 template <typename Iterator>
00029 struct IteratorRange: public std::pair<Iterator,Iterator> {
00030
00032 typedef std::pair<Iterator,Iterator> BaseType;
00033
00035 IteratorRange() {}
00036
00038 IteratorRange(const IteratorRange & ir): BaseType(ir) {}
00039
00042 IteratorRange(const BaseType & ir): BaseType(ir) {}
00043
00044 };
00045
00047 template <typename Container>
00048 inline IteratorRange<typename Container::iterator>
00049 range(Container & c) {
00050 return std::make_pair(c.begin(), c.end());
00051 }
00052
00055 template <typename Container>
00056 inline IteratorRange<typename Container::const_iterator>
00057 range(const Container & c) {
00058 return std::make_pair(c.begin(), c.end());
00059 }
00060
00063 template <typename Container>
00064 inline IteratorRange<typename Container::reverse_iterator>
00065 rrange(Container & c) {
00066 return std::make_pair(c.rbegin(), c.rend());
00067 }
00068
00071 template <typename Container>
00072 inline IteratorRange<typename Container::const_reverse_iterator>
00073 rrange(const Container & c) {
00074 return std::make_pair(c.rbegin(), c.rend());
00075 }
00076
00078 template <typename Iterator, typename FNC>
00079 inline FNC for_each(IteratorRange<Iterator> r, FNC f) {
00080 return std::for_each(r.first, r.second, f);
00081 }
00082
00084 template <typename Iterator, typename T>
00085 inline Iterator find(IteratorRange<Iterator> r, const T & t) {
00086 return std::find(r.first, r.second, t);
00087 }
00088
00090 template <typename Iterator, typename Pred>
00091 inline Iterator find_if(IteratorRange<Iterator> r, Pred p) {
00092 return std::find_if(r.first, r.second, p);
00093 }
00094
00096 template <typename Iterator, typename T>
00097 inline void replace(IteratorRange<Iterator> r, const T & oval, const T & nval) {
00098 return std::replace(r.first, r.second, oval, nval);
00099 }
00100
00102 template <typename Cont, typename FNC>
00103 inline FNC for_each(Cont & c, FNC f) {
00104 return std::for_each(c.begin(), c.end(), f);
00105 }
00106
00108 template <typename Cont, typename FNC>
00109 inline FNC for_each(const Cont & c, FNC f) {
00110 return std::for_each(c.begin(), c.end(), f);
00111 }
00112
00114 template <typename Cont, typename Type>
00115 inline typename Cont::iterator find(Cont & c, const Type & t) {
00116 return find(range(c), t);
00117 }
00118
00120 template <typename Cont, typename Type>
00121 inline typename Cont::const_iterator find(const Cont & c, const Type & t) {
00122 return find(range(c), t);
00123 }
00124
00126 template <typename Cont, typename Pred>
00127 inline typename Cont::iterator find_if(Cont & c, const Pred & p) {
00128 return find_if(range(c), p);
00129 }
00130
00132 template <typename Cont, typename Pred>
00133 inline typename Cont::const_iterator find_if(const Cont & c, const Pred & p) {
00134 return find_if(range(c), p);
00135 }
00136
00138 template <typename Cont, typename T>
00139 inline void replace(Cont & c, const T & oval, const T & nval) {
00140 return replace(range(c), oval, nval);
00141 }
00142
00143 }
00144
00145
00146 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
00147
00148 #endif
00149
00150 #endif