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.
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>.
--
2.56.0