From 122726fe65eb0ad470675ee63cf1d17d845b253a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 28 Feb 2020 17:00:16 +1000 Subject: [PATCH] Common/StringUtil: Support compiling on gcc7 --- src/common/string_util.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/string_util.h b/src/common/string_util.h index fb6ff676c..6380d775b 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -1,11 +1,16 @@ #pragma once -#include #include #include #include #include #include +#if __cplusplus >= 201703L +#include +#else +#include +#endif + namespace StringUtil { /// Constructs a std::string from a format string. @@ -33,11 +38,21 @@ template std::optional FromChars(const std::string_view str) { T value; + +#if __cplusplus >= 201703L + T value; const std::from_chars_result result = std::from_chars(str.data(), str.data() + str.length(), value); if (result.ec != std::errc()) return std::nullopt; +#else + std::string temp(str); + std::istringstream ss(temp); + ss >> value; + if (ss.fail()) + return std::nullopt; +#endif return value; } -} // namespace StringUtil \ No newline at end of file +} // namespace StringUtil