[libcxx-commits] [PATCH] D106207: [libcxx][ranges] makes `ranges::subrange` a borrowed range

Christopher Di Bella via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 16 19:23:27 PDT 2021


cjdb updated this revision to Diff 359518.
cjdb added a comment.

fixes test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106207/new/

https://reviews.llvm.org/D106207

Files:
  libcxx/include/__ranges/subrange.h
  libcxx/include/ranges
  libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp


Index: libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: gcc-10
+
+// class std::ranges::subrange;
+
+#include <ranges>
+
+#include "test_iterators.h"
+
+namespace ranges = std::ranges;
+
+static_assert(ranges::borrowed_range<ranges::subrange<int*>>);
+static_assert(ranges::borrowed_range<ranges::subrange<int*, int const*>>);
+static_assert(ranges::borrowed_range<ranges::subrange<int*, sentinel_wrapper<int*>, ranges::subrange_kind::unsized>>);
Index: libcxx/include/ranges
===================================================================
--- libcxx/include/ranges
+++ libcxx/include/ranges
@@ -93,6 +93,16 @@
     requires is_class_v<D> && same_as<D, remove_cv_t<D>>
   class view_interface;
 
+  // [range.subrange], sub-ranges
+  enum class subrange_kind : bool { unsized, sized };
+
+  template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
+    requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
+  class subrange;
+
+  template<class I, class S, subrange_kind K>
+    inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
+
   // [range.empty], empty view
   template<class T>
     requires is_object_v<T>
Index: libcxx/include/__ranges/subrange.h
===================================================================
--- libcxx/include/__ranges/subrange.h
+++ libcxx/include/__ranges/subrange.h
@@ -226,6 +226,9 @@
     else
       return __subrange.end();
   }
+
+  template<class _Ip, class _Sp, subrange_kind _Kp>
+  inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true;
 } // namespace ranges
 
 using ranges::get;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106207.359518.patch
Type: text/x-patch
Size: 2329 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210717/7609c42c/attachment.bin>


More information about the libcxx-commits mailing list