File indexing completed on 2026-08-06 09:38:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ThePEG_algorithm_H
0010 #define ThePEG_algorithm_H
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "ThePEG/Config/ThePEG.h"
0020 #include <algorithm>
0021
0022 namespace ThePEG {
0023
0024
0025
0026
0027
0028 template <typename Iterator>
0029 struct IteratorRange: public std::pair<Iterator,Iterator> {
0030
0031
0032 typedef std::pair<Iterator,Iterator> BaseType;
0033
0034
0035 IteratorRange() {}
0036
0037
0038 IteratorRange(const IteratorRange & ir): BaseType(ir) {}
0039
0040
0041
0042 IteratorRange(const BaseType & ir): BaseType(ir) {}
0043
0044 };
0045
0046
0047 template <typename Container>
0048 inline IteratorRange<typename Container::iterator>
0049 range(Container & c) {
0050 return std::make_pair(c.begin(), c.end());
0051 }
0052
0053
0054
0055 template <typename Container>
0056 inline IteratorRange<typename Container::const_iterator>
0057 range(const Container & c) {
0058 return std::make_pair(c.begin(), c.end());
0059 }
0060
0061
0062
0063 template <typename Container>
0064 inline IteratorRange<typename Container::reverse_iterator>
0065 rrange(Container & c) {
0066 return std::make_pair(c.rbegin(), c.rend());
0067 }
0068
0069
0070
0071 template <typename Container>
0072 inline IteratorRange<typename Container::const_reverse_iterator>
0073 rrange(const Container & c) {
0074 return std::make_pair(c.rbegin(), c.rend());
0075 }
0076
0077
0078 template <typename Iterator, typename FNC>
0079 inline FNC for_each(IteratorRange<Iterator> r, FNC f) {
0080 return std::for_each(r.first, r.second, f);
0081 }
0082
0083
0084 template <typename Iterator, typename T>
0085 inline Iterator find(IteratorRange<Iterator> r, const T & t) {
0086 return std::find(r.first, r.second, t);
0087 }
0088
0089
0090 template <typename Iterator, typename Pred>
0091 inline Iterator find_if(IteratorRange<Iterator> r, Pred p) {
0092 return std::find_if(r.first, r.second, p);
0093 }
0094
0095
0096 template <typename Iterator, typename T>
0097 inline void replace(IteratorRange<Iterator> r, const T & oval, const T & nval) {
0098 return std::replace(r.first, r.second, oval, nval);
0099 }
0100
0101
0102 template <typename Cont, typename FNC>
0103 inline FNC for_each(Cont & c, FNC f) {
0104 return std::for_each(c.begin(), c.end(), f);
0105 }
0106
0107
0108 template <typename Cont, typename FNC>
0109 inline FNC for_each(const Cont & c, FNC f) {
0110 return std::for_each(c.begin(), c.end(), f);
0111 }
0112
0113
0114 template <typename Cont, typename Type>
0115 inline typename Cont::iterator find(Cont & c, const Type & t) {
0116 return find(range(c), t);
0117 }
0118
0119
0120 template <typename Cont, typename Type>
0121 inline typename Cont::const_iterator find(const Cont & c, const Type & t) {
0122 return find(range(c), t);
0123 }
0124
0125
0126 template <typename Cont, typename Pred>
0127 inline typename Cont::iterator find_if(Cont & c, const Pred & p) {
0128 return find_if(range(c), p);
0129 }
0130
0131
0132 template <typename Cont, typename Pred>
0133 inline typename Cont::const_iterator find_if(const Cont & c, const Pred & p) {
0134 return find_if(range(c), p);
0135 }
0136
0137
0138 template <typename Cont, typename T>
0139 inline void replace(Cont & c, const T & oval, const T & nval) {
0140 return replace(range(c), oval, nval);
0141 }
0142
0143 }
0144
0145
0146 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
0147
0148 #endif
0149
0150 #endif