Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions strings/base_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ namespace winrt::impl
template <typename... Args>
inline hstring base_format(Args&&... args)
{
auto const size = std::formatted_size(args...);
auto const size = std::formatted_size(std::forward<Args>(args)...);
WINRT_ASSERT(size < UINT_MAX);
auto const size32 = static_cast<uint32_t>(size);

hstring_builder builder(size32);
WINRT_VERIFY_(size32, std::format_to_n(builder.data(), size32, args...).size);
WINRT_VERIFY_(size32, std::format_to_n(builder.data(), size32, std::forward<Args>(args)...).size);
return builder.to_hstring();
}
#endif
Expand All @@ -572,13 +572,13 @@ WINRT_EXPORT namespace winrt
template <typename... Args>
inline hstring format(std::wformat_string<Args...> const fmt, Args&&... args)
{
return impl::base_format(fmt, args...);
return impl::base_format(fmt, std::forward<Args>(args)...);
}

template <typename... Args>
inline hstring format(std::locale const& loc, std::wformat_string<Args...> const fmt, Args&&... args)
{
return impl::base_format(loc, fmt, args...);
return impl::base_format(loc, fmt, std::forward<Args>(args)...);
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions test/test_cpp20/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ TEST_CASE("format")
std::wstring str = L"World";
REQUIRE(winrt::format(L"Hello {}", str) == L"Hello World");
}

{
REQUIRE(winrt::format(L"C++/WinRT #{:d}", 1) == L"C++/WinRT #1");
}
#endif
}