npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
Triple.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_TRIPLE_HH_
2 #define NPSTAT_TRIPLE_HH_
3 
4 /*!
5 // \file Triple.hh
6 //
7 // \brief A simple analogue of std::pair with three components instead of two
8 //
9 // Author: I. Volobouev
10 //
11 // June 2012
12 */
13 
14 namespace npstat {
15  /** A simple analogue of std::pair with three components */
16  template <class First, class Second, class Third>
17  struct Triple
18  {
19  typedef First first_type;
20  typedef Second second_type;
21  typedef Third third_type;
22 
23  /**
24  // Default constructor of the triple calls default constructors
25  // of each component type
26  */
27  inline Triple() : first(First()), second(Second()), third(Third()) {}
28 
29  /** Construct a triple by combining three different objects */
30  inline Triple(const First& f, const Second& s, const Third& t)
31  : first(f), second(s), third(t) {}
32 
33  /** Converting copy constructor */
34  template<class F2, class S2, class T2>
35  inline Triple(const Triple<F2, S2, T2>& r)
36  : first(r.first), second(r.second), third(r.third) {}
37 
38  /** Converting assignment operator */
39  template<class F2, class S2, class T2>
41  {
42  if (static_cast<void*>(this) != static_cast<const void*>(&r))
43  {
44  first = r.first;
45  second = r.second;
46  third = r.third;
47  }
48  return *this;
49  }
50 
51  /** Comparison for equality */
52  inline bool operator==(const Triple& r) const
53  {return first == r.first && second == r.second && third == r.third;}
54 
55  /** Logical negation of operator== */
56  inline bool operator!=(const Triple& r) const
57  {return !(*this == r);}
58 
59  //@{
60  /**
61  // Ordering comparison. Initially, first elements are compared.
62  // If they are equal, second elements are compared, etc.
63  */
64  inline bool operator<(const Triple& r) const
65  {
66  if (first < r.first) return true;
67  if (r.first < first) return false;
68  if (second < r.second) return true;
69  if (r.second < second) return false;
70  return third < r.third;
71  }
72 
73  inline bool operator>(const Triple& r) const
74  {
75  if (first > r.first) return true;
76  if (r.first > first) return false;
77  if (second > r.second) return true;
78  if (r.second > second) return false;
79  return third > r.third;
80  }
81  //@}
82 
83  First first; ///< First element of the triple
84  Second second; ///< Second element of the triple
85  Third third; ///< Third element of the triple
86  };
87 
88  /** Utility function for triples similar to std::make_pair */
89  template <class First, class Second, class Third>
91  const First& f, const Second& s, const Third& t)
92  {
93  return Triple<First, Second, Third>(f, s, t);
94  }
95 }
96 
97 #endif // NPSTAT_TRIPLE_HH_
Definition: AbsArrayProjector.hh:14
Triple< First, Second, Third > make_Triple(const First &f, const Second &s, const Third &t)
Definition: Triple.hh:90
Definition: Triple.hh:18
Triple(const Triple< F2, S2, T2 > &r)
Definition: Triple.hh:35
Second second
Second element of the triple.
Definition: Triple.hh:84
bool operator!=(const Triple &r) const
Definition: Triple.hh:56
Triple & operator=(const Triple< F2, S2, T2 > &r)
Definition: Triple.hh:40
Triple(const First &f, const Second &s, const Third &t)
Definition: Triple.hh:30
Third third
Third element of the triple.
Definition: Triple.hh:85
First first
First element of the triple.
Definition: Triple.hh:83
bool operator==(const Triple &r) const
Definition: Triple.hh:52
bool operator<(const Triple &r) const
Definition: Triple.hh:64
Triple()
Definition: Triple.hh:27