[libcxx-commits] [libcxx] WIP: Implement std::ranges::view_interface<D>::cbegin/cend (PR #174690)

Will Hawkins via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 6 19:49:38 PST 2026


https://github.com/hawkinsw updated https://github.com/llvm/llvm-project/pull/174690

>From f0ab94297164153e96f18c3b0c63d355daa24170 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Tue, 6 Jan 2026 22:43:36 -0500
Subject: [PATCH] WIP: Implement std::ranges::view_interface<D>::cbegin/cend

Signed-off-by: Will Hawkins <hawkinsw at obs.cr>
---
 libcxx/include/__ranges/view_interface.h | 32 ++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/libcxx/include/__ranges/view_interface.h b/libcxx/include/__ranges/view_interface.h
index 3bcfbaf3a2f9e..84dc7fbcaa25e 100644
--- a/libcxx/include/__ranges/view_interface.h
+++ b/libcxx/include/__ranges/view_interface.h
@@ -150,6 +150,38 @@ class view_interface {
     return *ranges::prev(ranges::end(__derived()));
   }
 
+#  if _LIBCPP_STD_VER >= 23
+
+  template <class _D2 = _Derived>
+  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) cbegin()
+    requires input_range<_D2>
+  {
+    return *ranges::cbegin(__derived());
+  }
+
+  template <class _D2 = _Derived>
+  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) cbegin() const
+    requires input_range<const _D2>
+  {
+    return *ranges::cbegin(__derived());
+  }
+
+  template <class _D2 = _Derived>
+  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) cend()
+    requires input_range<_D2>
+  {
+    return *ranges::cend(__derived());
+  }
+
+  template <class _D2 = _Derived>
+  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) cend() const
+    requires input_range<const _D2>
+  {
+    return *ranges::cend(__derived());
+  }
+
+#  endif // _LIBCPP_STD_VER >= 23
+
   template <random_access_range _RARange = _Derived>
   _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) {
     return ranges::begin(__derived())[__index];



More information about the libcxx-commits mailing list