[libcxx-commits] [libcxx] ba032a6 - [libcxx][ranges] Enable borrowed range for drop view when T has borrowing enabled.

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 24 11:09:33 PDT 2021


Author: zoecarver
Date: 2021-06-24T11:09:25-07:00
New Revision: ba032a614a009c28eb1232efff7841c96eb828e0

URL: https://github.com/llvm/llvm-project/commit/ba032a614a009c28eb1232efff7841c96eb828e0
DIFF: https://github.com/llvm/llvm-project/commit/ba032a614a009c28eb1232efff7841c96eb828e0.diff

LOG: [libcxx][ranges] Enable borrowed range for drop view when T has borrowing enabled.

Added: 
    

Modified: 
    libcxx/include/__ranges/drop_view.h
    libcxx/test/std/ranges/range.adaptors/range.drop/general.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.drop/types.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__ranges/drop_view.h b/libcxx/include/__ranges/drop_view.h
index 610305709a34c..d88d69792ea0a 100644
--- a/libcxx/include/__ranges/drop_view.h
+++ b/libcxx/include/__ranges/drop_view.h
@@ -143,6 +143,9 @@ namespace ranges {
   // TODO: this is just recreating all_t.
     -> drop_view<decltype(views::all(std::declval<_Range>()))>;
 
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>;
+
 } // namespace ranges
 
 #endif // !defined(_LIBCPP_HAS_NO_RANGES)

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.drop/general.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.drop/general.pass.cpp
index 2d1245a0fe975..087e11e2f566c 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.drop/general.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.drop/general.pass.cpp
@@ -28,9 +28,12 @@
 template<class T>
 concept ValidDropView = requires { typename std::ranges::drop_view<T>; };
 
-static_assert(ValidDropView<ContiguousView>);
+static_assert( ValidDropView<ContiguousView>);
 static_assert(!ValidDropView<Range>);
 
+static_assert(!std::ranges::enable_borrowed_range<std::ranges::drop_view<ContiguousView>>);
+static_assert( std::ranges::enable_borrowed_range<std::ranges::drop_view<BorrowableView>>);
+
 template<std::ranges::view View>
 bool orderedFibonacci(View v, int n = 1) {
   if (v.size() < 3)

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.drop/types.h b/libcxx/test/std/ranges/range.adaptors/range.drop/types.h
index 35d91ed4b97b1..692fdfece2771 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.drop/types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range.drop/types.h
@@ -80,6 +80,16 @@ struct BorrowableRange {
 template<>
 inline constexpr bool std::ranges::enable_borrowed_range<BorrowableRange> = true;
 
+struct BorrowableView : std::ranges::view_base {
+  friend int* begin(BorrowableView const& range);
+  friend int* end(BorrowableView const&);
+  friend int* begin(BorrowableView& range);
+  friend int* end(BorrowableView&);
+};
+
+template<>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowableView> = true;
+
 struct InputView : std::ranges::view_base {
   constexpr cpp20_input_iterator<int*> begin() const { return cpp20_input_iterator<int*>(globalBuff); }
   constexpr int* end() const { return globalBuff + 8; }


        


More information about the libcxx-commits mailing list