-
Notifications
You must be signed in to change notification settings - Fork 244
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
Expose winrt::impl::hstring_builder as winrt::hstring_builder #1035
Comments
I ended up not making it public in my std::format support PR, because it requires some work to make safe for use with std::format. Would rather see that work happen before moving it out of the impl namespace to avoid locking the builder into unsafe by default. |
Ah sorry. I didn't know it was unsafe... Can you explain what makes |
There's no bounds checking, so something like format_to(back_inserter(builder)) will eventually buffer overflow. |
Ah okay... yeah but that's fine in this case, isn't it? Member functions called |
Can you give an example? HSTRING is not generally used with Win32 APIs. You're likely better off with something from the standard library. |
@kennykerr There are a number of Win32 APIs which offer an alternative mode returning the required number of output bytes. For instance |
Yeah the get size then fill pattern is pretty common in C APIs. std::string is even getting support for it soon (resize_and_overwrite) |
Thanks for the example. I typically use |
Is there a version of those things that automatically manages an |
@DHowett that's implemented by C++/WinRT automatically. |
hstring_builder seemingly taps into implementation details of hstring, so my hope by making that public is that we'd have a guarantee that it will work in the future or be updated to follow the implementation, unlike if we where to just copy it within our own project. |
There is a public API for this. You can simply call |
Are you aware of an alternative API that works on Win7? |
No, that's why C++/WinRT inlines all |
The reason it's an hstring is because it ends up exposed as a public property: But then this isn't really a hotpath (it gets called upon construction). Converting to hstring later sounds fine. And if they really want the best possible performance, then it's possible to wrap around |
winrt::impl::hstring_builder
is a rather useful class. It can be used as the out parameter for various Win32 methods, avoiding the need for extra intermediate copies. The idea of making it public was also suggested in #1018.Would it be feasible to create a public alias of
hstring_builder
?The text was updated successfully, but these errors were encountered: