[PATCH] libstdc++: Simplify selection of narrowest integer type in <charconv>

Tomasz Kaminski tkaminsk@redhat.com
Tue Nov 10 13:26:20 GMT 2026


On Mon, Nov 9, 2026 at 12:26 PM Jakub Jelinek <jakub@redhat.com> wrote:

> On Mon, Nov 09, 2026 at 10:49:09AM +0000, Jonathan Wakely wrote:
> > We don't need the full genericity of the __make_unsigned_selector_base
> > template from <type_traits> because we have a hardcoded list of three or
> > four integral types. We can just use a constexpr if-else ladder. This
> > avoids recursive class template instantiations and partial
> > specialization matching.
> >
> > libstdc++-v3/ChangeLog:
> >
> >       * include/std/charconv (__to_chars_unsigned_type): Remove.
> >       (__to_chars_unsigned_type): New constexpr function.
> >       (__unsigned_least_t): Use __to_chars_unsigned_type.
> > ---
> >
> > Tested 20_util/to_chars/* and testing the rest now, on x86_64-linux.
>
The changes LGTM.

>
> Thanks, this looks cleaner.  Once you commit it, I can tweak my patch
> not to define __make_unsigned_selector_base when using the trait.
>
> Wonder what to do for _BitInt, if we should instantiate for all possible
> widths used in the code or do something similar, use the unsigned int/long
> long/__int128 if that is wider or same precision and/or say round up
> _BitInt precision to multiples of 128 or something like that.

I think we want to reduce the number of instantiations, so upgrading to
standard
types, and then rounding bits seem like good choice.

>


>         Jakub
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20261110/f4559e33/attachment.htm>


More information about the Libstdc++ mailing list