We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1790677 commit f9f11bdCopy full SHA for f9f11bd
libredex/StlUtil.h
@@ -8,6 +8,7 @@
8
#pragma once
9
10
#include <algorithm>
11
+#include <cstring>
12
#include <deque>
13
#include <vector>
14
@@ -45,9 +46,15 @@ size_t erase_if(Container& c, const Pred& pred) {
45
46
return removed;
47
}
48
-template <typename To, typename From>
49
-constexpr To bit_cast(const From& from) noexcept {
50
- return __builtin_bit_cast(To, from);
+template <class To, class From>
+constexpr To bit_cast(const From& src) noexcept {
51
+ static_assert(std::is_trivially_constructible_v<To>,
52
+ "This implementation additionally requires "
53
+ "destination type to be trivially constructible");
54
+
55
+ To dst;
56
+ std::memcpy(&dst, &src, sizeof(To));
57
+ return dst;
58
59
60
} // namespace std20
0 commit comments