Fall back to fast_float when C++ stdlib doesn't provide from_chars for floats
Date: Tue, 06 Aug 2024 10:26:26 UTC
Hello all, On deskutils/treesheets port, upstream did some updated that broke build. After investigating it upstream says we are building with an outdated C++ standard lib. To fix it, I'm using a fall back to fast_float as we see in main PR: https://github.com/aardappel/treesheets/issues/686 As I don't have skills to understand why this fix works, I'd like to have some expert opinion on this fix since I don't know if this will be supported in the furure. Resuming we added __FreeBSD__ to fall back in code already present: <snip> template<typename T> T parse_float(string_view sv, const char **end = nullptr) { // FIXME: Upgrade compilers for these platforms on CI. - #if defined(__APPLE__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) + #if defined(__APPLE__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__FreeBSD__) auto &term = *(char *)(sv.data() + sv.size()); auto orig = term; term = 0; auto v = (T)strtod(sv.data(), (char **)end); term = orig; return v; #else T val = 0; auto res = from_chars(sv.data(), sv.data() + sv.size(), val); if (end) *end = res.ptr; return val; #endif } <snip> Commit is https://cgit.freebsd.org/ports/commit/?id=4ffd449f0cfdbef7d1c78442ad3ea0be9ab12ea3 Thanks, -- Nuno Teixeira FreeBSD UNIX: <eduardo@FreeBSD.org> Web: https://FreeBSD.org