Skip to content

Commit 64c16de

Browse files
committed
test fix
1 parent 1790677 commit 64c16de

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

libredex/StlUtil.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <algorithm>
11+
#include <cstring>
1112
#include <deque>
1213
#include <vector>
1314

@@ -45,9 +46,22 @@ size_t erase_if(Container& c, const Pred& pred) {
4546
return removed;
4647
}
4748

48-
template <typename To, typename From>
49-
constexpr To bit_cast(const From& from) noexcept {
50-
return __builtin_bit_cast(To, from);
49+
template<class To, class From>
50+
std::enable_if_t<
51+
sizeof(To) == sizeof(From) &&
52+
std::is_trivially_copyable_v<From> &&
53+
std::is_trivially_copyable_v<To>,
54+
To>
55+
// constexpr support needs compiler magic
56+
bit_cast(const From& src) noexcept
57+
{
58+
static_assert(std::is_trivially_constructible_v<To>,
59+
"This implementation additionally requires "
60+
"destination type to be trivially constructible");
61+
62+
To dst;
63+
std::memcpy(&dst, &src, sizeof(To));
64+
return dst;
5165
}
5266

5367
} // namespace std20

0 commit comments

Comments
 (0)