thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
MaxCmp.h
1
// -*- C++ -*-
2
//
3
// MaxCmp.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_MaxCmp_H
10
#define THEPEG_MaxCmp_H
11
//
12
// This is the declaration of the MaxCmp class.
13
//
14
15
#include <functional>
16
17
namespace
ThePEG
{
18
30
template
<
typename
T =
double
,
typename
Indx =
int
,
typename
Cmp = std::greater<T> >
31
class
MaxCmp
{
32
33
public
:
34
38
MaxCmp
() :
init
(false),
max
(T()),
indx
(Indx()) {}
39
43
MaxCmp
(
const
T & t, Indx in = Indx()) :
init
(true),
max
(t),
indx
(in) {}
44
45
public
:
46
51
bool
operator()
(
const
T & t, Indx i = Indx())
52
{
53
if
( !
init
||
cmp
(t,
max
) ) {
54
max
= t;
55
init
=
true
;
56
indx
= i;
57
return
true
;
58
}
59
return
false
;
60
}
61
65
operator
const
T & ()
const
{
return
value
(); }
66
70
const
T &
value
()
const
{
return
max
; }
71
75
Indx
index
()
const
{
76
return
indx
;
77
}
78
82
bool
operator!
()
const
{
83
return
!
init
;
84
}
85
86
private
:
87
91
bool
init
;
92
96
T
max
;
97
101
Indx
indx
;
102
106
Cmp
cmp
;
107
108
};
109
113
template
<
typename
T,
typename
Indx =
int
>
114
class
MinCmp
:
public
MaxCmp
<T, Indx, less<T> > {
115
116
public
:
117
121
MinCmp
() {}
122
126
MinCmp
(
const
T & t, Indx in = Indx()) :
MaxCmp
<T, Indx, less<T> >(t, in) {}
127
128
};
129
130
}
131
132
#endif
/* THEPEG_MaxCmp_H */
ThePEG::MaxCmp
MaxCmp is a helper class to be used in a loop where one would like to keep track of the largest value...
Definition:
MaxCmp.h:31
ThePEG::MaxCmp::max
T max
The largest value seen so far.
Definition:
MaxCmp.h:96
ThePEG::MaxCmp::index
Indx index() const
Return the index of the largest object seen so far.
Definition:
MaxCmp.h:75
ThePEG::MaxCmp::operator!
bool operator!() const
Return true if no index has been chosen.
Definition:
MaxCmp.h:82
ThePEG::MaxCmp::init
bool init
True if a first value has been given;.
Definition:
MaxCmp.h:91
ThePEG::MaxCmp::indx
Indx indx
The index for the largest value seen so far.
Definition:
MaxCmp.h:101
ThePEG::MaxCmp::MaxCmp
MaxCmp(const T &t, Indx in=Indx())
Constructor specifying an initial maximum value, t.
Definition:
MaxCmp.h:43
ThePEG::MaxCmp::cmp
Cmp cmp
The comparison object to be used.
Definition:
MaxCmp.h:106
ThePEG::MaxCmp::value
const T & value() const
Return the largest value so far.
Definition:
MaxCmp.h:70
ThePEG::MaxCmp::MaxCmp
MaxCmp()
The default constructor.
Definition:
MaxCmp.h:38
ThePEG::MaxCmp::operator()
bool operator()(const T &t, Indx i=Indx())
If t is the largest value seen so far return true.
Definition:
MaxCmp.h:51
ThePEG::MinCmp
Special calss for Minimum comparisons.
Definition:
MaxCmp.h:114
ThePEG::MinCmp::MinCmp
MinCmp(const T &t, Indx in=Indx())
Constructors are not inherited.
Definition:
MaxCmp.h:126
ThePEG::MinCmp::MinCmp
MinCmp()
Constructors are not inherited.
Definition:
MaxCmp.h:121
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6