[libcxx-commits] [libcxx] WIP: [libc++][ranges] Implement `ranges::slide_view` (PR #67146)
Will Hawkins via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 2 06:35:40 PDT 2023
https://github.com/hawkinsw updated https://github.com/llvm/llvm-project/pull/67146
>From 76a08de8f9b39cb7db31a2274cac1f41dc690133 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Fri, 22 Sep 2023 10:14:06 -0400
Subject: [PATCH 1/6] WIP: [libc++][ranges] Implement `ranges::slide_view`
---
libcxx/include/__ranges/slide_view.h | 219 +++++++++++++++++++++++++++
libcxx/modules/std/ranges.inc | 4 +-
2 files changed, 221 insertions(+), 2 deletions(-)
create mode 100644 libcxx/include/__ranges/slide_view.h
diff --git a/libcxx/include/__ranges/slide_view.h b/libcxx/include/__ranges/slide_view.h
new file mode 100644
index 000000000000000..48bad53740a1fda
--- /dev/null
+++ b/libcxx/include/__ranges/slide_view.h
@@ -0,0 +1,219 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___RANGES_SLIDE_VIEW_H
+#define _LIBCPP___RANGES_SLIDE_VIEW_H
+
+#include <__assert>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__iterator/prev.h>
+#include <__memory/addressof.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/counted.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/view_interface.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template <typename _V>
+concept __slide_caches_nothing = random_access_range<_V> && sized_range<_V>;
+template <typename _V>
+concept __slide_caches_last = !__slide_caches_nothing<_V> && bidirectional_range<_V> && common_range<_V>;
+template <typename _V>
+concept __slide_caches_first = !__slide_caches_nothing<_V> && !__slide_caches_last<_V>;
+
+template <forward_range _View>
+ requires view<_View>
+class slide_view : public view_interface<slide_view<_View>> {
+public:
+ template <bool>
+ class __iterator;
+ class __sentinel;
+
+private:
+ _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
+ range_difference_t<_View> __n_ = 0;
+ using _Cache = _If<!(__slide_caches_nothing<_View>), __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
+ _Cache __cached_begin_;
+ _Cache __cached_end_;
+
+public:
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit slide_view(_View __base, range_difference_t<_View> __n)
+ : __base_(std::move(__base)), __n_(__n) {}
+
+ _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+ requires copy_constructible<_View>
+ {
+ return __base_;
+ }
+
+ _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>)
+ {
+ 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_);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+ requires __slide_caches_nothing<_View>
+ {
+ return __iterator<true>(ranges::begin(__base_), __n_);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+ requires(!(__simple_view<_View> && __slide_caches_nothing<const _View>))
+ {
+ if constexpr (__slide_caches_nothing<_View>) {
+ return __iterator<false>(ranges::begin(__base_) + range_difference_t<_View>(size()), __n_);
+ } else if constexpr (__slide_caches_last<_View>) {
+ return __iterator<false>(ranges::prev(ranges::end(__base_), __n_ - 1, ranges::begin(__base_)), __n_);
+ } else if constexpr (common_range<_View>) {
+ return __iterator<false>(ranges::end(__base_), ranges::end(__base_), __n_);
+ } else {
+ return sentinel<false>(ranges::end(__base_));
+ }
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+ requires __slide_caches_nothing<const _View>
+ {
+ return begin() + range_difference_t<const _View>(size());
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+ requires sized_range<const _View>
+ {
+ auto __size = ranges::distance(__base_) - __n_ + 1;
+ if (__size < 0) {
+ __size = 0;
+ }
+ return std::__to_unsigned_like(__size);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+ requires sized_range<_View>
+ {
+ auto __size = ranges::distance(__base_) - __n_ + 1;
+ if (__size < 0) {
+ __size = 0;
+ }
+ }
+};
+
+template <class _Range>
+slide_view(_Range&&) -> slide_view<views::all_t<_Range>>;
+
+template <class _View>
+struct __slide_view_iterator_concept {
+ using type = forward_iterator_tag;
+};
+
+template <random_access_range _View>
+struct __slide_view_iterator_concept<_View> {
+ using type = random_access_iterator_tag;
+};
+
+template <bidirectional_range _View>
+struct __slide_view_iterator_concept<_View> {
+ using type = bidirectional_iterator_tag;
+};
+
+template <forward_range _View>
+ requires view<_View>
+template <bool _Const>
+class slide_view<_View>::__iterator {
+ friend slide_view;
+
+ using _Base = __maybe_const<_Const, _View>;
+ slide_view* __parent_ = nullptr;
+ _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __current_ = iterator_t<_Base>();
+ _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __last_ = iterator_t<_Base>();
+ range_difference_t<_Base> __n_ = 0;
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator(iterator_t<_Base> __current, range_difference_t<_Base> __n)
+ requires(!(__slide_caches_first<_Base>))
+ : __current_(__current), __n_(__n) {}
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator(
+ iterator_t<_Base> __current, iterator_t<_Base> __last, range_difference_t<_Base> __n)
+ requires(__slide_caches_first<_Base>)
+ : __current_(__current), __last_(__last), __n_(__n) {}
+
+public:
+ using value_type = decltype(views::counted(__current_, __n_));
+ using difference_type = range_difference_t<_Base>;
+ using iterator_category = input_iterator_tag;
+ using iterator_concept = __slide_view_iterator_concept<_Base>;
+
+ _LIBCPP_HIDE_FROM_ABI __iterator() = default;
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator<!_Const> __i)
+ requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
+ : __current_(std::move(__i.__current_)), __n_(__i.__n_) {}
+
+ // TODO ...
+};
+
+template <forward_range _View>
+ requires view<_View>
+class slide_view<_View>::__sentinel {
+ // TODO ...
+};
+
+namespace views {
+namespace __slide {
+struct __fn {
+ // TODO ...
+};
+} // namespace __slide
+
+inline namespace __cpo {
+inline constexpr auto slide = __slide::__fn{};
+} // namespace __cpo
+} // namespace views
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANGES_SLIDE_VIEW_H
diff --git a/libcxx/modules/std/ranges.inc b/libcxx/modules/std/ranges.inc
index a883103d812588b..fe0e5bc6eca1781 100644
--- a/libcxx/modules/std/ranges.inc
+++ b/libcxx/modules/std/ranges.inc
@@ -305,15 +305,15 @@ export namespace std {
namespace views {
using std::ranges::views::chunk;
}
+#endif
+#if _LIBCPP_STD_VER >= 23
using std::ranges::slide_view;
namespace views {
using std::ranges::views::slide;
}
-#endif
-#if _LIBCPP_STD_VER >= 23
// [range.chunk.by], chunk by view
using std::ranges::chunk_by_view;
>From 9a617a98330ea5b8f4992041cbeea393a8039678 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Wed, 27 Sep 2023 10:36:32 -0400
Subject: [PATCH 2/6] fixup! WIP: [libc++][ranges] Implement
`ranges::slide_view`
Continue implementation and add first smoke tests.
---
libcxx/include/CMakeLists.txt | 1 +
libcxx/include/__ranges/slide_view.h | 95 +++++++++++++++++--
libcxx/include/ranges | 3 +-
.../range.slide.view/adaptor.pass.cpp | 62 ++++++++++++
4 files changed, 151 insertions(+), 10 deletions(-)
create mode 100644 libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..4fbf7bdf198a55b 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -637,6 +637,7 @@ set(files
__ranges/single_view.h
__ranges/size.h
__ranges/split_view.h
+ __ranges/slide_view.h
__ranges/subrange.h
__ranges/take_view.h
__ranges/take_while_view.h
diff --git a/libcxx/include/__ranges/slide_view.h b/libcxx/include/__ranges/slide_view.h
index 48bad53740a1fda..c1c701addb10ecd 100644
--- a/libcxx/include/__ranges/slide_view.h
+++ b/libcxx/include/__ranges/slide_view.h
@@ -14,16 +14,17 @@
#include <__concepts/constructible.h>
#include <__concepts/convertible_to.h>
#include <__config>
+#include <__functional/bind_back.h>
#include <__iterator/concepts.h>
#include <__iterator/default_sentinel.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
#include <__iterator/prev.h>
-#include <__memory/addressof.h>
#include <__ranges/all.h>
#include <__ranges/concepts.h>
#include <__ranges/counted.h>
+#include <__ranges/empty_view.h>
#include <__ranges/non_propagating_cache.h>
#include <__ranges/range_adaptor.h>
#include <__ranges/view_interface.h>
@@ -134,6 +135,7 @@ class slide_view : public view_interface<slide_view<_View>> {
if (__size < 0) {
__size = 0;
}
+ return __size;
}
};
@@ -158,21 +160,21 @@ struct __slide_view_iterator_concept<_View> {
template <forward_range _View>
requires view<_View>
template <bool _Const>
-class slide_view<_View>::__iterator {
+class slide_view<_View>::__iterator : public __slide_view_iterator_concept<_View> {
friend slide_view;
- using _Base = __maybe_const<_Const, _View>;
- slide_view* __parent_ = nullptr;
+ using _Base = __maybe_const<_Const, _View>;
+ using _Last = _If<__slide_caches_first<_Base>, iterator_t<_Base>, empty_view<_Base>>;
+ slide_view* __parent_ = nullptr;
_LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __current_ = iterator_t<_Base>();
- _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __last_ = iterator_t<_Base>();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Last __last_ = {};
range_difference_t<_Base> __n_ = 0;
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(iterator_t<_Base> __current, range_difference_t<_Base> __n)
requires(!(__slide_caches_first<_Base>))
: __current_(__current), __n_(__n) {}
- _LIBCPP_HIDE_FROM_ABI constexpr __iterator(
- iterator_t<_Base> __current, iterator_t<_Base> __last, range_difference_t<_Base> __n)
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator(iterator_t<_Base> __current, _Last __last, range_difference_t<_Base> __n)
requires(__slide_caches_first<_Base>)
: __current_(__current), __last_(__last), __n_(__n) {}
@@ -188,7 +190,72 @@ class slide_view<_View>::__iterator {
requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
: __current_(std::move(__i.__current_)), __n_(__i.__n_) {}
- // TODO ...
+ _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { return views::counted(__current_, __n_); }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() {
+ __current_ = ranges::next(__current_);
+ if constexpr (__slide_caches_first<_Base>) {
+ __last_ = ranges::next(__last_);
+ }
+ return *this;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) {
+ auto __tmp = *this;
+ ++*this;
+ return __tmp;
+ // TODO ...
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--()
+ requires bidirectional_range<_View>
+ {
+ __current_ = ranges::prev(__current_);
+ if constexpr (__slide_caches_first<_Base>) {
+ __last_ = std::prev(__last_);
+ }
+ return *this;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int)
+ requires bidirectional_range<_View>
+ {
+ auto __tmp = *this;
+ --*this;
+ return __tmp;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __x)
+ requires random_access_range<_Base>
+ {
+ __current_ = std::prev(__current_, __x);
+ if constexpr (__slide_caches_first<_Base>) {
+ __last_ = std::prev(__last_, __x);
+ }
+ return *this;
+ }
+ _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator+=(difference_type __x)
+ requires random_access_range<_Base>
+ {
+ __current_ = std::next(__current_, __x);
+ if constexpr (__slide_caches_first<_Base>) {
+ __last_ = std::next(__last_, __x);
+ }
+ return *this;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __x) const
+ requires random_access_range<_Base>
+ {
+ return views::counted(__current_ + __x, __n_);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) {
+ if constexpr (__slide_caches_first<_Base>) {
+ __x.__last_ == __y.__last_;
+ }
+ return __x.__current_ == __y.__current_;
+ }
};
template <forward_range _View>
@@ -200,7 +267,17 @@ class slide_view<_View>::__sentinel {
namespace views {
namespace __slide {
struct __fn {
- // TODO ...
+ template <viewable_range _Range>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, range_difference_t<_Range> __n) const
+ noexcept(noexcept(slide_view{std::forward<_Range>(__range), __n}))
+ -> decltype(slide_view{std::forward<_Range>(__range), __n}) {
+ return slide_view{std::forward<_Range>(__range), __n};
+ }
+
+ template <class _Np>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Np&& __n) const {
+ return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Np>(__n)));
+ }
};
} // namespace __slide
diff --git a/libcxx/include/ranges b/libcxx/include/ranges
index db592fd5cb360c4..8f7ca939d4c81b9 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -405,6 +405,7 @@ namespace std {
#include <__ranges/reverse_view.h>
#include <__ranges/single_view.h>
#include <__ranges/size.h>
+#include <__ranges/slide_view.h>
#include <__ranges/split_view.h>
#include <__ranges/subrange.h>
#include <__ranges/take_view.h>
@@ -417,7 +418,7 @@ namespace std {
#include <version>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#include <__ranges/istream_view.h>
+# include <__ranges/istream_view.h>
#endif
// standard-mandated includes
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
new file mode 100644
index 000000000000000..6d075d25f027236
--- /dev/null
+++ b/libcxx/test/std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::views::slide
+
+
+#include "test_iterators.h"
+#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <utility>
+
+template <class View, class T>
+concept CanBePiped = requires(View&& view, T&& t) {
+ { std::forward<View>(view) | std::forward<T>(t) };
+};
+
+struct SizedView : std::ranges::view_base {
+ int* begin_ = nullptr;
+ int* end_ = nullptr;
+ constexpr SizedView(int* begin, int* end) : begin_(begin), end_(end) {}
+
+ constexpr auto begin() const { return forward_iterator<int*>(begin_); }
+ constexpr auto end() const { return sized_sentinel<forward_iterator<int*>>(forward_iterator<int*>(end_)); }
+};
+static_assert(std::ranges::forward_range<SizedView>);
+static_assert(std::ranges::sized_range<SizedView>);
+static_assert(std::ranges::view<SizedView>);
+
+constexpr bool test() {
+ constexpr int n = 8;
+ int buf[n] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ // Test that `std::views::slide` is a range adaptor.
+ {
+ using SomeView = SizedView;
+
+ // Test `view | views::take`
+ {
+ SomeView view(buf, buf + n);
+ std::same_as<std::ranges::slide_view<SomeView>> decltype(auto) result = view | std::views::slide(2);
+ assert(result.base().begin_ == buf);
+ assert(result.base().end_ == buf + n);
+ assert(result.size() == 7);
+ }
+ }
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
>From 525fa902d502a957016bbc3cc2697518348f64f0 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 2 Oct 2023 09:11:58 -0400
Subject: [PATCH 3/6] fixup! WIP: [libc++][ranges] Implement
`ranges::slide_view`
Add slide_view to the module map.
---
libcxx/include/module.modulemap.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 6d9bb8653fcb5e9..76cd73389c78eb4 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1719,6 +1719,7 @@ module std_private_ranges_size [system] {
header "__ranges/size.h"
export std_private_type_traits_make_unsigned
}
+module std_private_ranges_slide_view [system] { header "__ranges/slide_view.h" }
module std_private_ranges_split_view [system] { header "__ranges/split_view.h" }
module std_private_ranges_subrange [system] {
header "__ranges/subrange.h"
>From b86041f05b2fbf92f10f2a13b2f4af48f2fe42c6 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 2 Oct 2023 09:16:32 -0400
Subject: [PATCH 4/6] fixup! WIP: [libc++][ranges] Implement
`ranges::slide_view`
Make clang-format happy on blank line in test.
---
.../std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp | 1 -
1 file changed, 1 deletion(-)
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 6d075d25f027236..a4fb9784a6d8fcf 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>
>From a62ecd56777b7d86c258252abda6a8b2d054dab7 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 2 Oct 2023 09:35:01 -0400
Subject: [PATCH 5/6] fixup! WIP: [libc++][ranges] Implement
`ranges::slide_view`
Implement slide_view::__sentinel.
---
libcxx/include/__ranges/slide_view.h | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__ranges/slide_view.h b/libcxx/include/__ranges/slide_view.h
index c1c701addb10ecd..49e75d0c407b0b3 100644
--- a/libcxx/include/__ranges/slide_view.h
+++ b/libcxx/include/__ranges/slide_view.h
@@ -261,7 +261,26 @@ class slide_view<_View>::__iterator : public __slide_view_iterator_concept<_View
template <forward_range _View>
requires view<_View>
class slide_view<_View>::__sentinel {
- // TODO ...
+ sentinel_t<_View> __end_ = sentinel_t<_View>();
+ constexpr explicit __sentinel(sentinel_t<_View> __end) : __end_(__end) {}
+
+public:
+ __sentinel() = default;
+
+ friend constexpr bool operator==(const slide_view::__iterator<false>& __x, const __sentinel& __y) {
+ return __x.__last_ == __y.__end_;
+ };
+ friend constexpr range_difference_t<_View> operator-(const slide_view::__iterator<false>& __x, const __sentinel& __y)
+ requires sized_sentinel_for<sentinel_t<_View>, iterator_t<_View>>
+ {
+ return __x.__last_ - __y.__end_;
+ };
+
+ friend constexpr range_difference_t<_View> operator-(const __sentinel& __y, const slide_view::__iterator<false>& __x)
+ requires sized_sentinel_for<sentinel_t<_View>, iterator_t<_View>>
+ {
+ return __y.__end_ - __x.__last_;
+ }
};
namespace views {
>From fc449ed1d79f38dc583038cce8ca3acb99a26b38 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 2 Oct 2023 09:35:19 -0400
Subject: [PATCH 6/6] fixup! WIP: [libc++][ranges] Implement
`ranges::slide_view`
Fix typo in test.
---
.../std/ranges/range.adaptors/range.slide.view/adaptor.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 a4fb9784a6d8fcf..858212b266b508a 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
@@ -41,7 +41,7 @@ constexpr bool test() {
{
using SomeView = SizedView;
- // Test `view | views::take`
+ // Test `view | views::slide`
{
SomeView view(buf, buf + n);
std::same_as<std::ranges::slide_view<SomeView>> decltype(auto) result = view | std::views::slide(2);
More information about the libcxx-commits
mailing list