Skip to content

Commit d8605b5

Browse files
committed
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.
1 parent 1264a7e commit d8605b5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

chrono/timespan.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ using namespace std;
1717
namespace CppUtilities {
1818

1919
/// \cond
20-
inline std::from_chars_result from_chars(
21-
const char *first, const char *last, double &value, std::chars_format fmt = std::chars_format::general) noexcept
20+
21+
#if defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 10
22+
enum class chars_format { scientific = 1, fixed = 2, hex = 4, general = fixed | scientific };
23+
#else
24+
using char_format = std::chars_format;
25+
#endif
26+
27+
inline std::from_chars_result from_chars(const char *first, const char *last, double &value, chars_format fmt = chars_format::general) noexcept
2228
{
2329
#if defined(_LIBCPP_VERSION) || (defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 11)
2430
// workaround std::from_chars() not being implemented for floating point numbers in libc++ and older libstdc++ versions

0 commit comments

Comments
 (0)