v0.9.0
promote.hpp
Go to the documentation of this file.
1 /* Traits that allow auto-promotion of int's to double's, double's to
2  complex, etc. Shamelessly stolen from
3 
4  http://extreme.indiana.edu/~tveldhui/papers/techniques/
5 
6  For now, only int, double, and complex<double> are covered. If you
7  want more, just insert a DECLARE_PROMOTE(A,B,C), where A and B are
8  the two types, and C is what they should be coerced to. */
9 
10 #pragma once
11 
12 namespace FTensor
13 {
14  template <class T1, class T2> class promote
15  {
16  public:
17  using V = T1;
18  };
19 
20 #define DECLARE_PROMOTE(A, B, C) \
21  template <> class promote<A, B> { \
22  public: \
23  using V = C; \
24  }
25 
26  DECLARE_PROMOTE(int, double, double);
27  DECLARE_PROMOTE(double, int, double);
28  DECLARE_PROMOTE(int, std::complex<double>, std::complex<double>);
29  DECLARE_PROMOTE(std::complex<double>, int, std::complex<double>);
30  DECLARE_PROMOTE(double, std::complex<double>, std::complex<double>);
31  DECLARE_PROMOTE(std::complex<double>, double, std::complex<double>);
32 
33 #ifdef WITH_ADOL_C
38  DECLARE_PROMOTE(adtl::adouble, double, adtl::adouble);
39  DECLARE_PROMOTE(double, adtl::adouble, adtl::adouble);
40  DECLARE_PROMOTE(adtl::adouble, int, adtl::adouble);
41  DECLARE_PROMOTE(int, adtl::adouble, adtl::adouble);
42 #endif // WITH_ADOL_C
43 
44 #undef DECLARE_PROMOTE
45 } // namespace FTensor
Fully Antisymmetric Levi-Civita Tensor.
DECLARE_PROMOTE(int, double, double)