[libc-commits] [libc] f1d274b - [libc][NFC] Make the buffer size of the integer to string converter public.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Sun Jul 31 23:55:06 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-08-01T06:54:17Z
New Revision: f1d274b5c6811f3855cee4b44ba18de8818774cf

URL: https://github.com/llvm/llvm-project/commit/f1d274b5c6811f3855cee4b44ba18de8818774cf
DIFF: https://github.com/llvm/llvm-project/commit/f1d274b5c6811f3855cee4b44ba18de8818774cf.diff

LOG: [libc][NFC] Make the buffer size of the integer to string converter public.

This allows users of the IntegerToString class to size their buffers
appropriately at compile time.

Added: 
    

Modified: 
    libc/src/__support/integer_to_string.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h
index b90e36b1c44b..bd50c5830ad8 100644
--- a/libc/src/__support/integer_to_string.h
+++ b/libc/src/__support/integer_to_string.h
@@ -15,11 +15,7 @@
 namespace __llvm_libc {
 
 template <typename T> class IntegerToString {
-  static_assert(cpp::is_integral_v<T>,
-                "IntegerToString can only be used with integral types.");
-
-  using UnsignedType = cpp::make_unsigned_t<T>;
-
+public:
   // We size the string buffer using an approximation algorithm:
   //
   //   size = ceil(sizeof(T) * 5 / 2)
@@ -40,6 +36,13 @@ template <typename T> class IntegerToString {
   // integers.
   static constexpr size_t BUFSIZE =
       (sizeof(T) * 5 + 1) / 2 + (cpp::is_signed<T>() ? 1 : 0);
+
+private:
+  static_assert(cpp::is_integral_v<T>,
+                "IntegerToString can only be used with integral types.");
+
+  using UnsignedType = cpp::make_unsigned_t<T>;
+
   char strbuf[BUFSIZE] = {'\0'};
   size_t len = 0;
 


        


More information about the libc-commits mailing list