-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<algorithm> Implement P2302R4 ranges::contains #2911
Conversation
stl/inc/algorithm
Outdated
requires indirect_binary_predicate < ranges::equal_to, projected<_It, _Pj>, | ||
const _Ty* > // | ||
_NODISCARD constexpr bool operator()(_It _First, _Se _Last, const _Ty& _Val, _Pj _Proj = {}) const { | ||
return _RANGES find(_STD move(_First), _Last, _Val, _Pass_fn(_Proj)) != _Last; |
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.
No change requested: there are _Pass_fn
calls at multiple layers here, which we usually avoid, but I checked and _Pass_fn
will not wrap twice, so this seems reasonable for now.
Thanks! I validated and pushed minor fixes/cleanups, the most significant of which was guarding the product code for C++23. |
I'm speculatively mirroring this to the MSVC-internal repo (because I'm a greedy kitty who likes treats) - please notify me if any further changes are pushed. |
@StephanTLavavej pushed a minor change to the |
@SuperWig Updated the mirror, thanks for letting me know! 😻 |
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.
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.
That is a great contribution
@StephanTLavavej I think there are some issues that should be addressed |
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rng>, _Pj>, const _Ty*> | ||
_NODISCARD constexpr bool operator()(_Rng&& _Range, const _Ty& _Val, _Pj _Proj = {}) const { | ||
// clang-format on | ||
const auto _UResult = _RANGES _Find_unchecked(_Ubegin(_Range), _Uend(_Range), _Val, _Pass_fn(_Proj)); |
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 believe we should memoize _Uend(_Range)
as calling it twice might be expensive
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.
We generally don't avoid repeated calls to begin
and end
, because they are generally O(1). The first call may be expensive, but the subsequent calls are not. (Caching things across big function calls consumes stack and pushes us closer to cold stack space, so it's not a no-brainer.)
return true; | ||
} | ||
|
||
const auto _Match = _RANGES search(_Range1, _Range2, _Pass_fn(_Pred), _Pass_fn(_Proj1), _Pass_fn(_Proj2)); |
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.
Should we forward _Range1
and move _Range2
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.
lvalue ranges are strictly more capable than xvalue ranges, so forwarding is just noise for the purposes of algorithms.
Thanks, updating mirror! 🪞 |
Thanks for implementing this C++23 ranges feature - I can barely contain my excitement! 😹 🎉 😻 |
Glad to be part of bringing this super advanced technology that took decades to standardise. |
Co-authored-by: Stephan T. Lavavej <[email protected]> Co-authored-by: Casey Carter <[email protected]>
Fixes: #2921
I more or less just copied the tests for find and search. I'm guessing the feature test macro.