thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
algorithm.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// algorithm.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_algorithm_H
10#define ThePEG_algorithm_H
11
20#include <algorithm>
21
22namespace ThePEG {
23
28template <typename Iterator>
29struct IteratorRange: public std::pair<Iterator,Iterator> {
30
32 typedef std::pair<Iterator,Iterator> BaseType;
33
36
39
42 IteratorRange(const BaseType & ir): BaseType(ir) {}
43
44};
45
47template <typename Container>
48inline IteratorRange<typename Container::iterator>
49range(Container & c) {
50 return std::make_pair(c.begin(), c.end());
51}
52
55template <typename Container>
56inline IteratorRange<typename Container::const_iterator>
57range(const Container & c) {
58 return std::make_pair(c.begin(), c.end());
59}
60
63template <typename Container>
64inline IteratorRange<typename Container::reverse_iterator>
65rrange(Container & c) {
66 return std::make_pair(c.rbegin(), c.rend());
67}
68
71template <typename Container>
72inline IteratorRange<typename Container::const_reverse_iterator>
73rrange(const Container & c) {
74 return std::make_pair(c.rbegin(), c.rend());
75}
76
78template <typename Iterator, typename FNC>
79inline FNC for_each(IteratorRange<Iterator> r, FNC f) {
80 return std::for_each(r.first, r.second, f);
81}
82
84template <typename Iterator, typename T>
85inline Iterator find(IteratorRange<Iterator> r, const T & t) {
86 return std::find(r.first, r.second, t);
87}
88
90template <typename Iterator, typename Pred>
91inline Iterator find_if(IteratorRange<Iterator> r, Pred p) {
92 return std::find_if(r.first, r.second, p);
93}
94
96template <typename Iterator, typename T>
97inline void replace(IteratorRange<Iterator> r, const T & oval, const T & nval) {
98 return std::replace(r.first, r.second, oval, nval);
99}
100
102template <typename Cont, typename FNC>
103inline FNC for_each(Cont & c, FNC f) {
104 return std::for_each(c.begin(), c.end(), f);
105}
106
108template <typename Cont, typename FNC>
109inline FNC for_each(const Cont & c, FNC f) {
110 return std::for_each(c.begin(), c.end(), f);
111}
112
114template <typename Cont, typename Type>
115inline typename Cont::iterator find(Cont & c, const Type & t) {
116 return find(range(c), t);
117}
118
120template <typename Cont, typename Type>
121inline typename Cont::const_iterator find(const Cont & c, const Type & t) {
122 return find(range(c), t);
123}
124
126template <typename Cont, typename Pred>
127inline typename Cont::iterator find_if(Cont & c, const Pred & p) {
128 return find_if(range(c), p);
129}
130
132template <typename Cont, typename Pred>
133inline typename Cont::const_iterator find_if(const Cont & c, const Pred & p) {
134 return find_if(range(c), p);
135}
136
138template <typename Cont, typename T>
139inline void replace(Cont & c, const T & oval, const T & nval) {
140 return replace(range(c), oval, nval);
141}
142
143}
144
145// #include "algorithm.icc"
146#ifndef ThePEG_TEMPLATES_IN_CC_FILE
147// #include "algorithm.tcc"
148#endif
149
150#endif /* ThePEG_algorithm_H */
This is the main config header file for ThePEG.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Iterator find_if(IteratorRange< Iterator > r, Pred p)
The std::find_if function taking an IteratorRange as argument.
Definition: algorithm.h:91
void replace(IteratorRange< Iterator > r, const T &oval, const T &nval)
The std::replace function taking an IteratorRange as argument.
Definition: algorithm.h:97
IteratorRange< typename Container::iterator > range(Container &c)
Return an IteratorRange corresponding to the whole container.
Definition: algorithm.h:49
IteratorRange< typename Container::reverse_iterator > rrange(Container &c)
Return an IteratorRange of reverse iterators corresponding to the whole container.
Definition: algorithm.h:65
Iterator find(IteratorRange< Iterator > r, const T &t)
The std::find function taking an IteratorRange as argument.
Definition: algorithm.h:85
FNC for_each(IteratorRange< Iterator > r, FNC f)
The std::for_each function taking an IteratorRange as argument.
Definition: algorithm.h:79
A pair of iterators to be used in specialized algorithms instead of the standard first,...
Definition: algorithm.h:29
IteratorRange()
Default constructor.
Definition: algorithm.h:35
std::pair< Iterator, Iterator > BaseType
The underlying representation.
Definition: algorithm.h:32
IteratorRange(const IteratorRange &ir)
Copy constructor.
Definition: algorithm.h:38
IteratorRange(const BaseType &ir)
Constructor taking the underlying pair representation as argument.
Definition: algorithm.h:42