-
Notifications
You must be signed in to change notification settings - Fork 263
Efficient way to format directly to hstring #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient way to format directly to hstring #1207
Conversation
Would this work on Clang? I'm reluctant to merge this in until we can test it. |
|
It depends on changes in the STL, but it should work in Clang once VS is updated. |
|
I meant we could use Clang to test it so long, but yes if its STL-dependent then we'd have to wait for MSVC to catch up. |
|
Clang also uses the MSVC STL on Windows, so it's also blocked on 17.5 preview 1. I'm totally okay with waiting for a preview release before merging, I just opened this because it's work I had already done. |
|
It's very cool - similar to Rust's format so this is lovely. ❤️ |
|
This pull request is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
Commenting to avoid closing. This is stale because it's blocked on VS 17.5 |
|
This pull request is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
Going to look at this soon, VS 17.5 preview is out now |
|
Just took a look: this works fine on 17.5 Preview 1 with no changes needed 🎉 |
|
Looks good - I assume the CI build isn't yet validating this as its still using a previous version of the compiler. Is that correct? @DefaultRyan did you want to take a look at this? |
|
I would assume so as well, since 17.5 is preview only at the moment. |
|
@kennykerr any chance of making a new release? I'd like to start using this |
|
Coming up! (2.0.221117.1) |
|
fyi, wil has std::str_printf, but does not support winrt::hstring. |
|
Could you add winrt::format for older versions using the internal API (on MSVC at least) or simply being a wrapper on std::format that copies the result into an hstring? |
|
No, because the STL team strongly recommended against using the internal You need to use VS 17.5 for this. The entire point of |
This introduces a new API,
winrt::format, the exact equivalent ofstd::format(including compile-time format string checking), that efficiently formats to anhstringby usinghstring_builder. It avoids the copies that would be required if usingstd::format.Note that this will only light up on VS 17.5 Preview 1 (which is not available to the public yet), but I've manually tested it on VS 17.4 previews by changing
std::wformat_stringtostd::_Fmt_wstring(the internal name before it became a public API).