Skip to content

Commit

Permalink
iox-eclipse-iceoryx#591 Added void_t to type_traits
Browse files Browse the repository at this point in the history
Signed-off-by: Hintz Martin (XC-AD/ESW1-J1) <[email protected]>
  • Loading branch information
marthtz committed Mar 3, 2021
1 parent b411f5e commit f0f24b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions iceoryx_utils/include/iceoryx_utils/cxx/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ template <typename T1, typename T2>
using not_same = typename std::
integral_constant<bool, !bool(std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value)>;

/// @brief Maps a sequence of any types to the type void
template <typename...>
using void_t = void;
} // namespace cxx
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct HasInvalidStateMember : std::false_type
{
};
template <typename T>
struct HasInvalidStateMember<T, std::void_t<decltype(T::INVALID_STATE)>> : std::true_type
struct HasInvalidStateMember<T, iox::cxx::void_t<decltype(T::INVALID_STATE)>> : std::true_type
{
};
template <typename... T>
Expand Down
38 changes: 38 additions & 0 deletions iceoryx_utils/test/moduletests/test_cxx_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,41 @@ TEST(TypeTraitsTest, NotSameIsFalse)
auto sut = not_same<int, int>::value;
EXPECT_FALSE(sut);
}

namespace iox
{
namespace cxx
{
namespace test
{
template <typename, typename = void>
struct has_mytype_as_member : std::false_type
{
};

template <typename T>
struct has_mytype_as_member<T, void_t<typename T::myType>> : std::true_type
{
};
} // namespace test
} // namespace cxx
} // namespace iox

TEST(TypeTraitsTest, NoTypeAsMemberIsFalse)
{
struct Sut
{
};

EXPECT_FALSE(iox::cxx::test::has_mytype_as_member<Sut>::value);
}

TEST(TypeTraitsTest, MyTypeAsMemberIsTrue)
{
struct Sut
{
using myType = int;
};

EXPECT_TRUE(iox::cxx::test::has_mytype_as_member<Sut>::value);
}

0 comments on commit f0f24b4

Please sign in to comment.