From b41581ed656dde74b7a7b961b8a5c08bc61fb7d4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 24 Jun 2026 13:10:40 +0200 Subject: kstd: simplify kstd::to_string --- libs/kstd/kstd/string | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/string b/libs/kstd/kstd/string index de254a1d..682b8404 100644 --- a/libs/kstd/kstd/string +++ b/libs/kstd/kstd/string @@ -5,11 +5,12 @@ #include #include #include +#include +#include #include #include #include -#include #include namespace kstd @@ -17,32 +18,15 @@ namespace kstd using string = basic_string; /** - * @brief Converts an unsigned integer to a string by converting each digit to the corresponding character and - * concatenating them. - * @tparam N The type of the unsigned integer to convert. + * @brief Converts an integer to a string as if by kstd::format("{}", value). + * @tparam IntegralType The type of the unsigned integer to convert. * @param value The unsigned integer to convert. * @return A string representation of the given unsigned integer. */ - template - requires std::unsigned_integral - [[nodiscard]] constexpr auto inline to_string(N value) -> string + template + [[nodiscard]] constexpr auto inline to_string(IntegralType value) -> string { - if (value == 0) - { - return "0"; - } - - string result; - - while (value > 0) - { - char const digit = '0' + (value % 10); - result.push_back(digit); - value /= 10; - } - - std::reverse(result.begin(), result.end()); - return result; + return kstd::format("{}", value); } template<> -- cgit v1.2.3