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