ThePEG
1.8.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Utilities
MaxCmp.h
1
// -*- C++ -*-
2
//
3
// MaxCmp.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2011 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 2 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
79
private
:
80
84
bool
init
;
85
89
T
max
;
90
94
Indx
indx
;
95
99
Cmp
cmp
;
100
101
};
102
106
template
<
typename
T,
typename
Indx =
int
>
107
class
MinCmp
:
public
MaxCmp
<T, Indx, less<T> > {
108
109
public
:
110
114
MinCmp
() {}
115
119
MinCmp
(
const
T & t, Indx in = Indx()) :
MaxCmp
<T, Indx, less<T> >(t, in) {}
120
121
};
122
123
}
124
125
#endif
/* THEPEG_MaxCmp_H */
Generated on Sat Jun 16 2012 16:51:04 for ThePEG by
1.8.1.1