4 #ifndef LEXY_CALLBACK_BIT_CAST_HPP_INCLUDED
5 #define LEXY_CALLBACK_BIT_CAST_HPP_INCLUDED
9 #ifndef LEXY_HAS_BITCAST
10 # if defined(__has_builtin)
11 # if __has_builtin(__builtin_bit_cast)
12 # define LEXY_HAS_BITCAST 2
17 #ifndef LEXY_HAS_BITCAST
18 # if defined(__has_include)
19 # if __has_include(<bit>) && __cplusplus >= 202002L
21 # ifdef __cpp_lib_bit_cast
22 # define LEXY_HAS_BITCAST 1
28 #ifndef LEXY_HAS_BITCAST
29 # define LEXY_HAS_BITCAST 0
32 #if LEXY_HAS_BITCAST == 2
33 # define LEXY_BITCAST_CONSTEXPR constexpr
34 #elif LEXY_HAS_BITCAST == 1
35 # define LEXY_BITCAST_CONSTEXPR constexpr
38 # define LEXY_BITCAST_CONSTEXPR
46 static_assert(std::is_trivially_copyable_v<T>);
51 && std::is_trivially_copyable_v<Arg>>>
54 #if LEXY_HAS_BITCAST == 2
56 return __builtin_bit_cast(T, arg);
58 #elif LEXY_HAS_BITCAST == 1
60 return std::bit_cast<T>(arg);
64 static_assert(std::is_default_constructible_v<T>,
"sorry, get a better standard library");
67 std::memcpy(&to, &arg,
sizeof(T));
79 #endif // LEXY_CALLBACK_BIT_CAST_HPP_INCLUDED