diff --git a/include/fmt/format.h b/include/fmt/format.h index c4329ec9..68468dd8 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3741,6 +3741,21 @@ arg_join, detail::sentinel_t, wchar_t> join( return join(std::begin(range), std::end(range), sep); } +FMT_MODULE_EXPORT_END +namespace detail { + +template +inline std::basic_string integral_to_string(T value) { + // The buffer should be large enough to store the number including the sign or + // "false" for bool. + constexpr int max_size = detail::digits10() + 2; + Char buffer[max_size > 5 ? static_cast(max_size) : 5]; + Char* begin = buffer; + return std::basic_string(begin, detail::write(begin, value)); +} + +} +FMT_MODULE_EXPORT_BEGIN /** \rst Converts *value* to ``std::string`` using the default format for type *T*. @@ -3761,19 +3776,22 @@ inline std::string to_string(const T& value) { template ::value)> inline std::string to_string(T value) { - // The buffer should be large enough to store the number including the sign or - // "false" for bool. - constexpr int max_size = detail::digits10() + 2; - char buffer[max_size > 5 ? static_cast(max_size) : 5]; - char* begin = buffer; - return std::string(begin, detail::write(begin, value)); + return detail::integral_to_string(value); } /** Converts *value* to ``std::wstring`` using the default format for type *T*. */ -template inline std::wstring to_wstring(const T& value) { - return format(FMT_STRING(L"{}"), value); +template ::value)> +inline std::wstring to_wstring(const T& value) { + std::wstring result; + detail::write(std::back_inserter(result), value); + return result; +} + +template ::value)> +inline std::wstring to_wstring(T value) { + return detail::integral_to_string(value); } template