npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
PairCompare.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_PAIRCOMPARE_HH_
2 #define NPSTAT_PAIRCOMPARE_HH_
3 
4 /*!
5 // \file PairCompare.hh
6 //
7 // \brief Various comparison functors for std::pair and npstat::Triple
8 //
9 // Author: I. Volobouev
10 //
11 // December 2011
12 */
13 
14 #include <cmath>
15 
16 namespace npstat {
17  /** "less" functor to compare the first element only */
18  template <typename T>
19  struct LessByFirst
20  {
21  inline bool operator()(const T& x, const T& y) const
22  {return x.first < y.first;}
23  inline bool operator()(const T* x, const T* y) const
24  {return x->first < y->first;}
25  };
26 
27  /** "greater" functor to compare the first element only */
28  template <typename T>
30  {
31  inline bool operator()(const T& x, const T& y) const
32  {return y.first < x.first;}
33  inline bool operator()(const T* x, const T* y) const
34  {return y->first < x->first;}
35  };
36 
37  /** "less" functor to compare the magnitude of the first element only */
38  template <typename T>
40  {
41  inline bool operator()(const T& x, const T& y) const
42  {return std::abs(x.first) < std::abs(y.first);}
43  inline bool operator()(const T* x, const T* y) const
44  {return std::abs(x->first) < std::abs(y->first);}
45  };
46 
47  /** "greater" functor to compare the magnitude of the first element only */
48  template <typename T>
50  {
51  inline bool operator()(const T& x, const T& y) const
52  {return std::abs(y.first) < std::abs(x.first);}
53  inline bool operator()(const T* x, const T* y) const
54  {return std::abs(y->first) < std::abs(x->first);}
55  };
56 
57  /** "less" functor to compare the second element only */
58  template <typename T>
59  struct LessBySecond
60  {
61  inline bool operator()(const T& x, const T& y) const
62  {return x.second < y.second;}
63  inline bool operator()(const T* x, const T* y) const
64  {return x->second < y->second;}
65  };
66 
67  /** "greater" functor to compare the second element only */
68  template <typename T>
70  {
71  inline bool operator()(const T& x, const T& y) const
72  {return y.second < x.second;}
73  inline bool operator()(const T* x, const T* y) const
74  {return y->second < x->second;}
75  };
76 
77  /** "less" functor to compare the third element only */
78  template <typename T>
79  struct LessByThird
80  {
81  inline bool operator()(const T& x, const T& y) const
82  {return x.third < y.third;}
83  inline bool operator()(const T* x, const T* y) const
84  {return x->third < y->third;}
85  };
86 
87  /** "greater" functor to compare the third element only */
88  template <typename T>
90  {
91  inline bool operator()(const T& x, const T& y) const
92  {return y.third < x.third;}
93  inline bool operator()(const T* x, const T* y) const
94  {return y->third < x->third;}
95  };
96 }
97 
98 #endif // NPSTAT_PAIRCOMPARE_HH_
Definition: AbsArrayProjector.hh:14
Definition: PairCompare.hh:50
Definition: PairCompare.hh:30
Definition: PairCompare.hh:70
Definition: PairCompare.hh:90
Definition: PairCompare.hh:40
Definition: PairCompare.hh:20
Definition: PairCompare.hh:60
Definition: PairCompare.hh:80