-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[libc++][ranges] Implement ranges::stride_view
.
#65200
base: main
Are you sure you want to change the base?
Conversation
Thank you all for the feedback on this work. I am really excited to get to participate. As I said, I have committed small amounts of code in the past but this is my first attempt at doing a significant amount of implementation. I have already learned a ton and look forward to learning more! |
I just used a |
I know how busy you all must be with the transition to GitHub. I am going to continue to work on writing tests and look forward to any feedback you have! |
ranges::stride_view
.ranges::stride_view
.
Removed the Will |
using difference_type = range_difference_t<_Base>; | ||
using value_type = range_value_t<_Base>; | ||
using iterator_concept = | ||
_If<random_access_range<_Base>, |
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.
None of this needs the cost of lazy SFINAE. and that's a lot of instantiations. Can we reduce it some?
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.
@EricWF Sorry to have to ask ... I know what each of the words "lazy" and "SFINAE" means but in combination I am not entirely sure to what you are referring. Could you point me to something that I use to educate myself so that I can fix this antipattern? Sorry again to have to ask!
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.
@EricWF I now realized what you meant and believe that the fixup I am about to submit will resolve this! Thanks again for the feedback!
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 won't be so presumptuous as to Resolve this conversation, but let me know if what I just changed seems better.
forward_iterator_tag, | ||
/* else */ input_iterator_tag >>>; | ||
|
||
_LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __current_ = iterator_t<_Base>(); |
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.
A stateless iterator... interesting....
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 agree. Although the standard labels this default value as exposition only, I checked that other range adaptor implementations follow that "guidance" (see, e.g., transform_view
).
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 isn't just about empty types. This also compresses types with tail padding.
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.
Quick review of product code. Also, please rebase.
libcxx/modules/std/ranges.inc
Outdated
// [range.stride], stride view | ||
using std::ranges::stride_view; | ||
|
||
namespace views { | ||
using std::ranges::views::stride; | ||
} | ||
|
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
module is available in C++20 as an extensions, we should add language guards:
// [range.stride], stride view | |
using std::ranges::stride_view; | |
namespace views { | |
using std::ranges::views::stride; | |
} | |
#if _LIBCPP_STD_VER >= 23 | |
// [range.stride], stride view | |
using std::ranges::stride_view; | |
namespace views { | |
using std::ranges::views::stride; | |
} | |
#endif // _LIBCPP_STD_VER >= 23 |
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 just want to make sure that I understand:
In C++20 there is an extension that would enable the use of this module. std::ranges::stride_view
is only available as of C++23. So, in the case where this module was used as an extension in a C++20-compatible compiler, without this guard there would be a problem.
I hope that I am understanding correctly! Great catch!
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.
In C++20 there is an extension that would enable the use of this module.
Yes, it is documented here: https://libcxx.llvm.org/Modules.html
std::ranges::stride_view
is only available as of C++23. So, in the case where this module was used as an extension in a C++20-compatible compiler, without this guard there would be a problem.
Yes, I've got bitten by it too while implementing views::chunk_by
.
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.
Thank you! I appreciate you pointing this out and I am glad that I understood your point. I believe that I have addressed the comment. If so, would you mind if I marked the conversation resolved?
@JMazurkiewicz Thank you for your incredibly helpful comments. I have a few things to do at $dayjob but I will address them as soon as possible. Thank you again for taking the time to comment. |
f06de96
to
a3279a3
Compare
Hello again and sorry to bother. I would love to make any changes to the implementation that you think are necessary. I have really enjoyed the opportunity to implement stride_view and I have already started on slide_view! |
Please update the status page and any papers: libcxx/docs/Status/RangesViews.csv |
Thank you for the feedback! Are you asking for an update to remove you as an implementer? Refer to the this URL for the PR? I believe that the paper listed in the CSV is the right one? I am sorry if I am missing something obvious. |
Please change the URL to point to this PR, also mark which papers this PR implements as complete. You probably need to add the paper to the release notes, when this PR is approved. |
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.
Sorry about the long delay! I only went through the stride_view.h
header and haven't looked at the tests closely yet, but I wanted to give you the feedback I have so far. Thanks a lot for all the work on the patch!
|
||
public: | ||
_LIBCPP_HIDE_FROM_ABI constexpr explicit stride_view(_View __base, range_difference_t<_View> __stride) | ||
: __base_(std::move(__base)), __stride_(__stride) {} |
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.
Can we test with a move-only __base
?
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 that I addressed this in a93fef8
|
||
_LIBCPP_HIDE_FROM_ABI friend constexpr range_rvalue_reference_t<_Base> | ||
iter_move(__iterator const& __it) noexcept(noexcept(ranges::iter_move(__it.__current_))) { | ||
return ranges::iter_move(__it.__current_); |
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.
Question: do we have tests for the customization point (here and for iter_swap
)?
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 that this is addressed in 8405d877bc86bde51c4ec61ca7811065c69f1149.
struct __fn { | ||
template <viewable_range _Range> | ||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, range_difference_t<_Range> __n) const | ||
noexcept(noexcept(stride_view{std::forward<_Range>(__range), __n})) |
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 would be slightly easier to read if the three repetitions of the expression were vertically aligned. I think the best way to achieve that is using a /* */
comment like this -- see e.g. as_rvalue_view.h
for an example.
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.
Clever use of the block comment! I believe that this is addressed in accfb24af355238748e22653b46ed3c08db2208d.
✅ With the latest revision this PR passed the C/C++ code formatter. |
f33b89b
to
861dbbb
Compare
Fix formatting.
Fix dereference test unsupported tag.
Address feedback from @EricWF.
Fix issue with version file.
Updating tests based on feedback. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Add check for whether iterator::base is move/copy Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
clang-format Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Add additional testing for sentinel mathematics. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Make sure that all nodiscard-marked member functions are checked. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Fix bad rebase. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Finish fixing bad rebase. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Format. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Format. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Format. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Begin splitting iterator tests into different files. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Clean up the iterator increment tests. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Fix minor format error. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Refactor and add additional tests. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Bring into line with updates to features like [[nodiscard]] vs _LIBCPP_NODISCARD
Discard accidental change to another range adaptor.
Make formatting happy.
Add stride view into the module map. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Rebase to main.
Clang format changes.
Clang format changes.
Add another operator (+) test.
Fix verifier error triggered by bad auto format.
Explicitly import vector where needed (for modules).
// Test that std::ranges::stride_view::base() is marked nodiscard. | ||
|
||
#include <ranges> | ||
|
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.
CI failure caused by missed inclusion.
#include <vector> | |
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.
Thanks!
Implement
ranges::stride_view
in libc++. Migrating to this GitHub from Phabricator (https://reviews.llvm.org/D156924).Closes #105198