https://gcc.gnu.org/g:d5a80f8893475059122ba8331cc9375caf34fc12

commit r17-6116-gd5a80f8893475059122ba8331cc9375caf34fc12
Author: Jonathan Wakely <[email protected]>
Date:   Mon Nov 9 10:47:01 2026 +0000

    libstdc++: Simplify selection of narrowest integer type in <charconv>
    
    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.
    
    Reviewed-by: Tomasz KamiƄski <[email protected]>

Diff:
---
 libstdc++-v3/include/std/charconv | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/std/charconv 
b/libstdc++-v3/include/std/charconv
index 993ceb3f7443..c2767a8671cc 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -97,18 +97,24 @@ namespace __detail
   // and to_chars<unsigned> will all use the same code, and so will
   // to_chars<long> when sizeof(int) == sizeof(long).
   template<typename _Tp>
-    struct __to_chars_unsigned_type : __make_unsigned_selector_base
+    constexpr auto
+    __to_chars_unsigned_type()
     {
-      using _UInts = _List<unsigned int, unsigned long, unsigned long long
+      if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
+       return __type_identity<unsigned int>{};
+      else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
+       return __type_identity<unsigned long>{};
+      else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long))
+       return __type_identity<unsigned long long>{};
 #if __SIZEOF_INT128__ > __SIZEOF_LONG_LONG__
-       , unsigned __int128
+      else if constexpr (sizeof(_Tp) <= sizeof(unsigned __int128))
+       return __type_identity<unsigned __int128>{};
 #endif
-       >;
-      using type = typename __select<sizeof(_Tp), _UInts>::__type;
-    };
+    }
 
   template<typename _Tp>
-    using __unsigned_least_t = typename __to_chars_unsigned_type<_Tp>::type;
+    using __unsigned_least_t
+      = typename decltype(__to_chars_unsigned_type<_Tp>())::type;
 
   // Generic implementation for arbitrary bases.
   // Defined in <bits/charconv.h>.

Reply via email to