From f1d274b5c6811f3855cee4b44ba18de8818774cf Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Mon, 1 Aug 2022 06:43:11 +0000 Subject: [PATCH] [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. --- libc/src/__support/integer_to_string.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h index b90e36b..bd50c58 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 class IntegerToString { - static_assert(cpp::is_integral_v, - "IntegerToString can only be used with integral types."); - - using UnsignedType = cpp::make_unsigned_t; - +public: // We size the string buffer using an approximation algorithm: // // size = ceil(sizeof(T) * 5 / 2) @@ -40,6 +36,13 @@ template class IntegerToString { // integers. static constexpr size_t BUFSIZE = (sizeof(T) * 5 + 1) / 2 + (cpp::is_signed() ? 1 : 0); + +private: + static_assert(cpp::is_integral_v, + "IntegerToString can only be used with integral types."); + + using UnsignedType = cpp::make_unsigned_t; + char strbuf[BUFSIZE] = {'\0'}; size_t len = 0; -- 2.7.4