numeric/str: Add type to IntToStr
Otherwise, we can't use it in a ToStrHandle.
Change-Id: I6127813300b25e4c13accd5b4de07f1aa7ca718d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/numeric/str.hpp b/include/stdplus/numeric/str.hpp
index 680ceb7..a9c2281 100644
--- a/include/stdplus/numeric/str.hpp
+++ b/include/stdplus/numeric/str.hpp
@@ -234,6 +234,7 @@
template <uint8_t base, std::integral T>
struct IntToStr
{
+ using type = T;
static_assert(base > 1 && base <= detail::maxBase);
static inline constexpr size_t buf_size = []() {
@@ -262,9 +263,7 @@
template <std::integral T>
struct ToStr<T> : IntToStr<10, T>
-{
- using type = T;
-};
+{};
template <uint8_t base, std::integral T>
struct StrToInt
diff --git a/test/numeric/str.cpp b/test/numeric/str.cpp
index cedc87c..94ccde9 100644
--- a/test/numeric/str.cpp
+++ b/test/numeric/str.cpp
@@ -36,6 +36,8 @@
static_assert(enc.buf_size == 6);
char buf[enc.buf_size];
EXPECT_EQ("55255", std::string_view(buf, enc(buf, 55255, 3)));
+ ToStrHandle<IntToStr<10, uint16_t>> tsh;
+ EXPECT_EQ("55255", tsh(55255));
}
TEST(IntToStr, Uint32_10)
@@ -59,6 +61,8 @@
EXPECT_EQ("00", std::string_view(buf, enc(buf, 0, 2)));
EXPECT_EQ("02", std::string_view(buf, enc(buf, 2, 2)));
EXPECT_EQ("ff", std::string_view(buf, enc(buf, 255, 2)));
+ ToStrHandle<IntToStr<16, uint8_t>> tsh;
+ EXPECT_EQ("2a", tsh(0x2a));
}
TEST(IntToStr, Uint8_8)