[libcxx-commits] [libcxx] WIP: [libc++][ranges] Implement `ranges::slide_view` (PR #67146)

Xiaoyang Liu via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 19 23:13:13 PDT 2024


================
@@ -0,0 +1,315 @@
+// -*- 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 <__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 <__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>
+
+#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_;
----------------
xiaoyang-sde wrote:

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


https://github.com/llvm/llvm-project/pull/67146


More information about the libcxx-commits mailing list