From 209f5b05fb9ff0aa9fcb36dc11da3e6a035a62ef Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 21 Aug 2019 09:19:19 -0400 Subject: [PATCH] Only allow floating point types in complex_overloads.h --- .../incompatibilities/20190821DanielArndt | 4 ++ include/deal.II/base/complex_overloads.h | 37 +++++++++++-------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20190821DanielArndt diff --git a/doc/news/changes/incompatibilities/20190821DanielArndt b/doc/news/changes/incompatibilities/20190821DanielArndt new file mode 100644 index 0000000000..43cf76d39d --- /dev/null +++ b/doc/news/changes/incompatibilities/20190821DanielArndt @@ -0,0 +1,4 @@ +Changed: The complex operator overloads for multiplication and division are +restricted to floating point types. +
+(Daniel Arndt, 2019/08/21) diff --git a/include/deal.II/base/complex_overloads.h b/include/deal.II/base/complex_overloads.h index 75eaf842ee..7f29b3ea2c 100644 --- a/include/deal.II/base/complex_overloads.h +++ b/include/deal.II/base/complex_overloads.h @@ -24,8 +24,6 @@ DEAL_II_NAMESPACE_OPEN // Forward declarations #ifndef DOXYGEN -template -struct EnableIfScalar; template struct ProductType; #endif @@ -39,7 +37,9 @@ struct ProductType; * @relatesalso ProductType */ template -inline typename ProductType, std::complex>::type +inline typename std::enable_if< + std::is_floating_point::value && std::is_floating_point::value, + typename ProductType, std::complex>::type>::type operator*(const std::complex &left, const std::complex &right) { using result_type = @@ -55,7 +55,9 @@ operator*(const std::complex &left, const std::complex &right) * @relatesalso ProductType */ template -inline typename ProductType, std::complex>::type +inline typename std::enable_if< + std::is_floating_point::value && std::is_floating_point::value, + typename ProductType, std::complex>::type>::type operator/(const std::complex &left, const std::complex &right) { using result_type = @@ -68,12 +70,13 @@ operator/(const std::complex &left, const std::complex &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 inline - typename ProductType, typename EnableIfScalar::type>::type + typename std::enable_if::value && + std::is_floating_point::value, + typename ProductType, U>::type>::type operator*(const std::complex &left, const U &right) { using result_type = typename ProductType, 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 inline - typename ProductType, typename EnableIfScalar::type>::type + typename std::enable_if::value && + std::is_floating_point::value, + typename ProductType, U>::type>::type operator/(const std::complex &left, const U &right) { using result_type = typename ProductType, 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 -inline - typename ProductType::type, std::complex>::type +inline typename + + std::enable_if::value && + std::is_floating_point::value, + typename ProductType>::type>::type operator*(const T &left, const std::complex &right) { - using result_type = typename ProductType, U>::type; + using result_type = typename ProductType>::type; return static_cast(left) * static_cast(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 inline - typename ProductType::type, std::complex>::type + typename std::enable_if::value && + std::is_floating_point::value, + typename ProductType>::type>::type operator/(const T &left, const std::complex &right) { - using result_type = typename ProductType, U>::type; + using result_type = typename ProductType>::type; return static_cast(left) / static_cast(right); } #endif /* DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS */ -- 2.39.5