Use std::to_chars
instead of std::snprintf
for converting numbers to string
#18
Labels
enhancement
New feature or request
Milestone
std::snprintf
insists on adding a null-terminating character all the time, which forces us to loose one character when running out of space. This is normally not a problem, because we will usually truncate with...
anyway (hence overwriting the last three characters), but just out of principle.std::to_chars
is the modern alternative. I haven't seen benchmarks to compare the performance, but I would expect it to be faster (edit: it is massively faster). The downside ofstd::to_chars
is that it won't write anything if there's not enough space, so we need to handle that logic ourselves. The other big downside is thatstd::to_chars
for floating point numbers has poor vendor support, and was added only in libstdc++ 11, libc++ 14 despite being a C++17 feature (MSVC did better there).Work in progress on this is started in https://github.com/cschreib/snatch/tree/to_chars.
The text was updated successfully, but these errors were encountered: