-
Notifications
You must be signed in to change notification settings - Fork 30
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
implement filter_map #192
implement filter_map #192
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
=======================================
Coverage 98.22% 98.22%
=======================================
Files 69 69
Lines 2360 2360
=======================================
Hits 2318 2318
Misses 42 42 ☔ View full report in Codecov by Sentry. |
Thanks for working on this @Guekka.
The function When reading from the pipeline, the temporary optional gets dereferenced in this lambda: This returns a reference to the temporary optional's internal One solution is to try to detect the problem, by noticing when dereffing the optional-like would return an rvalue reference, and returning by value instead. Like so: struct filter_map_fn {
// If dereffing the optional would give us an rvalue reference,
// prevent a probable dangling reference by returning by value instead
template <typename T>
using strip_rvalue_ref_t = std::conditional_t<
std::is_rvalue_reference_v<T>, std::remove_reference_t<T>, T>;
template <adaptable_sequence Seq, typename Func>
requires (std::invocable<Func&, element_t<Seq>> &&
optional_like<std::remove_cvref_t<std::invoke_result_t<Func&, element_t<Seq>>>>)
constexpr auto operator()(Seq&& seq, Func func) const
{
return flux::map(FLUX_FWD(seq), std::move(func))
.filter([](auto&& opt) { return static_cast<bool>(opt); })
.map([](auto&& opt) -> strip_rvalue_ref_t<decltype(*FLUX_FWD(opt))> {
return *FLUX_FWD(opt);
});
}
}; Making this change fixes the original lifetime problem. Unfortunately this Hope this helps! |
Thank you @tcbrindle. Debugging why something is not constexpr is complex |
512a731
to
9a1f911
Compare
Cannot reproduce the CI failure locally on Windows. Will try later on Linux |
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.
This is looking good. I've suggested a few changes but they're pretty minor.
I the long term, I'd prefer filter_map
to have its own dedicated adaptor class rather than using a chain of three existing adaptors, but doing it this way is fine for now.
We also need some documentation (or at least placeholders) for filter_map
and filter_deref
in docs/reference/adaptors.rst
to let people know that they exist. If this is tricky then let me know and I can add it to the PR before merging.
Yeah, it seems like it only happens with libstdc++ -- both MSVC and libc++ pull in |
Resolved reviews. Still have to write doc |
Please review thoroughly the docs @tcbrindle, I'm not entirely sure of what I wrote I will rebase the PR once you approve it |
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.
Good job on the documentation, I've made some suggestions to add a bit more description but otherwise it's good. I like making the doc target watch all the .rst files 👍
There's one change I don't understand with FLUX_NO_UNIQUE_ADDRESS
, if this wasn't intentional then please revert it (or else let me know why it's needed)
Other than that it's just some minor formatting things
Fixed. A clang format file would really be helpful, even if it means losing some custom formatting, I think it would be worth it for contributors |
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.
Just one tiny change to silence a Sphinx warning and then we're good to go 👍
Co-authored-by: Tristan Brindle <[email protected]>
Thanks for your work on this @Guekka! |
Adresses #191
The functionality is there, but I am still trying to understand why the
static_assert
fail