triplet.hpp
Go to the documentation of this file.
1 
6 #ifndef TRIPLET_HPP
7 #define TRIPLET_HPP 1
8 
9 #include "universal_error.hpp"
10 
12 template<class T> class TripleConstRef
13 {
14  public:
15 
17  const T& first;
18 
20  const T& second;
21 
23  const T& third;
24 
30  TripleConstRef(const T& first_i,
31  const T& second_i,
32  const T& third_i):
33  first(first_i),
34  second(second_i),
35  third(third_i) {}
36 };
37 
39 template<class T> class Triplet
40 {
41  public:
42 
44  T first;
45 
47  T second;
48 
50  T third;
51 
57  Triplet(const T& first_i,
58  const T& second_i,
59  const T& third_i):
60  first(first_i),
61  second(second_i),
62  third(third_i) {}
63 
67  explicit Triplet(const TripleConstRef<int>& tcr):
68  first(tcr.first),
69  second(tcr.second),
70  third(tcr.third) {}
71 
77  void set(const T& first_i,
78  const T& second_i,
79  const T& third_i)
80  {
81  first = first_i;
82  second = second_i;
83  third = third_i;;
84  }
85 
90  const T& operator[](size_t i) const
91  {
92  assert(i<3);
93  static const T Triplet<T>::* temp [3] = {&Triplet<T>::first,
96  return this->*temp[i];
97  }
98 
103  T& operator[](size_t i)
104  {
105  assert(i<3);
106  static T Triplet<T>::* temp [] = {&Triplet<T>::first,
109  return this->*temp[i];
110  }
111 };
112 
113 #endif // TRIPLET_HPP
const T & third
Reference to third item.
Definition: triplet.hpp:23
const T & second
Reference to second item.
Definition: triplet.hpp:20
TripleConstRef(const T &first_i, const T &second_i, const T &third_i)
Class constructor.
Definition: triplet.hpp:30
const T & operator[](size_t i) const
Random access operator.
Definition: triplet.hpp:90
A collection of three identical references.
Definition: triplet.hpp:12
T & operator[](size_t i)
Random access operator.
Definition: triplet.hpp:103
T third
Third item.
Definition: triplet.hpp:50
Triplet(const TripleConstRef< int > &tcr)
Class constructor.
Definition: triplet.hpp:67
Triplet(const T &first_i, const T &second_i, const T &third_i)
Class constructor.
Definition: triplet.hpp:57
const T & first
Reference to first item.
Definition: triplet.hpp:17
T second
Second item.
Definition: triplet.hpp:47
A collection of 3 items of the same type.
Definition: triplet.hpp:39
A class for storing error and debug information.
T first
First item.
Definition: triplet.hpp:44