QDP++
include
PETE
TypeComputations.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
// ACL:license
3
// ----------------------------------------------------------------------
4
// This software and ancillary information (herein called "SOFTWARE")
5
// called PETE (Portable Expression Template Engine) is
6
// made available under the terms described here. The SOFTWARE has been
7
// approved for release with associated LA-CC Number LA-CC-99-5.
8
//
9
// Unless otherwise indicated, this SOFTWARE has been authored by an
10
// employee or employees of the University of California, operator of the
11
// Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
12
// the U.S. Department of Energy. The U.S. Government has rights to use,
13
// reproduce, and distribute this SOFTWARE. The public may copy, distribute,
14
// prepare derivative works and publicly display this SOFTWARE without
15
// charge, provided that this Notice and any statement of authorship are
16
// reproduced on all copies. Neither the Government nor the University
17
// makes any warranty, express or implied, or assumes any liability or
18
// responsibility for the use of this SOFTWARE.
19
//
20
// If SOFTWARE is modified to produce derivative works, such modified
21
// SOFTWARE should be clearly marked, so as not to confuse it with the
22
// version available from LANL.
23
//
24
// For more information about PETE, send e-mail to pete@acl.lanl.gov,
25
// or visit the PETE web page at http://www.acl.lanl.gov/pete/.
26
// ----------------------------------------------------------------------
27
// ACL:license
28
29
#ifndef PETE_PETE_TYPECOMPUTATIONS_H
30
#define PETE_PETE_TYPECOMPUTATIONS_H
31
32
//-----------------------------------------------------------------------------
33
//
34
// CLASS NAME
35
// UnaryReturn<T, Op>
36
//
37
// DESCRIPTION
38
// This template describes the default mechanism for calculating the
39
// return type to a unary expression given the argument type T and
40
// the operation type Op.
41
//
42
// There are a several sensible things one can do:
43
// o make the return type the same as the argument to the
44
// function/operation. For example, operator-(T) should return a T.
45
// o return a type based entirely on the operation.
46
// For example, operator! always returns a bool.
47
// o sythesize a type based on the type of the argument and the operation.
48
// The first case is most common. We therefore make it the behavior
49
// for the base template. The other cases are handled by partial
50
// specialization.
51
//
52
// For example, the abs function typically returns a double when the
53
// argument is a complex<double>. The appropriate specialization here
54
// would be:
55
// template<> struct PETEUnaryReturn<complex<double>, FnAbs> {
56
// typedef double Type_t;
57
// };
58
//
59
//-----------------------------------------------------------------------------
60
61
template
<
class
T,
class
Op>
62
struct
UnaryReturn
{
63
typedef
T
Type_t
;
64
};
65
66
//-----------------------------------------------------------------------------
67
//
68
// CLASS NAME
69
// Promote<T1, T2>
70
//
71
// DESCRIPTION
72
// General template and specializations to implement C++ type promotion
73
// for basic types.
74
//
75
//-----------------------------------------------------------------------------
76
77
// Base template: don't do anything by default.
78
79
template
<
class
T1,
class
T2>
80
struct
Promote
{
typedef
T1
Type_t
; };
81
82
// bool
83
84
template
<>
85
struct
Promote
<bool, bool> {
86
typedef
bool
Type_t
;
87
};
88
89
template
<>
90
struct
Promote
<bool, char> {
91
typedef
char
Type_t
;
92
};
93
94
template
<>
95
struct
Promote
<bool, short> {
96
typedef
short
Type_t
;
97
};
98
99
template
<>
100
struct
Promote
<bool, int> {
101
typedef
int
Type_t
;
102
};
103
104
template
<>
105
struct
Promote
<bool, long> {
106
typedef
long
Type_t
;
107
};
108
109
template
<>
110
struct
Promote
<bool, float> {
111
typedef
float
Type_t
;
112
};
113
114
template
<>
115
struct
Promote
<bool, double> {
116
typedef
double
Type_t
;
117
};
118
119
// char
120
121
template
<>
122
struct
Promote
<char, bool> {
123
typedef
char
Type_t
;
124
};
125
126
template
<>
127
struct
Promote
<char, char> {
128
typedef
char
Type_t
;
129
};
130
131
template
<>
132
struct
Promote
<char, short> {
133
typedef
short
Type_t
;
134
};
135
136
template
<>
137
struct
Promote
<char, int> {
138
typedef
int
Type_t
;
139
};
140
141
template
<>
142
struct
Promote
<char, long> {
143
typedef
long
Type_t
;
144
};
145
146
template
<>
147
struct
Promote
<char, float> {
148
typedef
float
Type_t
;
149
};
150
151
template
<>
152
struct
Promote
<char, double> {
153
typedef
double
Type_t
;
154
};
155
156
// short
157
158
template
<>
159
struct
Promote
<short, bool> {
160
typedef
short
Type_t
;
161
};
162
163
template
<>
164
struct
Promote
<short, char> {
165
typedef
short
Type_t
;
166
};
167
168
template
<>
169
struct
Promote
<short, short> {
170
typedef
short
Type_t
;
171
};
172
173
template
<>
174
struct
Promote
<short, int> {
175
typedef
int
Type_t
;
176
};
177
178
template
<>
179
struct
Promote
<short, long> {
180
typedef
long
Type_t
;
181
};
182
183
template
<>
184
struct
Promote
<short, float> {
185
typedef
float
Type_t
;
186
};
187
188
template
<>
189
struct
Promote
<short, double> {
190
typedef
double
Type_t
;
191
};
192
193
// int
194
195
template
<>
196
struct
Promote
<int, bool> {
197
typedef
int
Type_t
;
198
};
199
200
template
<>
201
struct
Promote
<int, char> {
202
typedef
int
Type_t
;
203
};
204
205
template
<>
206
struct
Promote
<int, short> {
207
typedef
int
Type_t
;
208
};
209
210
template
<>
211
struct
Promote
<int, int> {
212
typedef
int
Type_t
;
213
};
214
215
template
<>
216
struct
Promote
<int, long> {
217
typedef
long
Type_t
;
218
};
219
220
template
<>
221
struct
Promote
<int, float> {
222
typedef
float
Type_t
;
223
};
224
225
template
<>
226
struct
Promote
<int, double> {
227
typedef
double
Type_t
;
228
};
229
230
// long
231
232
template
<>
233
struct
Promote
<long, bool> {
234
typedef
long
Type_t
;
235
};
236
237
template
<>
238
struct
Promote
<long, char> {
239
typedef
long
Type_t
;
240
};
241
242
template
<>
243
struct
Promote
<long, short> {
244
typedef
long
Type_t
;
245
};
246
247
template
<>
248
struct
Promote
<long, int> {
249
typedef
long
Type_t
;
250
};
251
252
template
<>
253
struct
Promote
<long, long> {
254
typedef
long
Type_t
;
255
};
256
257
template
<>
258
struct
Promote
<long, float> {
259
typedef
float
Type_t
;
260
};
261
262
template
<>
263
struct
Promote
<long, double> {
264
typedef
double
Type_t
;
265
};
266
267
// float
268
269
template
<>
270
struct
Promote
<float, bool> {
271
typedef
float
Type_t
;
272
};
273
274
template
<>
275
struct
Promote
<float, char> {
276
typedef
float
Type_t
;
277
};
278
279
template
<>
280
struct
Promote
<float, short> {
281
typedef
float
Type_t
;
282
};
283
284
template
<>
285
struct
Promote
<float, int> {
286
typedef
float
Type_t
;
287
};
288
289
template
<>
290
struct
Promote
<float, long> {
291
typedef
float
Type_t
;
292
};
293
294
template
<>
295
struct
Promote
<float, float> {
296
typedef
float
Type_t
;
297
};
298
299
template
<>
300
struct
Promote
<float, double> {
301
typedef
double
Type_t
;
302
};
303
304
// double
305
306
template
<>
307
struct
Promote
<double, bool> {
308
typedef
double
Type_t
;
309
};
310
311
template
<>
312
struct
Promote
<double, char> {
313
typedef
double
Type_t
;
314
};
315
316
template
<>
317
struct
Promote
<double, short> {
318
typedef
double
Type_t
;
319
};
320
321
template
<>
322
struct
Promote
<double, int> {
323
typedef
double
Type_t
;
324
};
325
326
template
<>
327
struct
Promote
<double, long> {
328
typedef
double
Type_t
;
329
};
330
331
template
<>
332
struct
Promote
<double, float> {
333
typedef
double
Type_t
;
334
};
335
336
template
<>
337
struct
Promote
<double, double> {
338
typedef
double
Type_t
;
339
};
340
341
//-----------------------------------------------------------------------------
342
//
343
// CLASS NAME
344
// BinaryReturn<T1, T2, Op>
345
//
346
// DESCRIPTION
347
// This template describes the default mechanism for calculating the
348
// return type to a binary expression given the argument types T1 and
349
// T2 and the operation type Op.
350
//
351
// There are several sensible things one can do:
352
// o make the return type by promoting/converting the "simpler" type
353
// into the more "complex." For example, we typically want to do
354
// this with addition.
355
// o return the type of the left-hand operand. For example, this is
356
// what happens with operator<<.
357
// o return the type of the right-hand operand.
358
// o return a type based entirely on the operation.
359
// For example, operator!= always returns a bool.
360
// o synthesize the return type based on the operation and types.
361
// The first option is most common, so we make that the behavior of the
362
// base template. The other cases are handled by partial specialization.
363
//
364
// For example, the multiplication between a matrix and a vector might do a
365
// matrix/vector product, thereby returning a vector. The appropriate
366
// specialization here would be:
367
// struct BinaryReturn<Mat<double,3>, Vec<float,3>, OpMultiply> {
368
// typedef Vec<double,3> Type_t;
369
// };
370
// Notice how the element type is promoted.
371
//
372
//-----------------------------------------------------------------------------
373
374
template
<
class
T1,
class
T2,
class
Op>
375
struct
BinaryReturn
{
376
typedef
typename
Promote<T1, T2>::Type_t
Type_t
;
377
};
378
379
380
//-----------------------------------------------------------------------------
381
//
382
// CLASS NAME
383
// TrinaryReturn<T1, T2, T3, Op>
384
//
385
// DESCRIPTION
386
// This template describes the default mechanism for calculating the
387
// return type to a trinary expression given the argument types T1, T2, and
388
// T3 and the operation type Op. The only trinary expression supported
389
// in C++ is the ?: operation. In this case, T1 should end up being bool
390
// and the result of the calculation is of type Binary_Promotion(T2,T3)
391
// with the value being that associated with T2 if T1's associated value
392
// turns out to be true and T3 if T1's associated value turns out to be
393
// false.
394
//
395
//-----------------------------------------------------------------------------
396
397
template
<
class
T1,
class
T2,
class
T3,
class
Op>
398
struct
TrinaryReturn
{
399
typedef
typename
BinaryReturn<T2, T3, Op>::Type_t
Type_t
;
400
};
401
402
403
#endif
// PETE_PETE_TYPE_COMPUTATIONS_H
404
405
// ACL:rcsinfo
406
// ----------------------------------------------------------------------
407
// $RCSfile: TypeComputations.h,v $ $Author: edwards $
408
// $Revision: 1.1 $ $Date: 2002-09-12 18:22:16 $
409
// ----------------------------------------------------------------------
410
// ACL:rcsinfo
BinaryReturn
Definition
TypeComputations.h:375
Type_t::Type_t
Promote< A, B >::Type_t Type_t
Definition
TypeComputations.h:376
Promote< bool, bool >::Type_t
bool Type_t
Definition
TypeComputations.h:86
Promote< bool, char >::Type_t
char Type_t
Definition
TypeComputations.h:91
Promote< bool, double >::Type_t
double Type_t
Definition
TypeComputations.h:116
Promote< bool, float >::Type_t
float Type_t
Definition
TypeComputations.h:111
Promote< bool, int >::Type_t
int Type_t
Definition
TypeComputations.h:101
Promote< bool, long >::Type_t
long Type_t
Definition
TypeComputations.h:106
Promote< bool, short >::Type_t
short Type_t
Definition
TypeComputations.h:96
Promote< char, bool >::Type_t
char Type_t
Definition
TypeComputations.h:123
Promote< char, char >::Type_t
char Type_t
Definition
TypeComputations.h:128
Promote< char, double >::Type_t
double Type_t
Definition
TypeComputations.h:153
Promote< char, float >::Type_t
float Type_t
Definition
TypeComputations.h:148
Promote< char, int >::Type_t
int Type_t
Definition
TypeComputations.h:138
Promote< char, long >::Type_t
long Type_t
Definition
TypeComputations.h:143
Promote< char, short >::Type_t
short Type_t
Definition
TypeComputations.h:133
Promote< double, bool >::Type_t
double Type_t
Definition
TypeComputations.h:308
Promote< double, char >::Type_t
double Type_t
Definition
TypeComputations.h:313
Promote< double, double >::Type_t
double Type_t
Definition
TypeComputations.h:338
Promote< double, float >::Type_t
double Type_t
Definition
TypeComputations.h:333
Promote< double, int >::Type_t
double Type_t
Definition
TypeComputations.h:323
Promote< double, long >::Type_t
double Type_t
Definition
TypeComputations.h:328
Promote< double, short >::Type_t
double Type_t
Definition
TypeComputations.h:318
Promote< float, bool >::Type_t
float Type_t
Definition
TypeComputations.h:271
Promote< float, char >::Type_t
float Type_t
Definition
TypeComputations.h:276
Promote< float, double >::Type_t
double Type_t
Definition
TypeComputations.h:301
Promote< float, float >::Type_t
float Type_t
Definition
TypeComputations.h:296
Promote< float, int >::Type_t
float Type_t
Definition
TypeComputations.h:286
Promote< float, long >::Type_t
float Type_t
Definition
TypeComputations.h:291
Promote< float, short >::Type_t
float Type_t
Definition
TypeComputations.h:281
Promote< int, bool >::Type_t
int Type_t
Definition
TypeComputations.h:197
Promote< int, char >::Type_t
int Type_t
Definition
TypeComputations.h:202
Promote< int, double >::Type_t
double Type_t
Definition
TypeComputations.h:227
Promote< int, float >::Type_t
float Type_t
Definition
TypeComputations.h:222
Promote< int, int >::Type_t
int Type_t
Definition
TypeComputations.h:212
Promote< int, long >::Type_t
long Type_t
Definition
TypeComputations.h:217
Promote< int, short >::Type_t
int Type_t
Definition
TypeComputations.h:207
Promote< long, bool >::Type_t
long Type_t
Definition
TypeComputations.h:234
Promote< long, char >::Type_t
long Type_t
Definition
TypeComputations.h:239
Promote< long, double >::Type_t
double Type_t
Definition
TypeComputations.h:264
Promote< long, float >::Type_t
float Type_t
Definition
TypeComputations.h:259
Promote< long, int >::Type_t
long Type_t
Definition
TypeComputations.h:249
Promote< long, long >::Type_t
long Type_t
Definition
TypeComputations.h:254
Promote< long, short >::Type_t
long Type_t
Definition
TypeComputations.h:244
Promote< short, bool >::Type_t
short Type_t
Definition
TypeComputations.h:160
Promote< short, char >::Type_t
short Type_t
Definition
TypeComputations.h:165
Promote< short, double >::Type_t
double Type_t
Definition
TypeComputations.h:190
Promote< short, float >::Type_t
float Type_t
Definition
TypeComputations.h:185
Promote< short, int >::Type_t
int Type_t
Definition
TypeComputations.h:175
Promote< short, long >::Type_t
long Type_t
Definition
TypeComputations.h:180
Promote< short, short >::Type_t
short Type_t
Definition
TypeComputations.h:170
Promote
Definition
TypeComputations.h:80
Promote::Type_t
T1 Type_t
Definition
TypeComputations.h:80
TrinaryReturn
Definition
TypeComputations.h:398
Type_t::Type_t
BinaryReturn< B, C, Op >::Type_t Type_t
Definition
TypeComputations.h:399
UnaryReturn
Definition
TypeComputations.h:62
Type_t::Type_t
A Type_t
Definition
TypeComputations.h:63
Generated by
1.16.1