This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)
- From: Daniel Krügler <daniel dot kruegler at gmail dot com>
- To: Adrian Wielgosik <adrian dot wielgosik at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 28 May 2017 15:37:33 +0200
- Subject: Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)
- Authentication-results: sourceware.org; auth=none
- References: <CAPoJ1RH7BDKNCF9yo8XEXx_mSZ4=G2LWPxxG0rfL9oSyrQSUWQ@mail.gmail.com>
2017-05-27 23:46 GMT+02:00 Adrian Wielgosik <adrian.wielgosik@gmail.com>:
> Currently std::to_string takes a fairly long trip to vs(n/w)printf. The patch
> implements int-to-string formatting in header, to improve function performance.
The existing specification of std::to_string is specified in a way
that would make this replacement implementation non-conforming, IMO.
Reason for this is, that the C++ specification says:
"Each function returns a string object holding the character
representation of the value of
its argument that would be generated by calling sprintf(buf, fmt, val)
with a format specifier of
"%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf",
respectively, where buf designates
an internal character buffer of sufficient size."
The explicit reference to sprintf without specification of any locale
means that the outcome should depend on the currently set locale, so a
conforming program could notice the difference by either calling
std::setlocale.
This is different for the new "primitive numeric output" functions
(std::to_chars, std::from_chars), which explicitly require a
conversion as if the "C" locale would be active.
- Daniel