]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid std::abs() on unsigned types.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 20 Oct 2017 07:23:59 +0000 (09:23 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 20 Oct 2017 07:28:08 +0000 (09:28 +0200)
include/deal.II/base/partitioner.templates.h

index b42a1118eade9e4f1a591f4842c028c1d59840aa..1e3a15691307c71751d73e815effecdb328c36cb 100644 (file)
@@ -20,6 +20,8 @@
 #include <deal.II/base/partitioner.h>
 #include <deal.II/lac/la_parallel_vector.h>
 
+#include <type_traits>
+
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -281,6 +283,31 @@ namespace Utilities
 
 
 
+    namespace
+    {
+      // In the import_from_ghosted_array_finish we need to invoke abs() also
+      // on unsigned data types, which is ill-formed on newer C++
+      // standards. To avoid this, we use std::abs on default types but
+      // simply return the number on unsigned types
+      template <typename Number>
+      typename std::enable_if<!std::is_unsigned<Number>::value,
+               typename numbers::NumberTraits<Number>::real_type>::type
+               get_abs (const Number a)
+      {
+        return std::abs(a);
+      }
+
+      template <typename Number>
+      typename std::enable_if<std::is_unsigned<Number>::value, Number>::type
+      get_abs (const Number a)
+      {
+        return a;
+      }
+
+    }
+
+
+
     template <typename Number>
     void
     Partitioner::import_from_ghosted_array_finish(const VectorOperation::values  vector_operation,
@@ -352,8 +379,8 @@ namespace Utilities
                 // the face, values on this face obtained from each side might
                 // be different due to additions being done in different order.
                 Assert(*read_position == Number() ||
-                       std::abs(locally_owned_array[j] - *read_position) <=
-                       std::abs(locally_owned_array[j] + *read_position) *
+                       get_abs(locally_owned_array[j] - *read_position) <=
+                       get_abs(locally_owned_array[j] + *read_position) *
                        100000. *
                        std::numeric_limits<typename numbers::NumberTraits<Number>::real_type>::epsilon(),
                        typename LinearAlgebra::distributed::Vector<Number>::

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.