15 #include <daw/daw_attributes.h>
16 #include <daw/daw_cpp_feature_check.h>
20 #include <system_error>
21 #include <type_traits>
23 #if not defined( DAW_JSON_USE_STRTOD )
29 namespace json_details {
34 template<
typename Real>
35 DAW_ATTRIB_NOINLINE DAW_ATTRIB_NONNULL( ) [[nodiscard]] Real
36 parse_with_strtod(
char const *first,
char const *last ) {
37 static_assert( std::is_floating_point_v<Real>,
38 "Unexpected type passed to parse_with_strtod" );
39 #if defined( DAW_JSON_USE_STRTOD )
42 if constexpr( std::is_same_v<Real, float> ) {
43 return static_cast<Real
>( std::strtof( first, end ) );
44 }
else if( std::is_same_v<Real, double> ) {
45 return static_cast<Real
>( std::strtod( first, end ) );
47 return static_cast<Real
>( std::strtold( first, end ) );
51 auto fc_res = std::from_chars( first, last, result );
52 if( fc_res.ec == std::errc::result_out_of_range ) {
54 return -std::numeric_limits<Real>::infinity( );
56 return std::numeric_limits<Real>::infinity( );
59 ErrorReason::InvalidNumber );
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.