v0.14.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  DECLARE_PROMOTE(const double, std::complex<double>, std::complex<double>);
34  DECLARE_PROMOTE(const std::complex<double>, double, std::complex<double>);
35  DECLARE_PROMOTE(double, const std::complex<double>, std::complex<double>);
36  DECLARE_PROMOTE(std::complex<double>, const double, std::complex<double>);
37  DECLARE_PROMOTE(const std::complex<double>, const double,
38  std::complex<double>);
39  DECLARE_PROMOTE(const double, const std::complex<double>,
40  std::complex<double>);
41 
42 #ifdef WITH_ADOL_C
47  DECLARE_PROMOTE(adtl::adouble, double, adtl::adouble);
48  DECLARE_PROMOTE(double, adtl::adouble, adtl::adouble);
49  DECLARE_PROMOTE(adtl::adouble, int, adtl::adouble);
50  DECLARE_PROMOTE(int, adtl::adouble, adtl::adouble);
51  DECLARE_PROMOTE(adub, double, adub);
52  DECLARE_PROMOTE(double, adub, adub);
53  DECLARE_PROMOTE(adub, int, adub);
54  DECLARE_PROMOTE(int, adub, adub);
55 #endif // WITH_ADOL_C
56 
57 #undef DECLARE_PROMOTE
58 } // namespace FTensor
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::DECLARE_PROMOTE
DECLARE_PROMOTE(int, double, double)
FTensor::promote::V
T1 V
Definition: promote.hpp:17
adouble
FTensor::promote
Definition: promote.hpp:14