BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
scalar_traits.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef fiber_scalar_traits_hpp
22 #define fiber_scalar_traits_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include <complex>
27 
28 namespace Fiber
29 {
30 
39 template <typename T>
41 {
42  // If you get a compilation error here, you are probably trying to use an
43  // unsupported floating-point type. The supported types are: float, double,
44  // std::complex<float> and std::complex<double>.
45 };
46 
47 template <>
48 struct ScalarTraits<float>
49 {
50  typedef float RealType;
51  typedef std::complex<float> ComplexType;
52 };
53 
54 template <>
55 struct ScalarTraits<double>
56 {
57  typedef double RealType;
58  typedef std::complex<double> ComplexType;
59 };
60 
61 template <>
62 struct ScalarTraits<std::complex<float> >
63 {
64  typedef float RealType;
65  typedef std::complex<float> ComplexType;
66 };
67 
68 template <>
69 struct ScalarTraits<std::complex<double> >
70 {
71  typedef double RealType;
72  typedef std::complex<double> ComplexType;
73 };
74 
76 template <typename U, typename V>
77 struct Coercion
78 {
79  // If you get a compilation error here, chances are that you are trying to
80  // mix floating-point numbers with different precisions (e.g. float and
81  // double or std::complex<float> and double). BEM++ does not support this.
82 };
83 
84 template <>
85 struct Coercion<float, float>
86 {
87  typedef float Type;
88 };
89 
90 template <>
91 struct Coercion<double, double>
92 {
93  typedef double Type;
94 };
95 
96 template <>
97 struct Coercion<std::complex<float>, std::complex<float> >
98 {
99  typedef std::complex<float> Type;
100 };
101 
102 template <>
103 struct Coercion<std::complex<double>, std::complex<double> >
104 {
105  typedef std::complex<double> Type;
106 };
107 
108 template <>
109 struct Coercion<float, std::complex<float> >
110 {
111  typedef std::complex<float> Type;
112 };
113 
114 template <>
115 struct Coercion<std::complex<float>, float>
116 {
117  typedef std::complex<float> Type;
118 };
119 
120 template <>
121 struct Coercion<double, std::complex<double> >
122 {
123  typedef std::complex<double> Type;
124 };
125 
126 template <>
127 struct Coercion<std::complex<double>, double>
128 {
129  typedef std::complex<double> Type;
130 };
131 
132 } // namespace Fiber
133 
134 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
&quot;Larger&quot; of the types U and V.
Definition: scalar_traits.hpp:77