thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Config
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
19
#include "
ThePEG/Config/ThePEG.h
"
20
#include <algorithm>
21
22
namespace
ThePEG
{
23
28
template
<
typename
Iterator>
29
struct
IteratorRange
:
public
std::pair<Iterator,Iterator> {
30
32
typedef
std::pair<Iterator,Iterator>
BaseType
;
33
35
IteratorRange
() {}
36
38
IteratorRange
(
const
IteratorRange
& ir):
BaseType
(ir) {}
39
42
IteratorRange
(
const
BaseType
& ir):
BaseType
(ir) {}
43
44
};
45
47
template
<
typename
Container>
48
inline
IteratorRange<typename Container::iterator>
49
range
(Container & c) {
50
return
std::make_pair(c.begin(), c.end());
51
}
52
55
template
<
typename
Container>
56
inline
IteratorRange<typename Container::const_iterator>
57
range
(
const
Container & c) {
58
return
std::make_pair(c.begin(), c.end());
59
}
60
63
template
<
typename
Container>
64
inline
IteratorRange<typename Container::reverse_iterator>
65
rrange
(Container & c) {
66
return
std::make_pair(c.rbegin(), c.rend());
67
}
68
71
template
<
typename
Container>
72
inline
IteratorRange<typename Container::const_reverse_iterator>
73
rrange
(
const
Container & c) {
74
return
std::make_pair(c.rbegin(), c.rend());
75
}
76
78
template
<
typename
Iterator,
typename
FNC>
79
inline
FNC
for_each
(
IteratorRange<Iterator>
r, FNC f) {
80
return
std::for_each(r.first, r.second, f);
81
}
82
84
template
<
typename
Iterator,
typename
T>
85
inline
Iterator
find
(
IteratorRange<Iterator>
r,
const
T & t) {
86
return
std::find(r.first, r.second, t);
87
}
88
90
template
<
typename
Iterator,
typename
Pred>
91
inline
Iterator
find_if
(
IteratorRange<Iterator>
r, Pred p) {
92
return
std::find_if(r.first, r.second, p);
93
}
94
96
template
<
typename
Iterator,
typename
T>
97
inline
void
replace
(
IteratorRange<Iterator>
r,
const
T & oval,
const
T & nval) {
98
return
std::replace(r.first, r.second, oval, nval);
99
}
100
102
template
<
typename
Cont,
typename
FNC>
103
inline
FNC
for_each
(Cont & c, FNC f) {
104
return
std::for_each(c.begin(), c.end(), f);
105
}
106
108
template
<
typename
Cont,
typename
FNC>
109
inline
FNC
for_each
(
const
Cont & c, FNC f) {
110
return
std::for_each(c.begin(), c.end(), f);
111
}
112
114
template
<
typename
Cont,
typename
Type>
115
inline
typename
Cont::iterator
find
(Cont & c,
const
Type & t) {
116
return
find
(
range
(c), t);
117
}
118
120
template
<
typename
Cont,
typename
Type>
121
inline
typename
Cont::const_iterator
find
(
const
Cont & c,
const
Type & t) {
122
return
find
(
range
(c), t);
123
}
124
126
template
<
typename
Cont,
typename
Pred>
127
inline
typename
Cont::iterator
find_if
(Cont & c,
const
Pred & p) {
128
return
find_if
(
range
(c), p);
129
}
130
132
template
<
typename
Cont,
typename
Pred>
133
inline
typename
Cont::const_iterator
find_if
(
const
Cont & c,
const
Pred & p) {
134
return
find_if
(
range
(c), p);
135
}
136
138
template
<
typename
Cont,
typename
T>
139
inline
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 */
ThePEG.h
This is the main config header file for ThePEG.
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::find_if
Iterator find_if(IteratorRange< Iterator > r, Pred p)
The std::find_if function taking an IteratorRange as argument.
Definition:
algorithm.h:91
ThePEG::replace
void replace(IteratorRange< Iterator > r, const T &oval, const T &nval)
The std::replace function taking an IteratorRange as argument.
Definition:
algorithm.h:97
ThePEG::range
IteratorRange< typename Container::iterator > range(Container &c)
Return an IteratorRange corresponding to the whole container.
Definition:
algorithm.h:49
ThePEG::rrange
IteratorRange< typename Container::reverse_iterator > rrange(Container &c)
Return an IteratorRange of reverse iterators corresponding to the whole container.
Definition:
algorithm.h:65
ThePEG::find
Iterator find(IteratorRange< Iterator > r, const T &t)
The std::find function taking an IteratorRange as argument.
Definition:
algorithm.h:85
ThePEG::for_each
FNC for_each(IteratorRange< Iterator > r, FNC f)
The std::for_each function taking an IteratorRange as argument.
Definition:
algorithm.h:79
ThePEG::IteratorRange
A pair of iterators to be used in specialized algorithms instead of the standard first,...
Definition:
algorithm.h:29
ThePEG::IteratorRange::IteratorRange
IteratorRange()
Default constructor.
Definition:
algorithm.h:35
ThePEG::IteratorRange::BaseType
std::pair< Iterator, Iterator > BaseType
The underlying representation.
Definition:
algorithm.h:32
ThePEG::IteratorRange::IteratorRange
IteratorRange(const IteratorRange &ir)
Copy constructor.
Definition:
algorithm.h:38
ThePEG::IteratorRange::IteratorRange
IteratorRange(const BaseType &ir)
Constructor taking the underlying pair representation as argument.
Definition:
algorithm.h:42
Generated on Thu Jun 20 2024 14:47:00 for ThePEG by
1.9.6