Skip to content

Commit 8c64330

Browse files
committed
refactor: horrible_cast implementation
1 parent 9325fbd commit 8c64330

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

include/libimp/horrible_cast.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ union temp {
2323
} // namespace detail_horrible_cast
2424

2525
template <typename T, typename U>
26-
constexpr auto horrible_cast(U &&in) noexcept
27-
-> std::enable_if_t<(sizeof(T) == sizeof(std::decay_t<U>)), T> {
28-
return detail_horrible_cast::temp<T, std::decay_t<U>>{std::forward<U>(in)}.out;
26+
constexpr T horrible_cast(U &&in) noexcept {
27+
return detail_horrible_cast::temp<T, U>{std::forward<U>(in)}.out;
2928
}
3029

3130
LIBIMP_NAMESPACE_END_

test/imp/test_imp_utility.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ TEST(utility, horrible_cast) {
143143
EXPECT_EQ(b.a_[0], 0);
144144
#endif
145145

146-
// imp::horrible_cast<std::uint32_t>(0ll);
146+
#if LIBIMP_ENDIAN_LIT
147+
EXPECT_EQ(imp::horrible_cast<std::uint32_t>(0xff00'0000'0001ll), 1);
148+
#else
149+
EXPECT_EQ(imp::horrible_cast<std::uint32_t>(0xff00'0000'0001ll), 0xff00);
150+
#endif
147151
}
148152

149153
#if defined(LIBIMP_CPP_17)

0 commit comments

Comments
 (0)