Merge pull request #922 from atgeirr/from_char-workaround

Add workaround for libc++ incomplete from_chars().
This commit is contained in:
Bård Skaflestad 2024-08-12 18:38:22 +02:00 committed by GitHub
commit 8d382f7dcb

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