diff options
Diffstat (limited to 'zen/legacy_compiler.cpp')
-rw-r--r-- | zen/legacy_compiler.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/zen/legacy_compiler.cpp b/zen/legacy_compiler.cpp index 81efb4dd..6c5489d5 100644 --- a/zen/legacy_compiler.cpp +++ b/zen/legacy_compiler.cpp @@ -5,22 +5,24 @@ // ***************************************************************************** #include "legacy_compiler.h" -#ifdef __cpp_lib_to_chars - #error get rid of workarounds -#endif +#include <charconv> +/* 1. including <charconv> in header file blows up VC++: + - string_tools.h: "An internal error has occurred in the compiler. (compiler file 'd:\agent\_work\1\s\src\vctools\Compiler\Utc\src\p2\p2symtab.c', line 2618)" + - PCH: "fatal error C1076: compiler limit: internal heap limit reached" + => include in separate compilation unit + 2. Disable "C/C++ -> Code Generation -> Smaller Type Check" (and PCH usage!), at least for this compilation unit: https://github.com/microsoft/STL/pull/171 */ double zen::fromChars(const char* first, const char* last) { - return std::strtod(std::string(first, last).c_str(), nullptr); + double num = 0; + [[maybe_unused]] const std::from_chars_result rv = std::from_chars(first, last, num); + return num; } const char* zen::toChars(char* first, char* last, double num) { - const size_t bufSize = last - first; - const int charsWritten = std::snprintf(first, bufSize, "%g", num); - //C99: returns number of chars written if successful, < 0 or >= bufferSize on failure - - return 0 <= charsWritten && charsWritten < static_cast<int>(bufSize) ? - first + charsWritten : first; + const std::to_chars_result rv = std::to_chars(first, last, num); + return rv.ec == std::errc{} ? rv.ptr : first; } + |