From 9435375633e8a9306e8cc982fd552734be358112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Thu, 17 Feb 2022 11:32:51 +0100 Subject: [PATCH] Add a few static assertions --- src/mesh/ItemValueUtils.hpp | 9 ++++++--- src/utils/Array.hpp | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mesh/ItemValueUtils.hpp b/src/mesh/ItemValueUtils.hpp index 9c36db128..ef99f59e4 100644 --- a/src/mesh/ItemValueUtils.hpp +++ b/src/mesh/ItemValueUtils.hpp @@ -20,7 +20,8 @@ min(const ItemValue<DataType, item_type, ConnectivityPtr>& item_value) using data_type = std::remove_const_t<typename ItemValueType::data_type>; using index_type = typename ItemValueType::index_type; - static_assert(not std::is_same_v<data_type, bool>, "min cannot be called on boolean arrays"); + static_assert(std::is_arithmetic_v<data_type>, "min cannot be called on non-arithmetic data"); + static_assert(not std::is_same_v<data_type, bool>, "min cannot be called on boolean data"); class ItemValueMin { @@ -113,7 +114,9 @@ max(const ItemValue<DataType, item_type, ConnectivityPtr>& item_value) using data_type = std::remove_const_t<typename ItemValueType::data_type>; using index_type = typename ItemValueType::index_type; - static_assert(not std::is_same_v<data_type, bool>, "min cannot be called on boolean arrays"); + static_assert(std::is_arithmetic_v<data_type>, "max cannot be called on non arithmetic data"); + static_assert(not std::is_same_v<data_type, bool>, "max cannot be called on boolean data"); + class ItemValueMax { private: @@ -205,7 +208,7 @@ sum(const ItemValue<DataType, item_type, ConnectivityPtr>& item_value) using data_type = std::remove_const_t<typename ItemValueType::data_type>; using index_type = typename ItemValueType::index_type; - static_assert(not std::is_same_v<data_type, bool>, "sum cannot be called on boolean arrays"); + static_assert(not std::is_same_v<data_type, bool>, "sum cannot be called on boolean data"); class ItemValueSum { diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp index f78f54308..ca8a6ea6b 100644 --- a/src/utils/Array.hpp +++ b/src/utils/Array.hpp @@ -189,6 +189,9 @@ min(const Array<DataType>& array) using data_type = std::remove_const_t<typename ArrayType::data_type>; using index_type = typename ArrayType::index_type; + static_assert(std::is_arithmetic_v<data_type>, "min cannot be called on non-arithmetic data"); + static_assert(not std::is_same_v<data_type, bool>, "min cannot be called on boolean data"); + class ArrayMin { private: @@ -249,6 +252,9 @@ max(const Array<DataType>& array) using data_type = std::remove_const_t<typename ArrayType::data_type>; using index_type = typename ArrayType::index_type; + static_assert(std::is_arithmetic_v<data_type>, "max cannot be called on non-arithmetic data"); + static_assert(not std::is_same_v<data_type, bool>, "max cannot be called on boolean data"); + class ArrayMax { private: @@ -309,6 +315,8 @@ sum(const Array<DataType>& array) using data_type = std::remove_const_t<DataType>; using index_type = typename ArrayType::index_type; + static_assert(not std::is_same_v<data_type, bool>, "sum cannot be called on boolean data"); + class ArraySum { private: -- GitLab