Closed dmachaj closed 4 months ago
There is a formatter for winrt::hstring
already - however since hstrings are wide, you need a corresponding wide format string. This should work: std::format(L"My string is {0}", myString);
You're right. Not sure how I missed that 🤦.
I see this in <winrt/base.h>
#ifdef __cpp_lib_format
template<>
struct std::formatter<winrt::hstring, wchar_t> : std::formatter<std::wstring_view, wchar_t> {};
#endif
Version
No response
Summary
std::format
is a new C++ language feature that has some nice features for producing strings with data bound to them. It is possible to writestd::formatter
implementations that support additional types so that they can be natively used with std::format without requiring manual adaptation such as calling.c_str()
.It would be nice if the various cppwinrt types, especially
winrt::hstring
had a formatter implementation so they work natively. Bonus points if things like winrt::hresult or winrt::hresult_error also could be printed easily.Reproducible example
Expected behavior
Compiles and prints "My string is MyString"
Actual behavior
Build break
Additional comments
No response