From c1e2a3a9b33ecae2000d623a164d7377df6f78a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 12 Aug 2024 11:56:48 +0200 Subject: [PATCH] Add workaround from libc++ incomplete from_chars(). Float version not included in current version (15). --- opm/models/utils/parametersystem.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/opm/models/utils/parametersystem.hh b/opm/models/utils/parametersystem.hh index f5f489132..7c6584abe 100644 --- a/opm/models/utils/parametersystem.hh +++ b/opm/models/utils/parametersystem.hh @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -924,7 +925,18 @@ auto Get(bool errorIfNotRegistered) defaultValue = defVal == "1"; } else { +#ifdef _LIBCPP_VERSION // If this macro is defined, clang's libc++ is used + // For floating point types, libc++ (the llvm/clang library implementation) + // does not yet (as of clang 15) offer an implementation of std::from_chars(). + if constexpr (std::is_integral_v) { + std::from_chars(defVal.data(), defVal.data() + defVal.size(), defaultValue); + } else { + // Floating point workaround. + defaultValue = std::strtod(defVal.c_str(), nullptr); + } +#else std::from_chars(defVal.data(), defVal.data() + defVal.size(), defaultValue); +#endif } // prefix the parameter name by the model's GroupName. E.g. If