From a26b981f45dd0d5441c0e300a6aa945b811fef5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 15 Aug 2024 09:55:50 +0200 Subject: [PATCH] Don't Require Floating Point from_chars() Function This commit broadens the scope of commit 2ad332e0b (PR #922) to apply to all compilers/libraries, not just Clang/libc++, which do not have support for floating-point types in std::from_chars(). While hopefully a transient situation, this enables building the parameter system with GCC versions prior to GCC 11. We expect to require version 11 in the not too distant future, though. At that point we should revert this commit. We use a configure-time feature test of the compiler (CMake command 'try_compile') to detect whether or not the compiler supports floating-point overloads of std::from_chars() and emit the result to config.h as the new preprocessor symbol HAVE_FLOATING_POINT_FROM_CHARS We use std::strtod() as the fall-back alternative for floating point conversion if this symbol is defined to false (zero). --- cmake/test/testFloatFromChars.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 cmake/test/testFloatFromChars.cpp diff --git a/cmake/test/testFloatFromChars.cpp b/cmake/test/testFloatFromChars.cpp new file mode 100644 index 000000000..859ef3f11 --- /dev/null +++ b/cmake/test/testFloatFromChars.cpp @@ -0,0 +1,11 @@ +// CMake feature test for floating-point std::from_chars() support + +#include +#include + +int main() +{ + const auto s = std::string_view { "2.71828" }; + auto e = 0.0; + std::from_chars(s.data(), s.data() + s.size(), e); +}