30 namespace json_details {
32 template<
typename Real,
typename =
void>
33 inline constexpr bool has_precise_fallback_v =
34 std::is_same_v<Real, float> or std::is_same_v<Real, double> or
35 std::is_same_v<Real, long double>;
37#if not defined( DAW_JSON_USE_STRTOD )
38 template<
typename Real>
39 inline constexpr bool has_precise_fallback_v<
40 Real, std::void_t<
decltype( std::from_chars(
41 std::declval<char const *>( ), std::declval<char const *>( ),
42 std::declval<Real &>( ) ) )>> = std::is_floating_point_v<Real>;
49 template<
typename Real>
50 DAW_ATTRIB_NOINLINE [[nodiscard]] Real
51 parse_with_strtod( daw::not_null<char const *> first,
52 daw::not_null<char const *> last ) {
53 static_assert( std::is_floating_point_v<Real>,
54 "Unexpected type passed to parse_with_strtod" );
55#if defined( DAW_JSON_USE_STRTOD )
58 if constexpr( std::is_same_v<Real, float> ) {
59 return static_cast<Real
>( std::strtof( first, end ) );
60 }
else if constexpr( std::is_same_v<Real, double> ) {
61 return static_cast<Real
>( std::strtod( first, end ) );
63 return static_cast<Real
>( std::strtold( first, end ) );
67 auto fc_res = std::from_chars( first, last, result );
68 if( fc_res.ec == std::errc::result_out_of_range ) {
72 auto const token = std::string( first.get( ), last.get( ) );
73 if constexpr( std::is_same_v<Real, float> ) {
74 return std::strtof( token.c_str( ),
nullptr );
75 }
else if constexpr( std::is_same_v<Real, double> ) {
76 return std::strtod( token.c_str( ),
nullptr );
78 return static_cast<Real
>( std::strtold( token.c_str( ),
nullptr ) );
82 ErrorReason::InvalidNumber );