diff --git a/include/duckhandy/int_conv.hpp b/include/duckhandy/int_conv.hpp index 1067022..c8fa5c2 100644 --- a/include/duckhandy/int_conv.hpp +++ b/include/duckhandy/int_conv.hpp @@ -296,6 +296,12 @@ namespace dhandy { std::string to_string (I num) { return std::string(int_to_ary(num).to_string_view()); } + + template + std::string operator+ (std::string a, const ReversedSizedArray& b) { + a.append(b.data(), b.size() - 1); + return a; + } #endif } //namespace dhandy diff --git a/test/unit/int_conv_test.cpp b/test/unit/int_conv_test.cpp index c911f40..75497eb 100644 --- a/test/unit/int_conv_test.cpp +++ b/test/unit/int_conv_test.cpp @@ -21,6 +21,8 @@ #include "sprout/cstring/strlen.hpp" #include "sprout/preprocessor/comma.hpp" #include +#include +#include template using int_info_10 = dhandy::implem::int_info; template using int_info_16 = dhandy::implem::int_info; @@ -109,6 +111,22 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") { num = 0xFFFFFFFFFFFFFFFF; CHECK(int_to_ary<__int128_t SPROUT_PP_COMMA() 16>(num * 0x10000 + 0xffff) == "ffffffffffffffffffff"); #endif + + { + //Try a random test, which should not compile as constexpr + std::mt19937 gen; + gen.seed(1234); + for (int z = 0; z < 10; ++z) { + const int num = gen(); + CHECK(int_to_ary(num) == std::to_string(num)); + } + + const int num = gen(); + std::string hello = "hello world"; + std::string hello1 = hello + " " + int_to_ary(num); + std::string hello2 = hello + " " + std::to_string(num); + CHECK(hello1 == hello2); + } } TEST_CASE ("Check char array to int conversions", "[i2s][int_conv]") {