[libcxx-commits] [libcxx] d8fad66 - [libcxx][ranges] adds concept `sized_range` and cleans up `ranges::size`

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 19 11:17:03 PDT 2021


Author: Christopher Di Bella
Date: 2021-05-19T18:16:45Z
New Revision: d8fad6614923eea684f736e7d22fe54d5393f13f

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

LOG: [libcxx][ranges] adds concept `sized_range` and cleans up `ranges::size`

* adds `sized_range` and conformance tests
* moves `disable_sized_range` into namespace `std::ranges`
* removes explicit type parameter

Implements part of P0896 'The One Ranges Proposal'.

Differential Revision: https://reviews.llvm.org/D102434

Added: 
    libcxx/test/std/ranges/range.req/range.range/enable_borrowed_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/helper_aliases.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/iterator_t.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/sentinel_t.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/bidirectional_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/common_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/forward_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/input_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/random_access_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.refinements/subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.sized/sized_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.view/enable_view.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.view/view.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.view/view.subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.view/view_base.compile.pass.cpp

Modified: 
    libcxx/docs/OneRangesProposalStatus.csv
    libcxx/include/__ranges/concepts.h
    libcxx/include/__ranges/size.h
    libcxx/include/ranges
    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/ranges/range.access/range.prim/empty.pass.cpp
    libcxx/test/std/ranges/range.access/range.prim/size.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: 
    libcxx/test/std/ranges/range.range/enable_borrowed_range.compile.pass.cpp
    libcxx/test/std/ranges/range.range/helper_aliases.compile.pass.cpp
    libcxx/test/std/ranges/range.range/iterator_t.compile.pass.cpp
    libcxx/test/std/ranges/range.range/range.compile.pass.cpp
    libcxx/test/std/ranges/range.range/sentinel_t.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/bidirectional_range.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/common_range.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/forward_range.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/input_range.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/random_access_range.compile.pass.cpp
    libcxx/test/std/ranges/range.refinements/subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp
    libcxx/test/std/ranges/range.view/view.compile.pass.cpp
    libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp


################################################################################
diff  --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv
index b17d972757547..09af79ba98ee9 100644
--- a/libcxx/docs/OneRangesProposalStatus.csv
+++ b/libcxx/docs/OneRangesProposalStatus.csv
@@ -39,7 +39,7 @@ bidirectional_iterator: `D100278 <https://llvm.org/D100278>`_",
 [range.access],"ranges::begin, end, cbegin, cend, rbegin, rend, crbegin, and crend",[iterator.concepts],Christopher Di Bella,`D100255 <https://llvm.org/D100255>`_,
 [ranges.primitives],"size, empty, data, and cdata",[iterator.concepts],Zoe Carver,,
 [range.range],,[range.access],,,
-[range.sized],"ranges::sized_range","[range.primitives], [range.range]",Christopher Di Bella,"`D102434 <https://llvm.org/D102434>`_",
+[range.sized],"ranges::sized_range","[range.primitives], [range.range]",Christopher Di Bella,"`D102434 <https://llvm.org/D102434>`_",✅
 [range.view],View and enable_view,[range.range],Louis Dionne,https://reviews.llvm.org/D101547,✅
 [range.refinements],"OutputRange, InputRange, ForwardRange, BidirectionalRange, RandomAccessRange, ContiguousRange, CommonRange, ViewableRange","[ranges.syn]: pt. 2, [range.range]",Christopher Di Bella,"input_range: `D100271 <https://llvm.org/D100271>`_
 forward_range: `D100275 <https://llvm.org/D100275>`_

diff  --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h
index 8c28df35fefef..45dbfb5cc8a7d 100644
--- a/libcxx/include/__ranges/concepts.h
+++ b/libcxx/include/__ranges/concepts.h
@@ -6,10 +6,13 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-#ifndef _LIBCPP_RANGES_CONCEPTS_H
-#define _LIBCPP_RANGES_CONCEPTS_H
+#ifndef _LIBCPP___RANGES_CONCEPTS_H
+#define _LIBCPP___RANGES_CONCEPTS_H
 
 #include <__config>
+#include <__iterator/concepts.h>
+#include <__ranges/access.h>
+#include <__ranges/size.h>
 #include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -50,6 +53,12 @@ namespace ranges {
   template <range _Rp>
   using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<_Rp> >;
 
+  // [range.sized]
+  template <class _Tp>
+  concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
+
+  // `disable_sized_range` defined in `<__ranges/size.h>`
+
   // [range.refinements], other range refinements
   template <class _Tp>
   concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp> >;
@@ -60,12 +69,12 @@ namespace ranges {
   template <class _Tp>
   concept bidirectional_range = forward_range<_Tp> && bidirectional_iterator<iterator_t<_Tp> >;
 
-  template <class _Tp>
-  concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp> >;
-
   template <class _Tp>
   concept random_access_range =
       bidirectional_range<_Tp> && random_access_iterator<iterator_t<_Tp> >;
+
+  template <class _Tp>
+  concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp> >;
 } // namespace ranges
 
 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
@@ -76,4 +85,4 @@ _LIBCPP_END_NAMESPACE_STD
 
 _LIBCPP_POP_MACROS
 
-#endif // _LIBCPP_RANGES_CONCEPTS_H
+#endif // _LIBCPP___RANGES_CONCEPTS_H

diff  --git a/libcxx/include/__ranges/size.h b/libcxx/include/__ranges/size.h
index 555b14e0eecad..e94775407d729 100644
--- a/libcxx/include/__ranges/size.h
+++ b/libcxx/include/__ranges/size.h
@@ -26,11 +26,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if !defined(_LIBCPP_HAS_NO_RANGES)
 
+// clang-format off
+namespace ranges {
 template<class>
 inline constexpr bool disable_sized_range = false;
 
-// clang-format off
-namespace ranges {
 // [range.prim.size]
 namespace __size {
   void size(auto&) = delete;
@@ -89,8 +89,7 @@ namespace __size {
     template<__
diff erence _Tp>
     [[nodiscard]] constexpr __integer_like auto operator()(_Tp&& __t) const
         noexcept(noexcept(ranges::end(__t) - ranges::begin(__t))) {
-      return _VSTD::__to_unsigned_like<range_
diff erence_t<remove_cvref_t<_Tp>>>(
-          ranges::end(__t) - ranges::begin(__t));
+      return _VSTD::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t));
     }
   };
 } // end namespace __size

diff  --git a/libcxx/include/ranges b/libcxx/include/ranges
index 5401add0eab41..da443d77a0df6 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -50,6 +50,13 @@ namespace std::ranges {
   template<range R>
     using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
 
+  // [range.sized]
+  template<class>
+    inline constexpr bool disable_sized_range = false;
+
+  template<class T>
+    concept sized_range = ...;
+
   // [range.view], views
   template<class T>
     inline constexpr bool enable_view = ...;

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 8cf2edc0fd755..3e6f966272705 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 8113a791fb998..2c9d14ea2dea9 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 549b081d417b1..8c3f3a1fc8454 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 987d46b067ead..e0b878ea1f77e 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
@@ -26,6 +26,7 @@ static_assert(!stdr::random_access_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::bidirectional_range<range const>);
@@ -33,3 +34,4 @@ static_assert(!stdr::random_access_range<range const>);
 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>);

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 e62c086fc71b2..fe51c8fa286da 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
@@ -24,9 +24,10 @@ static_assert(!stdr::view<range>);
 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::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>);

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 22be6066546e7..3c2e6b0ff8a57 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
@@ -24,8 +24,10 @@ 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::view<range>);
+static_assert(stdr::sized_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>);

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 20d3f2bf2d5a6..6413c96468e46 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 76b73c75ec26d..ef0ea648063d1 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 57200cd92774c..da7f456014360 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
@@ -24,8 +24,10 @@ 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::view<range>);
+static_assert(stdr::sized_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>);

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 ecd13461cb574..cd8f1950464fe 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
@@ -24,8 +24,10 @@ 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::view<range>);
+static_assert(stdr::sized_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>);

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 0dadf6f4c7db1..85ecfed0d7d93 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 82828aed0aabf..386bd42f9a09a 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 5b0068e810bfe..b9b0743a2f9c0 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 b47fda8b4e2e2..38a32d1dc1700 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
@@ -25,9 +25,11 @@ static_assert(stdr::common_range<range>);
 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(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 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>);

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 b4fa79f745cec..f51b44c04ef20 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
@@ -24,8 +24,10 @@ 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::view<range>);
+static_assert(stdr::sized_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>);

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 79632d9e6ea9e..a3dd4a32b68f7 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
@@ -24,18 +24,22 @@ static_assert(std::same_as<stdr::iterator_t<fs::directory_iterator>, fs::directo
 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(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(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(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>);

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 78689946a32df..33ff8589264e2 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
@@ -24,9 +24,11 @@ static_assert(stdr::common_range<fs::path>);
 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(std::same_as<stdr::iterator_t<fs::path const>, fs::path::const_iterator>);
 static_assert(stdr::common_range<fs::path const>);
 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>);

diff  --git a/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp b/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
index e0013f67b221f..fc95c9c9f0c9a 100644
--- a/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
@@ -129,8 +129,8 @@ struct DisabledSizeRangeWithBeginEnd {
   constexpr size_t size() const { return 1; }
 };
 
-template<>
-inline constexpr bool std::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
 static_assert(!std::is_invocable_v<RangeSizeT, DisabledSizeRangeWithBeginEnd&>);
 
 struct BeginEndAndEmpty {

diff  --git a/libcxx/test/std/ranges/range.access/range.prim/size.pass.cpp b/libcxx/test/std/ranges/range.access/range.prim/size.pass.cpp
index c5ff300811f19..301a67c38aae9 100644
--- a/libcxx/test/std/ranges/range.access/range.prim/size.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/range.prim/size.pass.cpp
@@ -177,8 +177,8 @@ struct SizeMemberDisabled {
   size_t size() { return 42; }
 };
 
-template<>
-inline constexpr bool std::disable_sized_range<SizeMemberDisabled> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<SizeMemberDisabled> = true;
 
 struct ImproperlyDisabledMember {
   size_t size() const { return 42; }
@@ -186,22 +186,22 @@ struct ImproperlyDisabledMember {
 
 // Intentionally disabling "const ConstSizeMemberDisabled". This doesn't disable anything
 // because T is always uncvrefed before being checked.
-template<>
-inline constexpr bool std::disable_sized_range<const ImproperlyDisabledMember> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<const ImproperlyDisabledMember> = true;
 
 struct SizeFunctionDisabled {
   friend size_t size(SizeFunctionDisabled) { return 42; }
 };
 
-template<>
-inline constexpr bool std::disable_sized_range<SizeFunctionDisabled> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<SizeFunctionDisabled> = true;
 
 struct ImproperlyDisabledFunction {
   friend size_t size(ImproperlyDisabledFunction const&) { return 42; }
 };
 
-template<>
-inline constexpr bool std::disable_sized_range<const ImproperlyDisabledFunction> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<const ImproperlyDisabledFunction> = true;
 
 static_assert( std::is_invocable_v<RangeSizeT, ImproperlyDisabledMember&>);
 static_assert( std::is_invocable_v<RangeSizeT, const ImproperlyDisabledMember&>);
@@ -266,8 +266,8 @@ struct DisabledSizeRangeWithBeginEnd {
   constexpr size_t size() { return 1; }
 };
 
-template<>
-inline constexpr bool std::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
+template <>
+inline constexpr bool std::ranges::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
 
 struct SizeBeginAndEndMembers {
   int buff[8];

diff  --git a/libcxx/test/std/ranges/range.range/enable_borrowed_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/enable_borrowed_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/enable_borrowed_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/enable_borrowed_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.range/helper_aliases.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/helper_aliases.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/helper_aliases.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/helper_aliases.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.range/iterator_t.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/iterator_t.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/iterator_t.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/iterator_t.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.range/range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.range/sentinel_t.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/sentinel_t.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/sentinel_t.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/sentinel_t.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/bidirectional_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/bidirectional_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/bidirectional_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/bidirectional_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/common_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/common_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/common_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/common_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/forward_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/forward_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/forward_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/forward_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/input_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/input_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/input_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/input_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/random_access_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/random_access_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/random_access_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/random_access_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.refinements/subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.refinements/subsumption.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.refinements/subsumption.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.refinements/subsumption.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.req/range.sized/sized_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.sized/sized_range.compile.pass.cpp
new file mode 100644
index 0000000000000..ca03b8b6013c0
--- /dev/null
+++ b/libcxx/test/std/ranges/range.req/range.sized/sized_range.compile.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 sized_range;
+
+#include <ranges>
+
+#include "test_iterators.h"
+
+namespace stdr = std::ranges;
+
+static_assert(stdr::sized_range<int[5]>);
+static_assert(stdr::sized_range<int (&)[5]>);
+static_assert(!stdr::sized_range<int (&)[]>);
+static_assert(!stdr::sized_range<int[]>);
+
+struct range_has_size {
+  bidirectional_iterator<int*> begin();
+  bidirectional_iterator<int*> end();
+  int size();
+};
+static_assert(stdr::sized_range<range_has_size>);
+static_assert(!stdr::sized_range<range_has_size const>);
+
+struct range_has_const_size {
+  bidirectional_iterator<int*> begin();
+  bidirectional_iterator<int*> end();
+  int size() const;
+};
+static_assert(stdr::sized_range<range_has_const_size>);
+static_assert(!stdr::sized_range<range_has_const_size const>);
+
+struct const_range_has_size {
+  bidirectional_iterator<int*> begin() const;
+  bidirectional_iterator<int*> end() const;
+  int size();
+};
+static_assert(stdr::sized_range<const_range_has_size>);
+static_assert(stdr::range<const_range_has_size const>);
+static_assert(!stdr::sized_range<const_range_has_size const>);
+
+struct const_range_has_const_size {
+  bidirectional_iterator<int*> begin() const;
+  bidirectional_iterator<int*> end() const;
+  int size() const;
+};
+static_assert(stdr::sized_range<const_range_has_const_size>);
+static_assert(stdr::sized_range<const_range_has_const_size const>);
+
+struct sized_sentinel_range_has_size {
+  int* begin();
+  int* end();
+};
+static_assert(stdr::sized_range<sized_sentinel_range_has_size>);
+static_assert(!stdr::sized_range<sized_sentinel_range_has_size const>);
+
+struct const_sized_sentinel_range_has_size {
+  int* begin() const;
+  int* end() const;
+};
+static_assert(stdr::sized_range<const_sized_sentinel_range_has_size>);
+static_assert(stdr::sized_range<const_sized_sentinel_range_has_size const>);
+
+struct non_range_has_size {
+  int size() const;
+};
+static_assert(requires(non_range_has_size const x) { stdr::size(x); });
+static_assert(!stdr::sized_range<non_range_has_size>);
+static_assert(!stdr::sized_range<non_range_has_size const>);

diff  --git a/libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp
new file mode 100644
index 0000000000000..854429fbc8461
--- /dev/null
+++ b/libcxx/test/std/ranges/range.req/range.sized/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 sized_range;
+
+#include <ranges>
+
+template <std::ranges::range R>
+consteval bool check_subsumption() {
+  return false;
+}
+
+template <std::ranges::sized_range R>
+consteval bool check_subsumption() {
+  return true;
+}
+
+static_assert(check_subsumption<int[5]>());

diff  --git a/libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.view/enable_view.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.view/enable_view.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.view/view.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.view/view.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.view/view.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.view/view.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.view/view.subsumption.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.view/view.subsumption.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.view/view_base.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.view/view_base.compile.pass.cpp

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 764d79b555b1b..4b9833c8101b0 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
@@ -23,8 +23,10 @@ static_assert(std::same_as<stdr::iterator_t<std::cmatch>, std::cmatch::iterator>
 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(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>);

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 7d926acfeb74a..124a6fb4821a7 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
@@ -23,8 +23,10 @@ static_assert(std::same_as<stdr::iterator_t<std::string>, std::string::iterator>
 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(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>);

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 b30f6b4dcbf75..c36d4d04e332b 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
@@ -23,8 +23,10 @@ static_assert(std::same_as<stdr::iterator_t<std::string_view>, std::string_view:
 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(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>);
+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>);


        


More information about the libcxx-commits mailing list