From 86667319ef2289890b58413a6f1c1426fda42b81 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Fri, 20 Oct 2017 09:23:59 +0200 Subject: [PATCH] Avoid std::abs() on unsigned types. --- include/deal.II/base/partitioner.templates.h | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/include/deal.II/base/partitioner.templates.h b/include/deal.II/base/partitioner.templates.h index b42a1118ea..1e3a156913 100644 --- a/include/deal.II/base/partitioner.templates.h +++ b/include/deal.II/base/partitioner.templates.h @@ -20,6 +20,8 @@ #include #include +#include + 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 std::enable_if::value, + typename numbers::NumberTraits::real_type>::type + get_abs (const Number a) + { + return std::abs(a); + } + + template + typename std::enable_if::value, Number>::type + get_abs (const Number a) + { + return a; + } + + } + + + template 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::real_type>::epsilon(), typename LinearAlgebra::distributed::Vector:: -- 2.39.5