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: Adrian Wielgosik <adrian dot wielgosik at gmail dot com>
- To: Tim Song <t dot canens dot cpp at gmail dot com>
- Cc: Daniel Krügler <daniel dot kruegler at gmail dot com>, Ville Voutilainen <ville dot voutilainen at gmail dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 29 May 2017 10:46:04 +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> <CAGNvRgB6HeX2kT+PZM1stppJMZ_y-=nkGt9BjKgUm0gruTF92g@mail.gmail.com> <CAPoJ1RHDP41LqWvyUB1Sko=-sM5=tw2Hc-Cyh_HoJ90Ee3fOeA@mail.gmail.com> <CAGNvRgB2Nv7WEkmxDQ0s_n=P=ywGquYTF8tmhbyxeFQFsT2nyw@mail.gmail.com> <CAPQZVxugLY0uLdHCnzvrU3MYOeEvrzncvP6Nfkfed-Ky+CyZkQ@mail.gmail.com> <CAFk2RUaxjU-Ox+NnHWCmmYHz7EGiOA-YbA=poGDhhtZTjgD7DA@mail.gmail.com>
> Assuming that the locale issue isn't a problem, can that be reused?
The to_chars patch uses C++14 features, while to_string is C++11. If
that was solved, it probably could be used.
However, as far as I know, simply using to_chars in to_string would
technically be suboptimal, because it needs three loops:
- in to_chars, to determine length of the string
- in to_chars, to format the number
- in to_string, to copy the formatted string to std::string
Meanwhile, ideally to_string can use only two loops:
- to determine length of the std::string
- to format the number in constructed std::string
OR (this is what I am doing)
- to format the number in temporary buffer
- to copy the formatted string to std::string
That said, the proposed not-yet-committed to_chars implementation is
more optimized than my code (by doing less integer divisions), so it
may perform just as good as mine or better.