Skip to content

Conversation

hawkinsw
Copy link
Contributor

No description provided.

@hawkinsw hawkinsw requested a review from a team as a code owner September 22, 2023 14:15
@hawkinsw hawkinsw marked this pull request as draft September 22, 2023 14:15
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Sep 22, 2023
Continue implementation and add first smoke tests.
@hawkinsw hawkinsw self-assigned this Sep 27, 2023
@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 5b8204b2215f293f69dded5be2774bec7bb1fde0 9a617a98330ea5b8f4992041cbeea393a8039678 -- libcxx/include/__ranges/slide_view.h libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
View the diff from clang-format here.
diff --git a/libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
index 6d075d25f027..a4fb9784a6d8 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
@@ -10,7 +10,6 @@
 
 // std::views::slide
 
-
 #include "test_iterators.h"
 #include <cassert>
 #include <concepts>

@philnik777 philnik777 added the ranges Issues related to `<ranges>` label Oct 6, 2023
@tambry
Copy link
Contributor

tambry commented Oct 24, 2023

This fails to compile the following example:

#include <ranges>
#include <vector>

int main()
{
	const std::vector<int> v{1, 2, 3, 4, 5, 6};
	v | std::views::slide(2);
}

Copy link
Member

@xiaoyang-sde xiaoyang-sde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request appears to have been in a draft state for a while, and you might be blocked on stride_view (#65200). I left these comments to potentially unblock you on this pull rqeuests, as both the stride_view and slide_view features proposed for C++23 are useful features. In addition, it seems that slide_view::iterator lacks a few operators.

Take your time! No need to rush.

Reference: Draft C++ Standard: [range.slide]

Comment on lines +79 to +93
_LIBCPP_HIDE_FROM_ABI constexpr auto begin()
requires(!(__simple_view<_View> && __slide_caches_nothing<const _View>) && __slide_caches_last<_View>)
{
auto __first = ranges::begin(__base_);
if (!__cached_begin_.__has_value()) {
__cached_begin_.__emplace(ranges::next(__first, __n_ - 1, ranges::end(__base_)));
}
return __iterator<false>(__first, __cached_begin_, __n_);
}

_LIBCPP_HIDE_FROM_ABI constexpr auto begin()
requires(!(__simple_view<_View> && __slide_caches_nothing<const _View>))
{
return __iterator<false>(ranges::begin(__base_), __n_);
}
Copy link
Member

@xiaoyang-sde xiaoyang-sde Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these methods can be merged with if constexpr.

_LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }

_LIBCPP_HIDE_FROM_ABI constexpr auto begin()
requires(!(__simple_view<_View> && __slide_caches_nothing<const _View>) && __slide_caches_last<_View>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the constraint should be __slide_caches_first<_View> instead of __slide_caches_last<_View>.


_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) {
if constexpr (__slide_caches_first<_Base>) {
__x.__last_ == __y.__last_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__x.__last_ == __y.__last_;
return __x.__last_ == __y.__last_;

Comment on lines +63 to +65
using _Cache = _If<!(__slide_caches_nothing<_View>), __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_Cache __cached_begin_;
_Cache __cached_end_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these caches can't exist at the same time, so I think we can make either of them an __empty_cache.

@hawkinsw
Copy link
Contributor Author

This pull request appears to have been in a draft state for a while, and you might be blocked on stride_view (#65200). I left these comments to potentially unblock you on this pull rqeuests, as both the stride_view and slide_view features proposed for C++23 are useful features. In addition, it seems that slide_view::iterator lacks a few operators.

Take your time! No need to rush.

Reference: Draft C++ Standard: [range.slide]

Thank you for the feedback! Yes, I am blocked on stride_view so I will double down and get back to work on this! Thank you, again, for the feedback!!

Will

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants