@@ -120,27 +120,6 @@ using parse_options = parse_options_t<char>;
120120
121121} // namespace fast_float
122122
123- #if FASTFLOAT_HAS_BIT_CAST
124- #include < bit>
125- #endif
126-
127- namespace fast_float {
128- template <typename To, typename From>
129- FASTFLOAT_CONSTEXPR20 To bit_cast (const From &from) noexcept {
130- #if FASTFLOAT_HAS_BIT_CAST
131- return std::bit_cast<To>(from);
132- #else
133- // Implementation of std::bit_cast for pre-C++20.
134- static_assert (sizeof (To) == sizeof (From),
135- " bit_cast requires source and destination to be the same size" );
136- auto to = To ();
137- // The cast suppresses a bogus -Wclass-memaccess on GCC.
138- std::memcpy (static_cast <void *>(&to), &from, sizeof (to));
139- return to;
140- #endif
141- }
142- } // namespace fast_float
143-
144123#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
145124 defined (__amd64) || defined(__aarch64__) || defined(_M_ARM64) || \
146125 defined(__MINGW64__) || defined(__s390x__) || \
@@ -269,7 +248,25 @@ FASTFLOAT_CONSTEXPR20 To bit_cast(const From &from) noexcept {
269248#define FASTFLOAT_ENABLE_IF (...) \
270249 typename std::enable_if<(__VA_ARGS__), int >::type
271250
251+ #if FASTFLOAT_HAS_BIT_CAST
252+ #include < bit>
253+ #endif
254+
272255namespace fast_float {
256+ template <typename To, typename From>
257+ constexpr fastfloat_really_inline To bit_cast (const From &from) noexcept {
258+ #if FASTFLOAT_HAS_BIT_CAST
259+ return std::bit_cast<To>(from);
260+ #else
261+ // Implementation of std::bit_cast for pre-C++20.
262+ static_assert (sizeof (To) == sizeof (From),
263+ " bit_cast requires source and destination to be the same size" );
264+ auto to = To ();
265+ // The cast suppresses a bogus -Wclass-memaccess on GCC.
266+ std::memcpy (static_cast <void *>(&to), &from, sizeof (to));
267+ return to;
268+ #endif
269+ }
273270
274271fastfloat_really_inline constexpr bool cpp20_and_in_constexpr () noexcept {
275272#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
@@ -1124,7 +1121,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
11241121 word =
11251122 equiv_uint (word | equiv_uint (negative) << binary_format<T>::sign_index ());
11261123#endif
1127- value = bit_cast<T, equiv_uint >(word);
1124+ value = bit_cast<T>(word);
11281125}
11291126
11301127#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
0 commit comments