|
10 | 10 | #include <cstring> |
11 | 11 | #include <limits> |
12 | 12 | #include <system_error> |
13 | | -#if __cplusplus >= 202300L || _MSVC_LANG >= 202300L |
14 | | - #include <stdfloat> |
| 13 | +#ifdef __has_include |
| 14 | + #if __has_include(<stdfloat>) |
| 15 | + #include <stdfloat> |
| 16 | + #endif |
15 | 17 | #endif |
16 | 18 | namespace fast_float { |
17 | 19 |
|
@@ -135,33 +137,59 @@ fastfloat_really_inline bool rounds_to_nearest() noexcept { |
135 | 137 |
|
136 | 138 | } // namespace detail |
137 | 139 |
|
138 | | -template<typename T, typename UC> |
139 | | -FASTFLOAT_CONSTEXPR20 |
140 | | -from_chars_result_t<UC> from_chars(UC const * first, UC const * last, |
141 | | - T &value, chars_format fmt /*= chars_format::general*/) noexcept { |
142 | | -#if __cplusplus >= 202300L || _MSVC_LANG >= 202300L |
143 | | - #ifdef __STDCPP_FLOAT32_T__ |
144 | | - // if std::float32_t is defined, and we are in C++23 mode; macro set for float32; |
145 | | - // set value to float due to equivalence between float and float32_t |
146 | | - if(std::is_same<T, std::float32_t>::value){ |
147 | | - float value32; |
148 | | - from_chars_result_t<UC> ret = from_chars_advanced(first, last, value32, parse_options_t<UC>{fmt}); |
149 | | - value = value32; |
| 140 | +template <typename T> |
| 141 | +struct from_chars_caller |
| 142 | +{ |
| 143 | + template <typename UC> |
| 144 | + FASTFLOAT_CONSTEXPR20 |
| 145 | + static from_chars_result_t<UC> call(UC const * first, UC const * last, |
| 146 | + T &value, parse_options_t<UC> options) noexcept { |
| 147 | + return from_chars_advanced(first, last, value, options); |
| 148 | + } |
| 149 | +}; |
| 150 | + |
| 151 | +#if __STDCPP_FLOAT32_T__ == 1 |
| 152 | +template <> |
| 153 | +struct from_chars_caller<std::float32_t> |
| 154 | +{ |
| 155 | + template <typename UC> |
| 156 | + FASTFLOAT_CONSTEXPR20 |
| 157 | + static from_chars_result_t<UC> call(UC const * first, UC const * last, |
| 158 | + std::float32_t &value, parse_options_t<UC> options) noexcept{ |
| 159 | + // if std::float32_t is defined, and we are in C++23 mode; macro set for float32; |
| 160 | + // set value to float due to equivalence between float and float32_t |
| 161 | + float val; |
| 162 | + auto ret = from_chars_advanced(first, last, val, options); |
| 163 | + value = val; |
150 | 164 | return ret; |
151 | 165 | } |
152 | | - #endif |
153 | | - #ifdef __STDCPP_FLOAT64_T__ |
154 | | - // if std::float64_t is defined, and we are in C++23 mode; macro set for float64; |
155 | | - // set value as double due to equivalence between double and float64_t |
156 | | - if(std::is_same<T, std::float64_t>::value){ |
157 | | - double value64; |
158 | | - from_chars_result_t<UC> ret = from_chars_advanced(first, last, value64, parse_options_t<UC>{fmt}); |
159 | | - value = value64; |
| 166 | +}; |
| 167 | +#endif |
| 168 | + |
| 169 | +#if __STDCPP_FLOAT64_T__ == 1 |
| 170 | +template <> |
| 171 | +struct from_chars_caller<std::float64_t> |
| 172 | +{ |
| 173 | + template <typename UC> |
| 174 | + FASTFLOAT_CONSTEXPR20 |
| 175 | + static from_chars_result_t<UC> call(UC const * first, UC const * last, |
| 176 | + std::float64_t &value, parse_options_t<UC> options) noexcept{ |
| 177 | + // if std::float64_t is defined, and we are in C++23 mode; macro set for float64; |
| 178 | + // set value as double due to equivalence between double and float64_t |
| 179 | + double val; |
| 180 | + auto ret = from_chars_advanced(first, last, val, options); |
| 181 | + value = val; |
160 | 182 | return ret; |
161 | 183 | } |
162 | | - #endif |
| 184 | +}; |
163 | 185 | #endif |
164 | | - return from_chars_advanced(first, last, value, parse_options_t<UC>{fmt}); |
| 186 | + |
| 187 | + |
| 188 | +template<typename T, typename UC> |
| 189 | +FASTFLOAT_CONSTEXPR20 |
| 190 | +from_chars_result_t<UC> from_chars(UC const * first, UC const * last, |
| 191 | + T &value, chars_format fmt /*= chars_format::general*/) noexcept { |
| 192 | + return from_chars_caller<T>::call(first, last, value, parse_options_t<UC>(fmt)); |
165 | 193 | } |
166 | 194 |
|
167 | 195 | template<typename T, typename UC> |
|
0 commit comments