]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only allow floating point types in complex_overloads.h 8614/head
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 21 Aug 2019 13:19:19 +0000 (09:19 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Wed, 21 Aug 2019 13:22:23 +0000 (09:22 -0400)
doc/news/changes/incompatibilities/20190821DanielArndt [new file with mode: 0644]
include/deal.II/base/complex_overloads.h

diff --git a/doc/news/changes/incompatibilities/20190821DanielArndt b/doc/news/changes/incompatibilities/20190821DanielArndt
new file mode 100644 (file)
index 0000000..43cf76d
--- /dev/null
@@ -0,0 +1,4 @@
+Changed: The complex operator overloads for multiplication and division are
+restricted to floating point types.
+<br>
+(Daniel Arndt, 2019/08/21)
index 75eaf842eef2ed72c4b89ecb86a6e02078bbce90..7f29b3ea2c1c6e28d780a80097d16d7527e58159 100644 (file)
@@ -24,8 +24,6 @@ DEAL_II_NAMESPACE_OPEN
 
 // Forward declarations
 #ifndef DOXYGEN
-template <typename T>
-struct EnableIfScalar;
 template <typename T, typename U>
 struct ProductType;
 #endif
@@ -39,7 +37,9 @@ struct ProductType;
  * @relatesalso ProductType
  */
 template <typename T, typename U>
-inline typename ProductType<std::complex<T>, std::complex<U>>::type
+inline typename std::enable_if<
+  std::is_floating_point<T>::value && std::is_floating_point<U>::value,
+  typename ProductType<std::complex<T>, std::complex<U>>::type>::type
 operator*(const std::complex<T> &left, const std::complex<U> &right)
 {
   using result_type =
@@ -55,7 +55,9 @@ operator*(const std::complex<T> &left, const std::complex<U> &right)
  * @relatesalso ProductType
  */
 template <typename T, typename U>
-inline typename ProductType<std::complex<T>, std::complex<U>>::type
+inline typename std::enable_if<
+  std::is_floating_point<T>::value && std::is_floating_point<U>::value,
+  typename ProductType<std::complex<T>, std::complex<U>>::type>::type
 operator/(const std::complex<T> &left, const std::complex<U> &right)
 {
   using result_type =
@@ -68,12 +70,13 @@ operator/(const std::complex<T> &left, const std::complex<U> &right)
  * floating point type with a different real floating point type. Annoyingly,
  * the standard library does not provide such an operator...
  *
- * @relatesalso EnableIfScalar
  * @relatesalso ProductType
  */
 template <typename T, typename U>
 inline
-  typename ProductType<std::complex<T>, typename EnableIfScalar<U>::type>::type
+  typename std::enable_if<std::is_floating_point<T>::value &&
+                            std::is_floating_point<U>::value,
+                          typename ProductType<std::complex<T>, U>::type>::type
   operator*(const std::complex<T> &left, const U &right)
 {
   using result_type = typename ProductType<std::complex<T>, U>::type;
@@ -85,12 +88,13 @@ inline
  * floating point type with a different real floating point type. Annoyingly,
  * the standard library does not provide such an operator...
  *
- * @relatesalso EnableIfScalar
  * @relatesalso ProductType
  */
 template <typename T, typename U>
 inline
-  typename ProductType<std::complex<T>, typename EnableIfScalar<U>::type>::type
+  typename std::enable_if<std::is_floating_point<T>::value &&
+                            std::is_floating_point<U>::value,
+                          typename ProductType<std::complex<T>, U>::type>::type
   operator/(const std::complex<T> &left, const U &right)
 {
   using result_type = typename ProductType<std::complex<T>, U>::type;
@@ -102,15 +106,17 @@ inline
  * floating point type with a different complex floating point type.
  * Annoyingly, the standard library does not provide such an operator...
  *
- * @relatesalso EnableIfScalar
  * @relatesalso ProductType
  */
 template <typename T, typename U>
-inline
-  typename ProductType<typename EnableIfScalar<T>::type, std::complex<U>>::type
+inline typename
+
+  std::enable_if<std::is_floating_point<T>::value &&
+                   std::is_floating_point<U>::value,
+                 typename ProductType<T, std::complex<U>>::type>::type
   operator*(const T &left, const std::complex<U> &right)
 {
-  using result_type = typename ProductType<std::complex<T>, U>::type;
+  using result_type = typename ProductType<T, std::complex<U>>::type;
   return static_cast<result_type>(left) * static_cast<result_type>(right);
 }
 
@@ -119,15 +125,16 @@ inline
  * floating point type with a different complex floating point type.
  * Annoyingly, the standard library does not provide such an operator...
  *
- * @relatesalso EnableIfScalar
  * @relatesalso ProductType
  */
 template <typename T, typename U>
 inline
-  typename ProductType<typename EnableIfScalar<T>::type, std::complex<U>>::type
+  typename std::enable_if<std::is_floating_point<T>::value &&
+                            std::is_floating_point<U>::value,
+                          typename ProductType<T, std::complex<U>>::type>::type
   operator/(const T &left, const std::complex<U> &right)
 {
-  using result_type = typename ProductType<std::complex<T>, U>::type;
+  using result_type = typename ProductType<T, std::complex<U>>::type;
   return static_cast<result_type>(left) / static_cast<result_type>(right);
 }
 #endif /* DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS */

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.