diff --git a/include/fmt/format.h b/include/fmt/format.h index 0da9fd09..d2a90b45 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2816,26 +2816,6 @@ inline auto format_to(basic_memory_buffer& buf, return detail::buffer_appender(buf); } -template , - FMT_ENABLE_IF(detail::is_output_iterator::value && - !std::is_same::value)> -auto vformat_to(OutputIt out, const S& format_str, - basic_format_args>> args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, to_string_view(format_str), args); - return detail::get_iterator(buf); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value && - !std::is_same::value)> -inline auto format_to(OutputIt out, const S& fmt, Args&&... args) -> OutputIt { - const auto& vargs = fmt::make_args_checked(fmt, args...); - return vformat_to(out, to_string_view(fmt), vargs); -} - template ::value&& detail::is_locale::value)> @@ -2854,38 +2834,6 @@ FMT_INLINE auto format_to(OutputIt out, const Locale& loc, format_string fmt, T&&... args) -> OutputIt { return vformat_to(loc, out, fmt, fmt::make_format_args(args...)); } - -template ::value && - !std::is_same::value)> -inline auto vformat_to_n( - OutputIt out, size_t n, basic_string_view format_str, - basic_format_args>> args) - -> format_to_n_result { - detail::iterator_buffer buf(out, - n); - detail::vformat_to(buf, format_str, args); - return {buf.out(), buf.count()}; -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value && - !std::is_same::value)> -inline auto format_to_n(OutputIt out, size_t n, const S& fmt, - const Args&... args) -> format_to_n_result { - const auto& vargs = fmt::make_args_checked(fmt, args...); - return vformat_to_n(out, n, to_string_view(fmt), vargs); -} - -template , - FMT_ENABLE_IF(!std::is_same::value)> -inline auto formatted_size(const S& fmt, Args&&... args) -> size_t { - detail::counting_buffer buf; - const auto& vargs = fmt::make_args_checked(fmt, args...); - detail::vformat_to(buf, to_string_view(fmt), vargs); - return buf.count(); -} FMT_MODULE_EXPORT_END FMT_END_NAMESPACE diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index d4b0a1cc..835b87eb 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -91,6 +91,26 @@ inline std::basic_string format(const Locale& loc, const S& format_str, fmt::make_args_checked(format_str, args...)); } +template , + FMT_ENABLE_IF(detail::is_output_iterator::value&& + detail::is_exotic_char::value)> +auto vformat_to(OutputIt out, const S& format_str, + basic_format_args>> args) + -> OutputIt { + auto&& buf = detail::get_buffer(out); + detail::vformat_to(buf, to_string_view(format_str), args); + return detail::get_iterator(buf); +} + +template , + FMT_ENABLE_IF(detail::is_output_iterator::value&& + detail::is_exotic_char::value)> +inline auto format_to(OutputIt out, const S& fmt, Args&&... args) -> OutputIt { + const auto& vargs = fmt::make_args_checked(fmt, args...); + return vformat_to(out, to_string_view(fmt), vargs); +} + template , FMT_ENABLE_IF(detail::is_output_iterator::value&& @@ -116,6 +136,38 @@ inline auto format_to(OutputIt out, const Locale& loc, const S& format_str, return vformat_to(out, loc, to_string_view(format_str), vargs); } +template ::value&& + detail::is_exotic_char::value)> +inline auto vformat_to_n( + OutputIt out, size_t n, basic_string_view format_str, + basic_format_args>> args) + -> format_to_n_result { + detail::iterator_buffer buf(out, + n); + detail::vformat_to(buf, format_str, args); + return {buf.out(), buf.count()}; +} + +template , + FMT_ENABLE_IF(detail::is_output_iterator::value&& + detail::is_exotic_char::value)> +inline auto format_to_n(OutputIt out, size_t n, const S& fmt, + const Args&... args) -> format_to_n_result { + const auto& vargs = fmt::make_args_checked(fmt, args...); + return vformat_to_n(out, n, to_string_view(fmt), vargs); +} + +template , + FMT_ENABLE_IF(detail::is_exotic_char::value)> +inline auto formatted_size(const S& fmt, Args&&... args) -> size_t { + detail::counting_buffer buf; + const auto& vargs = fmt::make_args_checked(fmt, args...); + detail::vformat_to(buf, to_string_view(fmt), vargs); + return buf.count(); +} + inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) { wmemory_buffer buffer; detail::vformat_to(buffer, fmt, args); diff --git a/test/format-test.cc b/test/format-test.cc index d1b01043..e271227e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1890,12 +1890,6 @@ TEST(format_test, format_to) { EXPECT_EQ("part1part2", s); } -TEST(format_test, format_to_wide) { - std::vector buf; - fmt::format_to(std::back_inserter(buf), L"{}{}", 42, L'\0'); - EXPECT_STREQ(buf.data(), L"42"); -} - TEST(format_test, format_to_memory_buffer) { auto buf = fmt::basic_memory_buffer(); fmt::format_to(buf, "{}", "foo"); diff --git a/test/wchar-test.cc b/test/wchar-test.cc index 8c834c48..89556f18 100644 --- a/test/wchar-test.cc +++ b/test/wchar-test.cc @@ -24,6 +24,12 @@ TEST(wchar_test, format_explicitly_convertible_to_wstring_view) { } #endif +TEST(wchar_test, format_to) { + auto buf = std::vector(); + fmt::format_to(std::back_inserter(buf), L"{}{}", 42, L'\0'); + EXPECT_STREQ(buf.data(), L"42"); +} + TEST(wchar_test, vformat_to) { using wcontext = fmt::wformat_context; fmt::basic_format_arg warg = fmt::detail::make_arg(42);