[libcxx-commits] [libcxx] [libcxx] extends test range types to take a value-type (PR #74672)

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 6 14:59:22 PST 2023


https://github.com/cjdb created https://github.com/llvm/llvm-project/pull/74672

This increases the types' versatility so that they're not restricted just to `int*`.

>From 66011e265dbf81049c764bab0c1fbc4715f09e82 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Wed, 6 Dec 2023 22:41:33 +0000
Subject: [PATCH] [libcxx] extends test range types to take a value-type

This increases the types' versatility so that they're not restricted
just to `int*`.
---
 .../range.ref.view/borrowing.compile.pass.cpp |  2 +-
 libcxx/test/support/test_range.h              | 54 ++++++++++---------
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/libcxx/test/std/ranges/range.adaptors/range.all/range.ref.view/borrowing.compile.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.all/range.ref.view/borrowing.compile.pass.cpp
index 4405742eb023a..2887ef10b0978 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.all/range.ref.view/borrowing.compile.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.all/range.ref.view/borrowing.compile.pass.cpp
@@ -15,6 +15,6 @@
 
 #include "test_range.h"
 
-static_assert(std::ranges::borrowed_range<std::ranges::ref_view<BorrowedRange>>);
+static_assert(std::ranges::borrowed_range<std::ranges::ref_view<BorrowedRange<>>>);
 static_assert(std::ranges::borrowed_range<std::ranges::ref_view<BorrowedView>>);
 static_assert(std::ranges::borrowed_range<std::ranges::ref_view<NonBorrowedView>>);
diff --git a/libcxx/test/support/test_range.h b/libcxx/test/support/test_range.h
index eea8ce16ce7fa..22bed476666db 100644
--- a/libcxx/test/support/test_range.h
+++ b/libcxx/test/support/test_range.h
@@ -22,55 +22,57 @@ struct sentinel {
   bool operator==(std::input_or_output_iterator auto const&) const;
 };
 
-template <template <class...> class I>
-requires std::input_or_output_iterator<I<int*> >
+template <template <class...> class I, class T = int>
+  requires std::input_or_output_iterator<I<T*> >
 struct test_range {
-  I<int*> begin();
-  I<int const*> begin() const;
+  I<T*> begin();
+  I<T const*> begin() const;
   sentinel end();
   sentinel end() const;
 };
 
-template <template <class...> class I>
-requires std::input_or_output_iterator<I<int*> >
+template <template <class...> class I, class T = int>
+  requires std::input_or_output_iterator<I<T*> >
 struct test_non_const_range {
-  I<int*> begin();
+  I<T*> begin();
   sentinel end();
 };
 
-template <template <class...> class I>
-requires std::input_or_output_iterator<I<int*> >
+template <template <class...> class I, class T = int>
+  requires std::input_or_output_iterator<I<T*> >
 struct test_common_range {
-  I<int*> begin();
-  I<int const*> begin() const;
-  I<int*> end();
-  I<int const*> end() const;
+  I<T*> begin();
+  I<T const*> begin() const;
+  I<T*> end();
+  I<T const*> end() const;
 };
 
-template <template <class...> class I>
-requires std::input_or_output_iterator<I<int*> >
+template <template <class...> class I, class T = int>
+  requires std::input_or_output_iterator<I<T*> >
 struct test_non_const_common_range {
-  I<int*> begin();
-  I<int*> end();
+  I<T*> begin();
+  I<T*> end();
 };
 
-template <template <class...> class I>
-requires std::input_or_output_iterator<I<int*> >
+template <template <class...> class I, class T = int>
+  requires std::input_or_output_iterator<I<T*> >
 struct test_view : std::ranges::view_base {
-  I<int*> begin();
-  I<int const*> begin() const;
+  I<T*> begin();
+  I<T const*> begin() const;
   sentinel end();
   sentinel end() const;
 };
 
+template <class T = int>
 struct BorrowedRange {
-  int *begin() const;
-  int *end() const;
+  T* begin() const;
+  T* end() const;
   BorrowedRange(BorrowedRange&&) = delete;
 };
-template<> inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
-static_assert(!std::ranges::view<BorrowedRange>);
-static_assert(std::ranges::borrowed_range<BorrowedRange>);
+template <class T>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange<T>> = true;
+static_assert(!std::ranges::view<BorrowedRange<>>);
+static_assert(std::ranges::borrowed_range<BorrowedRange<>>);
 
 using BorrowedView = std::ranges::empty_view<int>;
 static_assert(std::ranges::view<BorrowedView>);



More information about the libcxx-commits mailing list