thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::MaxCmp< T, Indx, Cmp > Class Template Reference

MaxCmp is a helper class to be used in a loop where one would like to keep track of the largest value so far of a certain expression. More...

#include <MaxCmp.h>

Inheritance diagram for ThePEG::MaxCmp< T, Indx, Cmp >:

Public Member Functions

 MaxCmp ()
 The default constructor.
 
 MaxCmp (const T &t, Indx in=Indx())
 Constructor specifying an initial maximum value, t.
 
bool operator() (const T &t, Indx i=Indx())
 If t is the largest value seen so far return true.
 
 operator const T & () const
 Return the largest value so far.
 
const T & value () const
 Return the largest value so far.
 
Indx index () const
 Return the index of the largest object seen so far.
 
bool operator! () const
 Return true if no index has been chosen.
 

Private Attributes

bool init
 True if a first value has been given;.
 
max
 The largest value seen so far.
 
Indx indx
 The index for the largest value seen so far.
 
Cmp cmp
 The comparison object to be used.
 

Detailed Description

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
class ThePEG::MaxCmp< T, Indx, Cmp >

MaxCmp is a helper class to be used in a loop where one would like to keep track of the largest value so far of a certain expression.

The class simply checks if the given value to the operator() is the largest so far (in which case true is returned, and the value is saved together with the optional index argument. The Cmp template argument is by default greater<T>, but can be set to any comparison class to change the meaning of maximum: MaxCmp<double, int, less<double> > will keep track of the smallest value.

Definition at line 31 of file MaxCmp.h.

Constructor & Destructor Documentation

◆ MaxCmp() [1/2]

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
ThePEG::MaxCmp< T, Indx, Cmp >::MaxCmp ( )
inline

The default constructor.

Definition at line 38 of file MaxCmp.h.

◆ MaxCmp() [2/2]

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
ThePEG::MaxCmp< T, Indx, Cmp >::MaxCmp ( const T &  t,
Indx  in = Indx() 
)
inline

Constructor specifying an initial maximum value, t.

Definition at line 43 of file MaxCmp.h.

Member Function Documentation

◆ index()

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
Indx ThePEG::MaxCmp< T, Indx, Cmp >::index ( ) const
inline

Return the index of the largest object seen so far.

Definition at line 75 of file MaxCmp.h.

References ThePEG::MaxCmp< T, Indx, Cmp >::indx.

◆ operator const T &()

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
ThePEG::MaxCmp< T, Indx, Cmp >::operator const T & ( ) const
inline

Return the largest value so far.

Definition at line 65 of file MaxCmp.h.

References ThePEG::MaxCmp< T, Indx, Cmp >::value().

◆ operator!()

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
bool ThePEG::MaxCmp< T, Indx, Cmp >::operator! ( ) const
inline

Return true if no index has been chosen.

Definition at line 82 of file MaxCmp.h.

References ThePEG::MaxCmp< T, Indx, Cmp >::init.

◆ operator()()

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
bool ThePEG::MaxCmp< T, Indx, Cmp >::operator() ( const T &  t,
Indx  i = Indx() 
)
inline

If t is the largest value seen so far return true.

Otherwise return false. i is an optional index for the value t.

Definition at line 51 of file MaxCmp.h.

References ThePEG::MaxCmp< T, Indx, Cmp >::cmp, ThePEG::MaxCmp< T, Indx, Cmp >::indx, ThePEG::MaxCmp< T, Indx, Cmp >::init, and ThePEG::MaxCmp< T, Indx, Cmp >::max.

◆ value()

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
const T & ThePEG::MaxCmp< T, Indx, Cmp >::value ( ) const
inline

Return the largest value so far.

Definition at line 70 of file MaxCmp.h.

References ThePEG::MaxCmp< T, Indx, Cmp >::max.

Referenced by ThePEG::MaxCmp< T, Indx, Cmp >::operator const T &().

Member Data Documentation

◆ cmp

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
Cmp ThePEG::MaxCmp< T, Indx, Cmp >::cmp
private

The comparison object to be used.

Definition at line 106 of file MaxCmp.h.

Referenced by ThePEG::MaxCmp< T, Indx, Cmp >::operator()().

◆ indx

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
Indx ThePEG::MaxCmp< T, Indx, Cmp >::indx
private

The index for the largest value seen so far.

Definition at line 101 of file MaxCmp.h.

Referenced by ThePEG::MaxCmp< T, Indx, Cmp >::index(), and ThePEG::MaxCmp< T, Indx, Cmp >::operator()().

◆ init

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
bool ThePEG::MaxCmp< T, Indx, Cmp >::init
private

True if a first value has been given;.

Definition at line 91 of file MaxCmp.h.

Referenced by ThePEG::MaxCmp< T, Indx, Cmp >::operator!(), and ThePEG::MaxCmp< T, Indx, Cmp >::operator()().

◆ max

template<typename T = double, typename Indx = int, typename Cmp = std::greater<T>>
T ThePEG::MaxCmp< T, Indx, Cmp >::max
private

The largest value seen so far.

Definition at line 96 of file MaxCmp.h.

Referenced by ThePEG::MaxCmp< T, Indx, Cmp >::operator()(), and ThePEG::MaxCmp< T, Indx, Cmp >::value().


The documentation for this class was generated from the following file: