public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4254] libstdc++: Shorten integer std::to/from_chars symbol names
@ 2023-09-25 18:50 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-09-25 18:50 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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

commit r14-4254-gbf3c19903a801063551e43bdc2b8b7ea2f69b781
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Sep 25 14:48:26 2023 -0400

    libstdc++: Shorten integer std::to/from_chars symbol names
    
    For std::to_chars:
    
    The constrained alias __integer_to_chars_result_type seems unnecessary
    ever since r10-3080-g28f0075742ed58 got rid of the only public overload
    which used it.  Now only non-public overloads are constrained by it
    (through their return type) and these non-public overloads aren't used
    in a SFINAE context, so the constraints have no observable effect.  So
    this patch gets rid of this alias, which greatly shortens the symbol names
    of the affected functions (since the expanded alias is quite large).
    
    For std::from_chars:
    
    We can't get rid of the corresponding alias because its constrains the
    public integer std::from_chars overload.  But we can avoid having the
    constraint bloat the mangled name by instead encoding it as a defaulted
    template parameter.  We use the non-type parameter form
    
      enable_if_t<..., int> = 0
    
    instead of the type parameter form
    
      typename = enable_if_t<...>
    
    because the type form can be bypassed by giving an explicit template
    argument for the type parameter, e.g. 'std::from_chars<int, void>(...)',
    so the non-type form seems like the more robust choice.
    
    In passing, use __is_standard_integer in the constraint.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/charconv (__detail::__integer_to_chars_result_type):
            Remove.
            (__detail::__to_chars_16): Use to_chars_result as return type.
            (__detail::__to_chars_10): Likewise.
            (__detail::__to_chars_8): Likewise.
            (__detail::__to_chars_2): Likewise.
            (__detail::__to_chars_i): Likewise.
            (__detail::__integer_from_chars_result_type): Inline the
            constraint into ...
            (from_chars): ... here.  Use __is_standard_integer in the
            constraint.  Encode constraint as a defaulted non-type template
            parameter instead of within the return type.

Diff:
---
 libstdc++-v3/include/std/charconv | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
index 7edb6ade3d4..cb428fe6d3b 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -85,17 +85,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 namespace __detail
 {
-  template<typename _Tp>
-    using __integer_to_chars_result_type
-      = enable_if_t<__or_<__is_signed_integer<_Tp>,
-			  __is_unsigned_integer<_Tp>,
-#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
-			  is_same<_Tp, signed __int128>,
-			  is_same<_Tp, unsigned __int128>,
-#endif
-			  is_same<char, remove_cv_t<_Tp>>>::value,
-		    to_chars_result>;
-
   // Pick an unsigned type of suitable size. This is used to reduce the
   // number of specializations of __to_chars_len, __to_chars etc. that
   // get instantiated. For example, to_chars<char> and to_chars<short>
@@ -168,7 +157,7 @@ namespace __detail
     }
 
   template<typename _Tp>
-    constexpr __integer_to_chars_result_type<_Tp>
+    constexpr to_chars_result
     __to_chars_16(char* __first, char* __last, _Tp __val) noexcept
     {
       static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
@@ -214,7 +203,7 @@ namespace __detail
     }
 
   template<typename _Tp>
-    constexpr __integer_to_chars_result_type<_Tp>
+    constexpr to_chars_result
     __to_chars_10(char* __first, char* __last, _Tp __val) noexcept
     {
       static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
@@ -237,7 +226,7 @@ namespace __detail
     }
 
   template<typename _Tp>
-    constexpr __integer_to_chars_result_type<_Tp>
+    constexpr to_chars_result
     __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
     {
       static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
@@ -290,7 +279,7 @@ namespace __detail
     }
 
   template<typename _Tp>
-    constexpr __integer_to_chars_result_type<_Tp>
+    constexpr to_chars_result
     __to_chars_2(char* __first, char* __last, _Tp __val) noexcept
     {
       static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
@@ -326,7 +315,7 @@ namespace __detail
 } // namespace __detail
 
   template<typename _Tp>
-    constexpr __detail::__integer_to_chars_result_type<_Tp>
+    constexpr to_chars_result
     __to_chars_i(char* __first, char* __last, _Tp __value, int __base = 10)
     {
       __glibcxx_assert(2 <= __base && __base <= 36);
@@ -553,18 +542,13 @@ namespace __detail
       return true;
     }
 
-  template<typename _Tp>
-    using __integer_from_chars_result_type
-      = enable_if_t<__or_<__is_signed_integer<_Tp>,
-			  __is_unsigned_integer<_Tp>,
-			  is_same<char, remove_cv_t<_Tp>>>::value,
-		    from_chars_result>;
-
 } // namespace __detail
 
   /// std::from_chars for integral types.
-  template<typename _Tp>
-    _GLIBCXX23_CONSTEXPR __detail::__integer_from_chars_result_type<_Tp>
+  template<typename _Tp,
+	   enable_if_t<__or_<__is_standard_integer<_Tp>,
+			     is_same<char, remove_cv_t<_Tp>>>::value, int> = 0>
+    _GLIBCXX23_CONSTEXPR from_chars_result
     from_chars(const char* __first, const char* __last, _Tp& __value,
 	       int __base = 10)
     {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-25 18:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 18:50 [gcc r14-4254] libstdc++: Shorten integer std::to/from_chars symbol names Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).