Skip to content

Commit cd61547

Browse files
committed
FASTFLOAT_HAS_BIT_CAST fix for old standards.
1 parent 051d151 commit cd61547

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/fast_float/float_common.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,23 @@ using parse_options = parse_options_t<char>;
251251
#endif
252252

253253
namespace fast_float {
254+
#if FASTFLOAT_HAS_BIT_CAST
254255
template <typename To, typename From>
255256
fastfloat_really_inline constexpr To bit_cast(const From &from) noexcept {
256-
#if FASTFLOAT_HAS_BIT_CAST
257257
return std::bit_cast<To>(from);
258+
}
258259
#else
260+
template <typename To, typename From>
261+
fastfloat_really_inline To bit_cast(const From &from) noexcept {
259262
// Implementation of std::bit_cast for pre-C++20.
260263
static_assert(sizeof(To) == sizeof(From),
261264
"bit_cast requires source and destination to be the same size");
262265
auto to = To();
263266
// The cast suppresses a bogus -Wclass-memaccess on GCC.
264267
std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
265268
return to;
266-
#endif
267269
}
270+
#endif
268271

269272
fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() noexcept {
270273
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED

0 commit comments

Comments
 (0)