Skip to content

Commit

Permalink
cleanup header, add any type check - #15
Browse files Browse the repository at this point in the history
  • Loading branch information
timdewhirst committed Feb 7, 2023
1 parent cea2b96 commit 3d52723
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openpiv/core/enum_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <vector>

/// EnumHelper provides a standard way to produce string representations
/// of enumerations. The enum mapping is not particularly efficient being
Expand Down
16 changes: 14 additions & 2 deletions openpiv/core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ To checked_unsigned_conversion(const From& v);
template <typename To, typename... From>
struct are_all_convertible
{
constexpr static bool value = (std::is_convertible<From,To>::value && ...);
constexpr static bool value = (std::is_convertible_v<From,To> && ...);
};


Expand All @@ -103,12 +103,24 @@ inline constexpr bool are_all_convertible_v = are_all_convertible<To, From...>::
template <typename TypeA, typename... TypeB>
struct are_all_equal
{
constexpr static bool value = (std::is_same<TypeA, TypeB>::value && ...);
constexpr static bool value = (std::is_same_v<TypeA, TypeB> && ...);
};

template <typename To, typename... From>
inline constexpr bool are_all_equal_v = are_all_equal<To, From...>::value;


template <typename TypeA, typename... TypeB>
struct are_any_equal
{
constexpr static bool value = (std::is_same_v<TypeA, TypeB> || ...);
};


template <typename To, typename... From>
inline constexpr bool are_any_equal_v = are_any_equal<To, From...>::value;


template<typename Dest, typename Src, std::size_t N>
auto convert_array_to(const std::array<Src, N> &src) -> std::array<Dest, N>;

Expand Down
13 changes: 13 additions & 0 deletions test/util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, int, double, char> );
REQUIRE( are_any_equal_v<double, double, char, int> );
REQUIRE( are_any_equal_v<double, char, int, double> );
}

TEST_CASE("util_test - are_any_equal_false")
{
bool b{ are_all_equal_v<double, char, int, float> };
REQUIRE(!b);
}

TEST_CASE("util_test - convert_array")
{
std::array<int, 4> i{ {1, 2, 3, 4} };
Expand Down

0 comments on commit 3d52723

Please sign in to comment.