Skip to content

Commit

Permalink
Merge pull request #592 from boschglobal/iox-#591-stdvoid-used-in-code
Browse files Browse the repository at this point in the history
iox-#591 Added void_t to type_traits
  • Loading branch information
marthtz authored Mar 4, 2021
2 parents b411f5e + f0f24b4 commit 9daa95d
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 9daa95d

Please sign in to comment.