-
Notifications
You must be signed in to change notification settings - Fork 247
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
Allow passing array_view as span #1289
Comments
@kennykerr Sorry for leaving the issue blank before, please reopen the issue now. |
The reason the issues page only lets you create a bug report is because cppwinrt is in maintenance mode and no longer receiving new feature work. cppwinrt serves an important and specific role, but further feature development risks destabilizing the project. Additional helpers are regularly contributed to complimentary projects such as https://github.com/microsoft/wil/. |
This is not an external helper, it must be added to the array_view type itself. |
How |
You can provide conversion operators although std::span using size_t for size could be an issue as array_view uses uin32_t. |
This is a sad state of affairs considering WinRT is supposed to be the future of Windows development (WASDK & WinUI) |
This isn't meant as a negative statement. cppwinrt has reached all of its goals and is generally considered complete and largely bug-free (1). Whether WinRT/WinUI/WinAppSDK is the future is debatable. My experience has shown me that the Windows operating system is at its best when you embrace the Windows API as a whole, including Win32/COM/WinRT, and not just the latest shiny wave. You can see this in action with the popularity of projects like win32metadata and windows-rs that support both WinRT and non-WinRT APIs seamlessly. |
We need C++/WinRT to be updated for the win32metadata project to shine for C++, now that C++/Win32 is archived. We need a cleaner way of consuming COM and Win32 APIs without much of the manual HResult handling, and smart pointer noise. |
I don't think that #1331 is the best approach, as I indicated in #1289 (comment) - I've tagged a few project maintainers. If one of them is available to offer guidance and mentorship for this issue, they will reach out according to the contributing guide to discuss and agree on an approach. https://github.com/orgs/microsoft/teams/cppwinrt-maintainers |
I'm on the side of just removing array_view, and using std::span - but that would mean bumping the minimum to C++20. |
I'd be in favor of that. |
Why not simply alias std::span as array_view on C++20, but keep it for C++17? One thing though is winrt::array_view represents size with an uint32_t and I have some code in C++20 that uses winrt::array_view just because of that, instead of span. I don't see any problem with having implicit conversions, except maybe some template code that requires the type to be identified as a WinRT type and obviously std::span won't in the current arrangement. |
It is needlessly complicated having types in C++/WinRT that can just as well be served by standard library types. One of the great challenges with the continued maintenance and modernization of C++/WinRT is the growing complexity caused by new features and the baggage of legacy language and library support. Any opportunity for paying back debt is goodness. |
There are enough differences between array_view and span to make this non trivial |
While I'm all for moving people forward to modern language standards, even parts of the OS and associated codebases are still on C++17. Conversions into and out of array_view for std::span when available seems reasonable. |
Last I heard the OS supported |
This issue 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. |
@jonwis is it true that the OS repo supports std::span? Maybe this would allow us to move forward with replacing array_view |
This issue 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. |
I wonder how possible it'd be to at least keep source compatibility by typedefing array_view to std::span. The C++ STL doesn't support std::span in C++17, so at least externally this would represent a C++ version bump (unless we keep the old array_view when span isn't available, but this would increase tech debt, not pay it off) |
This comment was marked as off-topic.
This comment was marked as off-topic.
I believe @kennykerr summarized it well with the following:
Basically, take anything being "deprecated" with a pinch of salt and don't be too quick to jump onto the latest technique. In other words, Win32 API is still king ;) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Option A - stymied by ephemeralityThis is a semi-common use case of array-passing: void IFoo::Bar(std::span<uint32_t> arg);
void x(IFoo const& p) {
p.Bar({1, 2, 3});
} ... which does not work because See https://gist.github.com/jonwis/2fb5449307399476dabd65f4a95373cc for the example "bad span" and the code showing the hazard. But, I got pretty far along in the conversion before hitting this. See https://github.com/microsoft/cppwinrt/compare/master...jonwis:cppwinrt:user/jonwis/span-for-arrays?expand=1 as my attempt. It also required updating the baseline to C++20 for span. Option B - winrt::param::array plus spanInstead, we could consider an For harness methods that invoke implementations, we could use Similarly, Option C - retain array-view, add the conversions/constructorsJust merge #1331 so that someone who thinks in OpinionI think the value-prop of using a specific "this is a winrt array that has certain behaviors and a 32-bit size, but is convertable from a std::span" is the right combination, so my preference is on option C. |
I like the option A as it reduces tech debt (no need to maintain what's pretty much a whole copy of std::span). It is definitely the most breaking of changes, and silently truncating 32 bits sizes isn't ideal either, however. |
I'm all for reducing technical debt, but option C sounds like the most realistic approach. |
Sadly "option A" means more words: p.SetNames(std::array{L"kittens", L"puppies"}); I kind of like "option b" as it makes it super clear that array_view<> is a currency, not a thing you should be using on your own. Nobody (should be) using
Agree. It's kind of a random thread to drop this on, but maybe the answer is to start a wish-list for "C++/WinRT 3.0" ... on my wish list in no particular order:
Outside of "C++20 only and auto-fast-abi" it's not clear that this is truly a 3.0; most can be done on 2.0 in an additive or nondisruptive way. |
That was discussed in #1123. Perhaps reopen that issue to avoid your comments being lost when this issue is closed. |
This issue 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. |
Holy cow this bot is obnoxious. |
I've never liked stale bots. |
It may be a little annoying, but it gives everyone a reminder not to let the issue go unnoticed. By contrast, Xaml has this set to 180 days... microsoft/microsoft-ui-xaml#8072 ...and from experience this just means that 180 days later the customer has given up on the product and the issue is never resolved one way or another. cppwinrt/.github/workflows/stale.yml Lines 19 to 20 in 9b453cf
Feel free to tweak these numbers, but I wouldn't recommend bumping them up too high for the reason above. |
I want to be able to use std::span for portablity and implicitly pass an array_view from WinRT to it.
The text was updated successfully, but these errors were encountered: