blob: 1780f6676eb2921a3bbae1c1d01f8b8c8e6d9197 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
diff --git a/include/__bit/bit_cast.h b/include/__bit/bit_cast.h
index fc29a74..10c2c94 100644
--- a/include/__bit/bit_cast.h
+++ b/include/__bit/bit_cast.h
@@ -31,6 +31,19 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
constexpr _ToType bit_cast(_FromType const& __from) noexcept {
return __builtin_bit_cast(_ToType, __from);
}
+#else _LIBCPP_STD_VER > 14
+
+template<class _ToType, class _FromType, class = enable_if_t<
+ sizeof(_ToType) == sizeof(_FromType) &&
+ is_trivially_copyable<_ToType>::value &&
+ is_trivially_copyable<_FromType>::value
+>>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
+constexpr _ToType bit_cast(_FromType const& __from) noexcept {
+ _ToType __to;
+ ::memcpy(&__to, &__from, sizeof(__from));
+ return __to;
+}
#endif // _LIBCPP_STD_VER > 17
|