[libcxx-commits] [libcxx] c40b026 - [libcxx][ranges] Implement `ranges::borrowed_range`.
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 20 11:51:49 PDT 2021
Author: zoecarver
Date: 2021-05-20T11:51:44-07:00
New Revision: c40b02608eea5541b9f402f285b78cb0c1f3bb72
URL: https://github.com/llvm/llvm-project/commit/c40b02608eea5541b9f402f285b78cb0c1f3bb72
DIFF: https://github.com/llvm/llvm-project/commit/c40b02608eea5541b9f402f285b78cb0c1f3bb72.diff
LOG: [libcxx][ranges] Implement `ranges::borrowed_range`.
Differential Revision: https://reviews.llvm.org/D102426
Added:
libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp
Modified:
libcxx/include/__ranges/concepts.h
libcxx/test/std/containers/associative/map/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/associative/multimap/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/associative/multiset/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/array/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/deque/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/forwardlist/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/list/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/vector/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/unord/unord.set/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/views/range_concept_conformance.compile.pass.cpp
libcxx/test/std/input.output/filesystems/class.directory_iterator/range_concept_conformance.compile.pass.cpp
libcxx/test/std/input.output/filesystems/class.path/range_concept_conformance.compile.pass.cpp
libcxx/test/std/re/re.results/range_concept_conformance.compile.pass.cpp
libcxx/test/std/strings/basic.string/range_concept_conformance.compile.pass.cpp
libcxx/test/std/strings/string.view/range_concept_conformance.compile.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h
index 45dbfb5cc8a7d..4c044f52368ab 100644
--- a/libcxx/include/__ranges/concepts.h
+++ b/libcxx/include/__ranges/concepts.h
@@ -36,6 +36,10 @@ namespace ranges {
ranges::end(__t);
};
+ template<class _Range>
+ concept borrowed_range = range<_Range> &&
+ (is_lvalue_reference_v<_Range> || enable_borrowed_range<remove_cvref_t<_Range>>);
+
// `iterator_t` defined in <__ranges/access.h>
template <range _Rp>
diff --git a/libcxx/test/std/containers/associative/map/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/associative/map/range_concept_conformance.compile.pass.cpp
index 3e6f966272705..0b3204c9d775f 100644
--- a/libcxx/test/std/containers/associative/map/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(!stdr::random_access_range<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(!stdr::random_access_range<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/associative/multimap/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/associative/multimap/range_concept_conformance.compile.pass.cpp
index 2c9d14ea2dea9..9b0b9fc995ca6 100644
--- a/libcxx/test/std/containers/associative/multimap/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/associative/multimap/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(!stdr::random_access_range<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(!stdr::random_access_range<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/associative/multiset/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/associative/multiset/range_concept_conformance.compile.pass.cpp
index 8c3f3a1fc8454..f95952c8bba60 100644
--- a/libcxx/test/std/containers/associative/multiset/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/associative/multiset/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(!stdr::random_access_range<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(!stdr::random_access_range<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp
index e0b878ea1f77e..a2150558e0169 100644
--- a/libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp
@@ -27,6 +27,7 @@ static_assert(stdr::common_range<range>);
static_assert(stdr::input_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::bidirectional_range<range const>);
@@ -35,3 +36,4 @@ static_assert(stdr::common_range<range const>);
static_assert(stdr::input_range<range>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/array/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/array/range_concept_conformance.compile.pass.cpp
index fe51c8fa286da..0b457c3ae4389 100644
--- a/libcxx/test/std/containers/sequences/array/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/range_concept_conformance.compile.pass.cpp
@@ -25,9 +25,11 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
static_assert(stdr::common_range<range>);
static_assert(stdr::random_access_range<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(!stdr::view<range const>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
static_assert(stdr::random_access_range<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/deque/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/deque/range_concept_conformance.compile.pass.cpp
index 3c2e6b0ff8a57..1f20686998fe9 100644
--- a/libcxx/test/std/containers/sequences/deque/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/range_concept_conformance.compile.pass.cpp
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
static_assert(stdr::random_access_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
static_assert(stdr::random_access_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/forwardlist/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/range_concept_conformance.compile.pass.cpp
index 6413c96468e46..af237700f943d 100644
--- a/libcxx/test/std/containers/sequences/forwardlist/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/forwardlist/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::forward_range<range>);
static_assert(!stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(!stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::forward_range<range const>);
static_assert(!stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(!stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/list/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/range_concept_conformance.compile.pass.cpp
index ef0ea648063d1..bbe6020603e6c 100644
--- a/libcxx/test/std/containers/sequences/list/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/list/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(!stdr::random_access_range<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(!stdr::random_access_range<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/vector.bool/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/range_concept_conformance.compile.pass.cpp
index da7f456014360..5e2b5b0a14c3f 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/range_concept_conformance.compile.pass.cpp
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
static_assert(stdr::random_access_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
static_assert(stdr::random_access_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/sequences/vector/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/range_concept_conformance.compile.pass.cpp
index cd8f1950464fe..f7568d39628dd 100644
--- a/libcxx/test/std/containers/sequences/vector/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/range_concept_conformance.compile.pass.cpp
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
static_assert(stdr::random_access_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
static_assert(stdr::random_access_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/unord/unord.map/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/range_concept_conformance.compile.pass.cpp
index 85ecfed0d7d93..450705c3417c2 100644
--- a/libcxx/test/std/containers/unord/unord.map/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::forward_range<range>);
static_assert(!stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::forward_range<range const>);
static_assert(!stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/unord/unord.multimap/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/range_concept_conformance.compile.pass.cpp
index 386bd42f9a09a..c98d7b85c4e7b 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::forward_range<range>);
static_assert(!stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::forward_range<range const>);
static_assert(!stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/unord/unord.multiset/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/range_concept_conformance.compile.pass.cpp
index b9b0743a2f9c0..64332c422ba73 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multiset/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::forward_range<range>);
static_assert(!stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::forward_range<range const>);
static_assert(!stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/unord/unord.set/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.set/range_concept_conformance.compile.pass.cpp
index 38a32d1dc1700..922ca43e1242c 100644
--- a/libcxx/test/std/containers/unord/unord.set/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.set/range_concept_conformance.compile.pass.cpp
@@ -26,6 +26,7 @@ static_assert(stdr::forward_range<range>);
static_assert(!stdr::bidirectional_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(!stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
static_assert(stdr::common_range<range const>);
@@ -33,3 +34,4 @@ static_assert(stdr::forward_range<range const>);
static_assert(!stdr::bidirectional_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(!stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/containers/views/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/containers/views/range_concept_conformance.compile.pass.cpp
index f51b44c04ef20..c627c87296e0e 100644
--- a/libcxx/test/std/containers/views/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/containers/views/range_concept_conformance.compile.pass.cpp
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
static_assert(stdr::random_access_range<range>);
static_assert(!stdr::view<range>);
static_assert(stdr::sized_range<range>);
+static_assert(stdr::borrowed_range<range>);
static_assert(std::same_as<stdr::iterator_t<range const>, range::iterator>);
static_assert(stdr::common_range<range const>);
static_assert(stdr::random_access_range<range const>);
static_assert(!stdr::view<range const>);
static_assert(stdr::sized_range<range const>);
+static_assert(stdr::borrowed_range<range const>);
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_iterator/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_iterator/range_concept_conformance.compile.pass.cpp
index a3dd4a32b68f7..80445f28e25cd 100644
--- a/libcxx/test/std/input.output/filesystems/class.directory_iterator/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.directory_iterator/range_concept_conformance.compile.pass.cpp
@@ -25,21 +25,25 @@ static_assert(stdr::common_range<fs::directory_iterator>);
static_assert(stdr::input_range<fs::directory_iterator>);
static_assert(!stdr::view<fs::directory_iterator>);
static_assert(!stdr::sized_range<fs::directory_iterator>);
+static_assert(!stdr::borrowed_range<fs::directory_iterator>);
static_assert(std::same_as<stdr::iterator_t<fs::directory_iterator const>, fs::directory_iterator>);
static_assert(stdr::common_range<fs::directory_iterator const>);
static_assert(stdr::input_range<fs::directory_iterator const>);
static_assert(!stdr::view<fs::directory_iterator const>);
static_assert(!stdr::sized_range<fs::directory_iterator const>);
+static_assert(!stdr::borrowed_range<fs::directory_iterator const>);
static_assert(std::same_as<stdr::iterator_t<fs::recursive_directory_iterator>, fs::recursive_directory_iterator>);
static_assert(stdr::common_range<fs::recursive_directory_iterator>);
static_assert(stdr::input_range<fs::recursive_directory_iterator>);
static_assert(!stdr::view<fs::recursive_directory_iterator>);
static_assert(!stdr::sized_range<fs::recursive_directory_iterator>);
+static_assert(!stdr::borrowed_range<fs::recursive_directory_iterator>);
static_assert(std::same_as<stdr::iterator_t<fs::recursive_directory_iterator const>, fs::recursive_directory_iterator>);
static_assert(stdr::common_range<fs::recursive_directory_iterator const>);
static_assert(stdr::input_range<fs::recursive_directory_iterator const>);
static_assert(!stdr::view<fs::recursive_directory_iterator const>);
static_assert(!stdr::sized_range<fs::recursive_directory_iterator const>);
+static_assert(!stdr::borrowed_range<fs::recursive_directory_iterator const>);
diff --git a/libcxx/test/std/input.output/filesystems/class.path/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/range_concept_conformance.compile.pass.cpp
index 33ff8589264e2..47cec87ffac67 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/range_concept_conformance.compile.pass.cpp
@@ -25,6 +25,7 @@ static_assert(stdr::bidirectional_range<fs::path>);
static_assert(!stdr::view<fs::path>);
static_assert(!stdr::random_access_range<fs::path>);
static_assert(!stdr::sized_range<fs::path>);
+static_assert(!stdr::borrowed_range<fs::path>);
static_assert(std::same_as<stdr::iterator_t<fs::path const>, fs::path::const_iterator>);
static_assert(stdr::common_range<fs::path const>);
@@ -32,3 +33,4 @@ static_assert(stdr::bidirectional_range<fs::path const>);
static_assert(!stdr::view<fs::path const>);
static_assert(!stdr::random_access_range<fs::path const>);
static_assert(!stdr::sized_range<fs::path const>);
+static_assert(!stdr::borrowed_range<fs::path const>);
diff --git a/libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp b/libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
new file mode 100644
index 0000000000000..d645efec0aac8
--- /dev/null
+++ b/libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// template<class T>
+// concept borrowed_range;
+
+#include <ranges>
+
+struct NotRange {
+ int begin() const;
+ int end() const;
+};
+
+struct Range {
+ int *begin();
+ int *end();
+};
+
+struct ConstRange {
+ int *begin() const;
+ int *end() const;
+};
+
+struct BorrowedRange {
+ int *begin() const;
+ int *end() const;
+};
+
+template<>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
+
+static_assert(!std::ranges::borrowed_range<NotRange>);
+static_assert(!std::ranges::borrowed_range<NotRange&>);
+static_assert(!std::ranges::borrowed_range<const NotRange>);
+static_assert(!std::ranges::borrowed_range<const NotRange&>);
+static_assert(!std::ranges::borrowed_range<NotRange&&>);
+
+static_assert(!std::ranges::borrowed_range<Range>);
+static_assert( std::ranges::borrowed_range<Range&>);
+static_assert(!std::ranges::borrowed_range<const Range>);
+static_assert(!std::ranges::borrowed_range<const Range&>);
+static_assert(!std::ranges::borrowed_range<Range&&>);
+
+static_assert(!std::ranges::borrowed_range<ConstRange>);
+static_assert( std::ranges::borrowed_range<ConstRange&>);
+static_assert(!std::ranges::borrowed_range<const ConstRange>);
+static_assert( std::ranges::borrowed_range<const ConstRange&>);
+static_assert(!std::ranges::borrowed_range<ConstRange&&>);
+
+static_assert( std::ranges::borrowed_range<BorrowedRange>);
+static_assert( std::ranges::borrowed_range<BorrowedRange&>);
+static_assert( std::ranges::borrowed_range<const BorrowedRange>);
+static_assert( std::ranges::borrowed_range<const BorrowedRange&>);
+static_assert( std::ranges::borrowed_range<BorrowedRange&&>);
diff --git a/libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp
new file mode 100644
index 0000000000000..163cef4a390bc
--- /dev/null
+++ b/libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// template<class T>
+// concept borrowed_range;
+
+#include <ranges>
+
+template <std::ranges::range R>
+consteval bool check_subsumption() {
+ return false;
+}
+
+template <std::ranges::borrowed_range R>
+consteval bool check_subsumption() {
+ return true;
+}
+
+static_assert(check_subsumption<int (&)[8]>());
diff --git a/libcxx/test/std/re/re.results/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/re/re.results/range_concept_conformance.compile.pass.cpp
index 4b9833c8101b0..c8e8023dddb3d 100644
--- a/libcxx/test/std/re/re.results/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/re/re.results/range_concept_conformance.compile.pass.cpp
@@ -24,9 +24,11 @@ static_assert(stdr::common_range<std::cmatch>);
static_assert(stdr::random_access_range<std::cmatch>);
static_assert(!stdr::view<std::cmatch>);
static_assert(stdr::sized_range<std::cmatch>);
+static_assert(!stdr::borrowed_range<std::cmatch>);
static_assert(std::same_as<stdr::iterator_t<std::cmatch const>, std::cmatch::const_iterator>);
static_assert(stdr::common_range<std::cmatch const>);
static_assert(stdr::random_access_range<std::cmatch const>);
static_assert(!stdr::view<std::cmatch const>);
static_assert(stdr::sized_range<std::cmatch const>);
+static_assert(!stdr::borrowed_range<std::cmatch const>);
diff --git a/libcxx/test/std/strings/basic.string/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/strings/basic.string/range_concept_conformance.compile.pass.cpp
index 124a6fb4821a7..6c3bea2d11304 100644
--- a/libcxx/test/std/strings/basic.string/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/range_concept_conformance.compile.pass.cpp
@@ -24,9 +24,11 @@ static_assert(stdr::common_range<std::string>);
static_assert(stdr::random_access_range<std::string>);
static_assert(!stdr::view<std::string>);
static_assert(stdr::sized_range<std::string>);
+static_assert(!stdr::borrowed_range<std::string>);
static_assert(std::same_as<stdr::iterator_t<std::string const>, std::string::const_iterator>);
static_assert(stdr::common_range<std::string const>);
static_assert(stdr::random_access_range<std::string const>);
static_assert(!stdr::view<std::string const>);
static_assert(stdr::sized_range<std::string const>);
+static_assert(!stdr::borrowed_range<std::string const>);
diff --git a/libcxx/test/std/strings/string.view/range_concept_conformance.compile.pass.cpp b/libcxx/test/std/strings/string.view/range_concept_conformance.compile.pass.cpp
index c36d4d04e332b..e99739a173f14 100644
--- a/libcxx/test/std/strings/string.view/range_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/strings/string.view/range_concept_conformance.compile.pass.cpp
@@ -24,9 +24,11 @@ static_assert(stdr::common_range<std::string_view>);
static_assert(stdr::random_access_range<std::string_view>);
static_assert(!stdr::view<std::string_view>);
static_assert(stdr::sized_range<std::string_view>);
+static_assert(stdr::borrowed_range<std::string_view>);
static_assert(std::same_as<stdr::iterator_t<std::string_view const>, std::string_view::const_iterator>);
static_assert(stdr::common_range<std::string_view const>);
static_assert(stdr::random_access_range<std::string_view const>);
static_assert(!stdr::view<std::string_view const>); // FIXME: string_view needs to be patched so this is true
static_assert(stdr::sized_range<std::string_view const>);
+static_assert(stdr::borrowed_range<std::string_view const>);
More information about the libcxx-commits
mailing list