Library of Assembled Shared Sources
triple.inl
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43namespace lass
44{
45namespace stde
46{
47
48// --- public --------------------------------------------------------------------------------------
49
50
51/** default constructor
52 * The default constructor creates a vlaue triple with triples that are initialized by the
53 * default constructor of their type. Because of language rules, an explicit call of a default
54 * constructor also initializes fundamental data types such as @c int.
55 */
56template <typename T1, typename T2, typename T3>
58 first(T1()),
59 second(T2()),
60 third(T3())
61{
62}
63
64
65
66/** constructor for three values
67 */
68template <typename T1, typename T2, typename T3>
69triple<T1, T2, T3>::triple(typename util::CallTraits<T1>::TParam a,
70 typename util::CallTraits<T2>::TParam b,
71 typename util::CallTraits<T3>::TParam c):
72 first(a),
73 second(b),
74 third(c)
75{
76}
77
78
79
80/** copy constructor with implicit conversions
81 * This template version of the copy constructor provided here is ussed when implicit
82 * conversions are necessary.
83 */
84template <typename T1, typename T2, typename T3>
85template <typename U1, typename U2, typename U3>
87 first(other.first),
88 second(other.second),
89 third(other.third)
90{
91}
92
93
94
95// --- protected -----------------------------------------------------------------------------------
96
97
98
99// --- private -------------------------------------------------------------------------------------
100
101
102
103// --- free ----------------------------------------------------------------------------------------
104
105/** two triples are identical if all elements (first, second, third) are identical.
106 * @relates triple
107 */
108template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
110{
111 return x.first == y.first && x.second == y.second && x.third == y.third;
112}
113
114/** return true if x is "less" than y.
115 * @relates triple
116 *
117 * As for std::pair, the "less than" comparison is implemented for Triples in a similar way.
118 * The first value has higher priority than the second and third, and the second value has higher
119 * priority than the third. Thus, if the first values of two pairs differ, the result of their
120 * comparison is used as the result of the comparison of the whole triples. If the first values
121 * are equal, the comparison of the second values yields the result if they differ. If the
122 * second values are equal too, the comparison of the third values finally yields the result.
123 */
124template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
126{
127 return x.first < y.first || (!(y.first < x.first) &&
128 (x.second < y.second || (!(y.second < x.second) && x.third < y.third)));
129}
130
131/** equivalent to !(x == y), see operator<
132 * @relates triple
133 */
134template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
136{
137 return !(x == y);
138}
139
140/** equivalent to y < x, see operator<
141 * @relates triple
142 */
143template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
145{
146 return y < x;
147}
148
149/** equivalent to !(y < x), see operator<
150 * @relates triple
151 */
152template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
154{
155 return !(y < x);
156}
157
158/** equivalent to !(x < y), see operator<
159 * @relates triple
160 */
161template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3>
163{
164 return !(x < y);
165}
166
167
168
169/*
170 * @relates triple
171 */
172template <typename T1, typename T2, typename T3>
173std::ostream& operator<<(std::ostream& stream, const triple<T1, T2, T3>& x)
174{
175 return stream << "(" << x.first << ", " << x.second << ", " << x.third << ")";
176}
177
178
179
180/** convenience function to create a lass::stde::triple.
181 * @relates triple
182 *
183 * The make_triple template function enables you to create a value triple without writing the
184 * types explicitly. In particular the make_triple function makes it convenient to pass three
185 * values of a triple directly to a function that requires a triple as its argument.
186 * It works even when the types do not match exactly becuase the template copy constructor
187 * provides implicit type conversion.
188 *
189 * using make_triple should cost no runtime. The compiler should always optimize any implied
190 * overhead.
191 */
192template <typename T1, typename T2, typename T3>
193triple<T1, T2, T3> make_triple(const T1& a, const T2& b, const T3& c)
194{
195 return triple<T1, T2, T3>(a, b, c);
196}
197
198
199
200}
201
202}
203
204// EOF
lass extensions to the standard library
Library for Assembled Shared Sources.
Definition config.h:53
extension of std::pair to three values, trait three values as a single unit.
Definition triple.h:73
bool operator<=(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
equivalent to !(y < x), see operator<
Definition triple.inl:153
bool operator>=(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
equivalent to !(x < y), see operator<
Definition triple.inl:162
bool operator==(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
two triples are identical if all elements (first, second, third) are identical.
Definition triple.inl:109
triple()
default constructor The default constructor creates a vlaue triple with triples that are initialized ...
Definition triple.inl:57
bool operator!=(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
equivalent to !(x == y), see operator<
Definition triple.inl:135
bool operator<(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
return true if x is "less" than y.
Definition triple.inl:125
triple< T1, T2, T3 > make_triple(const T1 &a, const T2 &b, const T3 &c)
convenience function to create a lass::stde::triple.
Definition triple.inl:193
bool operator>(const triple< T1, T2, T3 > &x, const triple< U1, U2, U3 > &y)
equivalent to y < x, see operator<
Definition triple.inl:144