Add workaround from libc++ incomplete from_chars().

Float version not included in current version (15).
This commit is contained in:
Atgeirr Flø Rasmussen 2024-08-12 11:56:48 +02:00
parent 1a2cfa7a26
commit c1e2a3a9b3

View File

@ -41,6 +41,7 @@
#include <dune/common/classname.hh>
#include <dune/common/parametertree.hh>
#include <cstdlib>
#include <charconv>
#include <fstream>
#include <iostream>
@ -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<ParamType>) {
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