DACE 2.0 API Manual
Differential Algebra Core Engine
PromotionTrait.h
Go to the documentation of this file.
1 /******************************************************************************
2 * *
3 * DIFFERENTIAL ALGEBRA CORE ENGINE *
4 * *
5 *******************************************************************************
6 * *
7 * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) *
8 * Licensed under the Apache License, Version 2.0 (the "License"); *
9 * you may not use this file except in compliance with the License. *
10 * You may obtain a copy of the License at *
11 * *
12 * http://www.apache.org/licenses/LICENSE-2.0 *
13 * *
14 * Unless required by applicable law or agreed to in writing, software *
15 * distributed under the License is distributed on an "AS IS" BASIS, *
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 * See the License for the specific language governing permissions and *
18 * limitations under the License. *
19 * *
20 *******************************************************************************/
21 
22 /*
23  * PromotionTrait.h
24  *
25  * Created on: Sep. 15, 2014
26  * Author: Dinamica Srl
27  */
28 
29 #ifndef DINAMICA_PROMOTIONTRAIT_H_
30 #define DINAMICA_PROMOTIONTRAIT_H_
31 
32 namespace DACE{
33 
34 // forward declaration
35 class DA;
36 
37 /***********************************************************************************
38  PromotionTrait template class
39 ************************************************************************************/
40 /* General template implementation:
41  By default, everything is a double and two things of the same type return that type. */
42 template<class T1, class T2> class PromotionTrait { public: typedef double returnType; };
43 template<class T> class PromotionTrait<T,T> { public: typedef T returnType; };
44 
45 // type A with B (and B with A) yields a C
46 #define ADD_PROMOTION(A,B,C) \
47  template<> class PromotionTrait<A,B> { public: typedef C returnType; }; \
48  template<> class PromotionTrait<B,A> { public: typedef C returnType; };
49 
50 // type A with any other type (and any other type with A) yields a C
51 // includes also the case A with A to resolve the problem of which template to use otherwise
52 #define ADD_PROMOTION_ALL(A,C) \
53  template<typename T> class PromotionTrait<A,T> { public: typedef C returnType; }; \
54  template<typename T> class PromotionTrait<T,A> { public: typedef C returnType; }; \
55  template<> class PromotionTrait<A,A> { public: typedef C returnType; };
56 
57 /* Specialization for DA: everything with DA returns a DA */
58 ADD_PROMOTION_ALL(DA,DA)
59 
60 #undef ADD_PROMOTION
61 #undef ADD_PROMOTION_ALL
62 }
63 
64 // not sure this is a good idea
65 //#define PROMOTE(A,B) typename PromotionTrait<A,B>::returnType
66 
67 #endif /* DINAMICA_PROMOTIONTRAIT_H_ */
double returnType
Definition: PromotionTrait.h:42
T returnType
Definition: PromotionTrait.h:43
#define ADD_PROMOTION_ALL(A, C)
Definition: PromotionTrait.h:52
Definition: AlgebraicMatrix.cpp:39
Definition: PromotionTrait.h:42