From 23a9a647c7094b6a37a02ddcea7e52ccbd6aa0c6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 28 Apr 2024 14:44:08 -0400 Subject: [PATCH] xo-flatstring: replace from_int() with template on int repr --- include/xo/flatstring/flatstring.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/xo/flatstring/flatstring.hpp b/include/xo/flatstring/flatstring.hpp index 9057f51c..60828f7e 100644 --- a/include/xo/flatstring/flatstring.hpp +++ b/include/xo/flatstring/flatstring.hpp @@ -189,8 +189,14 @@ namespace xo { } /** @brief construct from integer **/ - static constexpr flatstring from_int(int x) { - constexpr size_t buf_z = 20; + template + requires std::is_integral_v + static constexpr flatstring from_int(Int x) { + /* 32-bit int ~ 4e9 + * 64-bit int ~ 16e18 + * 128-bit int - 256e36 ~ 2.6e38 + */ + constexpr size_t buf_z = 64; bool negative_flag = (x < 0); std::size_t i = buf_z;