From 3d52723da8f265705cd1a9411d6cfbedbd7d1660 Mon Sep 17 00:00:00 2001 From: Tim Dewhirst Date: Tue, 7 Feb 2023 00:25:01 +0000 Subject: [PATCH] cleanup header, add any type check - #15 --- openpiv/core/enum_helper.h | 2 +- openpiv/core/util.h | 16 ++++++++++++++-- test/util_test.cpp | 13 +++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/openpiv/core/enum_helper.h b/openpiv/core/enum_helper.h index d4cde42..6d8bce1 100644 --- a/openpiv/core/enum_helper.h +++ b/openpiv/core/enum_helper.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include /// EnumHelper provides a standard way to produce string representations /// of enumerations. The enum mapping is not particularly efficient being diff --git a/openpiv/core/util.h b/openpiv/core/util.h index 72d82a6..d3a87f7 100644 --- a/openpiv/core/util.h +++ b/openpiv/core/util.h @@ -93,7 +93,7 @@ To checked_unsigned_conversion(const From& v); template struct are_all_convertible { - constexpr static bool value = (std::is_convertible::value && ...); + constexpr static bool value = (std::is_convertible_v && ...); }; @@ -103,12 +103,24 @@ inline constexpr bool are_all_convertible_v = are_all_convertible:: template struct are_all_equal { - constexpr static bool value = (std::is_same::value && ...); + constexpr static bool value = (std::is_same_v && ...); }; template inline constexpr bool are_all_equal_v = are_all_equal::value; + +template +struct are_any_equal +{ + constexpr static bool value = (std::is_same_v || ...); +}; + + +template +inline constexpr bool are_any_equal_v = are_any_equal::value; + + template auto convert_array_to(const std::array &src) -> std::array; diff --git a/test/util_test.cpp b/test/util_test.cpp index 933dc5d..bbe4b02 100644 --- a/test/util_test.cpp +++ b/test/util_test.cpp @@ -143,6 +143,19 @@ TEST_CASE("util_test - are_all_equal_false") REQUIRE(!b); } +TEST_CASE("util_test - are_any_equal_true") +{ + REQUIRE( are_any_equal_v ); + REQUIRE( are_any_equal_v ); + REQUIRE( are_any_equal_v ); +} + +TEST_CASE("util_test - are_any_equal_false") +{ + bool b{ are_all_equal_v }; + REQUIRE(!b); +} + TEST_CASE("util_test - convert_array") { std::array i{ {1, 2, 3, 4} };