From d8605b50b0471c05b00f395cb10b10dbba14c0c7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 11 Dec 2023 19:58:35 +0100 Subject: [PATCH] Ensure `chars_format` is defined for older versions of libstdc++ Versions older than 10 don't even define this enum class. Note that libc++ always seems to define it even though it doesn't implement the FP overloads at all at this point. By the way, this means the minimum GCC version is 8 and the minimum libc++ version is 7 because for this code to work the `charconv` header still needs to be present at all. --- chrono/timespan.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chrono/timespan.cpp b/chrono/timespan.cpp index c0843c2..d77c8c7 100644 --- a/chrono/timespan.cpp +++ b/chrono/timespan.cpp @@ -17,8 +17,14 @@ using namespace std; namespace CppUtilities { /// \cond -inline std::from_chars_result from_chars( - const char *first, const char *last, double &value, std::chars_format fmt = std::chars_format::general) noexcept + +#if defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 10 +enum class chars_format { scientific = 1, fixed = 2, hex = 4, general = fixed | scientific }; +#else +using char_format = std::chars_format; +#endif + +inline std::from_chars_result from_chars(const char *first, const char *last, double &value, chars_format fmt = chars_format::general) noexcept { #if defined(_LIBCPP_VERSION) || (defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 11) // workaround std::from_chars() not being implemented for floating point numbers in libc++ and older libstdc++ versions