diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 31706f96eaf6..6d95a7377972 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -279,10 +279,18 @@ inline auto vformat_to_n(OutputIt out, size_t n, basic_string_view fmt, return {buf.out(), buf.count()}; } +template ::value)> +FMT_INLINE auto format_to_n(OutputIt out, size_t n, wformat_string fmt, + T&&... args) -> format_to_n_result { + return vformat_to_n(out, n, fmt.get(), fmt::make_wformat_args(args...)); +} + template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> + FMT_ENABLE_IF(detail::is_output_iterator::value && + !std::is_same::value && + !std::is_same::value)> inline auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) -> format_to_n_result { return vformat_to_n(out, n, fmt::basic_string_view(fmt), diff --git a/test/xchar-test.cc b/test/xchar-test.cc index cfe8389da625..f6620ddf44be 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -146,6 +146,26 @@ TEST(format_test, wide_format_to_n) { EXPECT_EQ(L"BC x", fmt::wstring_view(buffer, 4)); } +TEST(format_test, wide_format_to_n_runtime) { + wchar_t buffer[4]; + buffer[3] = L'x'; + auto result = fmt::format_to_n(buffer, 3, fmt::runtime(L"{}"), 12345); + EXPECT_EQ(5u, result.size); + EXPECT_EQ(buffer + 3, result.out); + EXPECT_EQ(L"123x", fmt::wstring_view(buffer, 4)); + buffer[0] = L'x'; + buffer[1] = L'x'; + buffer[2] = L'x'; + result = fmt::format_to_n(buffer, 3, fmt::runtime(L"{}"), L'A'); + EXPECT_EQ(1u, result.size); + EXPECT_EQ(buffer + 1, result.out); + EXPECT_EQ(L"Axxx", fmt::wstring_view(buffer, 4)); + result = fmt::format_to_n(buffer, 3, fmt::runtime(L"{}{} "), L'B', L'C'); + EXPECT_EQ(3u, result.size); + EXPECT_EQ(buffer + 3, result.out); + EXPECT_EQ(L"BC x", fmt::wstring_view(buffer, 4)); +} + TEST(xchar_test, named_arg_udl) { using namespace fmt::literals; auto udl_a =