-
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
Add synchronous generator support for IIterable<T> #1323
Add synchronous generator support for IIterable<T> #1323
Conversation
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, you got around to it before me lol
{ | ||
suspend_always yield_value(T&& value) noexcept | ||
{ | ||
m_result = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::move(value)
?
@@ -0,0 +1,38 @@ | |||
// Intentionally not using pch... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend adding a test for GetMany(), as well as normally iterating e.g. for (hstring h : Generator())
).
What about value types and reference types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what's the behavior regarding AddRef/Release counts. Also, it might be a good idea to add a test checking that not completing the iteration but dropping the IIterable & IIterator will free the coroutine frame (how? throwing an exception in the coroutine? just silently making the coroutine never complete and call destructors? The latter is what happens when you destroy the coroutine frame)
}; | ||
} | ||
|
||
namespace std |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace std | |
#ifdef __cpp_lib_coroutine | |
namespace std | |
#else | |
namespace std::experimental | |
#endif |
Unfortunately, a project maintainer is not currently available to review this pull request. Please see the contributing guide for more information. Feel free to keep the conversation going on the related issue. |
struct iterable_promise_base : implements<Derived, winrt::Windows::Foundation::Collections::IIterable<TResult>> | ||
{ | ||
private: | ||
struct iterator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation looks wrong here. make sure to use 4 spaces to indent
The https://github.com/microsoft/wil library is where we've been collecting implementation helpers such as this. You might want to open an issue on that repo for consideration. |
Yes - this looks much more appropriate for wil or https://github.com/microsoft/cpp-async as it doesn't really require cppwinrt on its own. Looking forward to the PR on either of those places! |
Feels weird to have to IAsyncOperation support be built-in but not IIterable. Perhaps both should be moved to wil? |
Async coroutine support is fundamental to C++/WinRT for both consumption and production. Generator support for iteration, while cool, has very narrowly defined application. |
This implements #1278.
IIterable::First()
throwsE_CHANGED_STATE
if it is called more than one time since the coroutine has already been resumed at that point; however, I am unsure whether this violates the API contract: