Ocean
Loading...
Searching...
No Matches
Triple.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_BASE_TRIPLE_H
9#define META_OCEAN_BASE_TRIPLE_H
10
11#include "ocean/base/Base.h"
12
13namespace Ocean
14{
15
16// Forward declaration.
17template <typename T1, typename T2, typename T3> class Triple;
18
19/**
20 * This class implements a triple object able to hold three individual elements.
21 * @tparam T1 Data type of the first element of the triple object
22 * @tparam T2 Data type of the second element of the triple object
23 * @tparam T3 Data type of the third element of the triple object
24 * @ingroup base
25 */
26template <typename T1, typename T2, typename T3>
27class Triple
28{
29 public:
30
31 /**
32 * Creates a new triple object with default values.
33 */
34 inline Triple() = default;
35
36 /**
37 * Creates a new triple object with three elements.
38 * @param first First element
39 * @param second Second element
40 * @param third Third element
41 */
42 inline explicit Triple(const T1& first, const T2& second = T2(), const T3& third = T3());
43
44 /**
45 * Returns the first element of this triple object.
46 * @return First element
47 */
48 inline const T1& first() const;
49
50 /**
51 * Returns the first element of this triple object.
52 * @return First element
53 */
54 inline T1& first();
55
56 /**
57 * Returns the second element of this triple object.
58 * @return First element
59 */
60 inline const T2& second() const;
61
62 /**
63 * Returns the second element of this triple object.
64 * @return Second element
65 */
66 inline T2& second();
67
68 /**
69 * Returns the third element of this triple object.
70 * @return Third element
71 */
72 inline const T3& third() const;
73
74 /**
75 * Returns the third element of this triple object.
76 * @return Third element
77 */
78 inline T3& third();
79
80 /**
81 * Returns whether two triples are equal.
82 * @param triple Second triple object
83 * @return True, if so
84 */
85 inline bool operator==(const Triple<T1, T2, T3>& triple) const;
86
87 /**
88 * Returns whether two triples are not equal.
89 * @param triple Second triple object
90 * @return True, if so
91 */
92 inline bool operator!=(const Triple<T1, T2, T3>& triple) const;
93
94 /**
95 * Returns whether this triple object is 'lesser' than a second triple object.
96 * @param triple The second triple object to be used for comparison
97 * @return True, if so
98 */
99 inline bool operator<(const Triple<T1, T2, T3>& triple) const;
100
101 private:
102
103 /// First element of this triple.
104 T1 first_ = T1();
105
106 /// Second element of this triple.
107 T2 second_ = T2();
108
109 /// Third element of this triple.
110 T3 third_ = T3();
111};
112
113template <typename T1, typename T2, typename T3>
114inline Triple<T1, T2, T3>::Triple(const T1& first, const T2& second, const T3& third) :
115 first_(first),
116 second_(second),
117 third_(third)
118{
119 // nothing to do here
120}
121
122template <typename T1, typename T2, typename T3>
123inline const T1& Triple<T1, T2, T3>::first() const
124{
125 return first_;
126}
127
128template <typename T1, typename T2, typename T3>
130{
131 return first_;
132}
133
134template <typename T1, typename T2, typename T3>
135inline const T2& Triple<T1, T2, T3>::second() const
136{
137 return second_;
138}
139
140template <typename T1, typename T2, typename T3>
142{
143 return second_;
144}
145
146template <typename T1, typename T2, typename T3>
147inline const T3& Triple<T1, T2, T3>::third() const
148{
149 return third_;
150}
151
152template <typename T1, typename T2, typename T3>
154{
155 return third_;
156}
157
158template <typename T1, typename T2, typename T3>
160{
161 return first_ == triple.first_ && second_ == triple.second_ && third_ == triple.third_;
162}
163
164template <typename T1, typename T2, typename T3>
166{
167 return !(*this == triple);
168}
169
170template <typename T1, typename T2, typename T3>
171inline bool Triple<T1, T2, T3>::operator<(const Triple<T1, T2, T3>& triple) const
172{
173 return (first_ < triple.first_)
174 || (first_ == triple.first_ && second_ < triple.second_)
175 || (first_ == triple.first_ && second_ == triple.second_ && third_ < triple.third_);
176}
177
178}
179
180#endif // META_OCEAN_BASE_TRIPLE_H
This class implements a triple object able to hold three individual elements.
Definition Triple.h:28
const T1 & first() const
Returns the first element of this triple object.
Definition Triple.h:123
const T3 & third() const
Returns the third element of this triple object.
Definition Triple.h:147
T2 second_
Second element of this triple.
Definition Triple.h:107
bool operator<(const Triple< T1, T2, T3 > &triple) const
Returns whether this triple object is 'lesser' than a second triple object.
Definition Triple.h:171
const T2 & second() const
Returns the second element of this triple object.
Definition Triple.h:135
Triple()=default
Creates a new triple object with default values.
bool operator!=(const Triple< T1, T2, T3 > &triple) const
Returns whether two triples are not equal.
Definition Triple.h:165
bool operator==(const Triple< T1, T2, T3 > &triple) const
Returns whether two triples are equal.
Definition Triple.h:159
T3 third_
Third element of this triple.
Definition Triple.h:110
T1 first_
First element of this triple.
Definition Triple.h:104
The namespace covering the entire Ocean framework.
Definition Accessor.h:15