[libcxx-commits] [libcxx] 2021d27 - [libc++] Implement ranges::view

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 4 08:06:01 PDT 2021


Author: Louis Dionne
Date: 2021-05-04T11:05:58-04:00
New Revision: 2021d272ad6c49e63deeb2314c8553da335284f6

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

LOG: [libc++] Implement ranges::view

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

Added: 
    libcxx/include/__ranges/view.h
    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

Modified: 
    libcxx/docs/OneRangesProposalStatus.csv
    libcxx/include/CMakeLists.txt
    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/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/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv
index 7a78472469ead..ed8d31ca42710 100644
--- a/libcxx/docs/OneRangesProposalStatus.csv
+++ b/libcxx/docs/OneRangesProposalStatus.csv
@@ -40,7 +40,7 @@ bidirectional_iterator: `D100278 <https://llvm.org/D100278>`_",
 [ranges.primitives],"size, empty, data, and cdata",[iterator.concepts],Zoe Carver,,
 [range.range],,[range.access],,,
 [range.sized],,"[range.primitives], [range.range]",,,
-[range.view],View and enable_view,[range.range],,,
+[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>`_
 bidirectional_range: `D100278 <https://llvm.org/D100278>`_",

diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 79981c59b8706..953c17610dcb6 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -38,6 +38,7 @@ set(files
   __ranges/access.h
   __ranges/concepts.h
   __ranges/enable_borrowed_range.h
+  __ranges/view.h
   __split_buffer
   __sso_allocator
   __std_stream

diff  --git a/libcxx/include/__ranges/view.h b/libcxx/include/__ranges/view.h
new file mode 100644
index 0000000000000..11c0ae2db072d
--- /dev/null
+++ b/libcxx/include/__ranges/view.h
@@ -0,0 +1,51 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___RANGES_VIEW_H
+#define _LIBCPP___RANGES_VIEW_H
+
+#include <__config>
+#include <__ranges/concepts.h>
+#include <concepts>
+
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_RANGES)
+
+namespace ranges {
+
+struct view_base { };
+
+template <class _Tp>
+inline constexpr bool enable_view = derived_from<_Tp, view_base>;
+
+template <class _Tp>
+concept view =
+  range<_Tp> &&
+  movable<_Tp> &&
+  default_initializable<_Tp> &&
+  enable_view<_Tp>;
+
+} // end namespace ranges
+
+#endif // !_LIBCPP_HAS_NO_RANGES
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANGES_VIEW_H

diff  --git a/libcxx/include/ranges b/libcxx/include/ranges
index 0328360b4ffe3..b74064ce34708 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -47,6 +47,15 @@ namespace std::ranges {
   template<range R>
     using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
 
+  // [range.view], views
+  template<class T>
+    inline constexpr bool enable_view = ...;
+
+  struct view_base { };
+
+  template<class T>
+    concept view = ...;
+
   // [range.refinements], other range refinements
   template<class T>
     concept input_range = see below;
@@ -67,6 +76,7 @@ namespace std::ranges {
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
 #include <__ranges/enable_borrowed_range.h>
+#include <__ranges/view.h>
 #include <compare>          // Required by the standard.
 #include <initializer_list> // Required by the standard.
 #include <iterator>         // Required by the standard.

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 2995a5256c649..cd2b299816c6d 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 f9d28d48813f2..46975cde7300e 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 d35995a91be03..40db2fe172e89 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 ec044081e22ab..30bae62187dd2 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::input_range<range>);
+static_assert(!stdr::view<range>);
 
 static_assert(std::same_as<stdr::iterator_t<range const>, range::const_iterator>);
 static_assert(stdr::common_range<range const>);
 static_assert(stdr::input_range<range>);
+static_assert(!stdr::view<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 02ea3ca87ece2..7794dfe1f58f2 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 ce8f709e66a2c..bece15281b4fd 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 a5a73a9e0a9b2..20d3f2bf2d5a6 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
@@ -24,8 +24,10 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 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(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>);

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 404d424d31f03..19966094b7004 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 0ed3618797652..b6f3268cbcd01 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 880f5bd5195e0..50620b2cc7ba2 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<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>);

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 dd50b31c4f24d..0dadf6f4c7db1 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
@@ -24,8 +24,10 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 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(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>);

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 0a6a10f1bb833..82828aed0aabf 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
@@ -24,8 +24,10 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 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(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>);

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 b244fce256fdb..5b0068e810bfe 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
@@ -24,8 +24,10 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 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(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>);

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 ab72da83b5432..b47fda8b4e2e2 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
@@ -24,8 +24,10 @@ static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 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(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>);

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 9234639dcf184..d0c4663e1187b 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
@@ -23,7 +23,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<range>, range::iterator>);
 static_assert(stdr::common_range<range>);
 static_assert(stdr::bidirectional_range<range>);
+static_assert(!stdr::view<range>);
 
 static_assert(std::same_as<stdr::iterator_t<range const>, range::iterator>);
 static_assert(stdr::common_range<range const>);
 static_assert(stdr::bidirectional_range<range const>);
+static_assert(!stdr::view<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 8b80681aa377c..79632d9e6ea9e 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
@@ -23,15 +23,19 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<fs::directory_iterator>, fs::directory_iterator>);
 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(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(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::directory_iterator>);
+static_assert(stdr::input_range<fs::recursive_directory_iterator>);
+static_assert(!stdr::view<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::directory_iterator const>);
+static_assert(stdr::input_range<fs::recursive_directory_iterator const>);
+static_assert(!stdr::view<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 281679c6dfda6..31a7070f64e6e 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
@@ -22,7 +22,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<fs::path>, fs::path::iterator>);
 static_assert(stdr::common_range<fs::path>);
 static_assert(stdr::bidirectional_range<fs::path>);
+static_assert(!stdr::view<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>);

diff  --git a/libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp b/libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp
new file mode 100644
index 0000000000000..2f7baab3fe2c9
--- /dev/null
+++ b/libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <ranges>
+
+// template<class T>
+// inline constexpr bool enable_view = ...;
+
+#include <ranges>
+
+#include "test_macros.h"
+
+// Doesn't derive from view_base
+struct Empty { };
+static_assert(!std::ranges::enable_view<Empty>);
+
+// Derives from view_base, but privately
+struct PrivateViewBase : private std::ranges::view_base { };
+static_assert(!std::ranges::enable_view<PrivateViewBase>);
+
+// Derives from view_base, but specializes enable_view to false
+struct EnableViewFalse : std::ranges::view_base { };
+namespace std::ranges { template <> constexpr bool enable_view<EnableViewFalse> = false; }
+static_assert(!std::ranges::enable_view<EnableViewFalse>);
+
+
+// Derives from view_base
+struct PublicViewBase : std::ranges::view_base { };
+static_assert(std::ranges::enable_view<PublicViewBase>);
+
+// Does not derive from view_base, but specializes enable_view to true
+struct EnableViewTrue { };
+namespace std::ranges { template <> constexpr bool enable_view<EnableViewTrue> = true; }
+static_assert(std::ranges::enable_view<EnableViewTrue>);
+
+
+// Make sure that enable_view is a bool, not some other contextually-convertible-to-bool type.
+ASSERT_SAME_TYPE(decltype(std::ranges::enable_view<Empty>), const bool);
+ASSERT_SAME_TYPE(decltype(std::ranges::enable_view<PublicViewBase>), const bool);

diff  --git a/libcxx/test/std/ranges/range.view/view.compile.pass.cpp b/libcxx/test/std/ranges/range.view/view.compile.pass.cpp
new file mode 100644
index 0000000000000..04e696d38822d
--- /dev/null
+++ b/libcxx/test/std/ranges/range.view/view.compile.pass.cpp
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <ranges>
+
+// template<class T>
+// concept view = ...;
+
+#include <ranges>
+
+#include "test_macros.h"
+
+// The type would be a view, but it's not moveable.
+struct NotMoveable : std::ranges::view_base {
+  NotMoveable() = default;
+  NotMoveable(NotMoveable&&) = delete;
+  NotMoveable& operator=(NotMoveable&&) = delete;
+  friend int* begin(NotMoveable&);
+  friend int* begin(NotMoveable const&);
+  friend int* end(NotMoveable&);
+  friend int* end(NotMoveable const&);
+};
+static_assert(std::ranges::range<NotMoveable>);
+static_assert(!std::movable<NotMoveable>);
+static_assert(std::default_initializable<NotMoveable>);
+static_assert(std::ranges::enable_view<NotMoveable>);
+static_assert(!std::ranges::view<NotMoveable>);
+
+// The type would be a view, but it's not default initializable
+struct NotDefaultInit : std::ranges::view_base {
+  NotDefaultInit() = delete;
+  friend int* begin(NotDefaultInit&);
+  friend int* begin(NotDefaultInit const&);
+  friend int* end(NotDefaultInit&);
+  friend int* end(NotDefaultInit const&);
+};
+static_assert(std::ranges::range<NotDefaultInit>);
+static_assert(std::movable<NotDefaultInit>);
+static_assert(!std::default_initializable<NotDefaultInit>);
+static_assert(std::ranges::enable_view<NotDefaultInit>);
+static_assert(!std::ranges::view<NotDefaultInit>);
+
+// The type would be a view, but it doesn't enable it with enable_view
+struct NotExplicitlyEnabled {
+  NotExplicitlyEnabled() = default;
+  NotExplicitlyEnabled(NotExplicitlyEnabled&&) = default;
+  NotExplicitlyEnabled& operator=(NotExplicitlyEnabled&&) = default;
+  friend int* begin(NotExplicitlyEnabled&);
+  friend int* begin(NotExplicitlyEnabled const&);
+  friend int* end(NotExplicitlyEnabled&);
+  friend int* end(NotExplicitlyEnabled const&);
+};
+static_assert(std::ranges::range<NotExplicitlyEnabled>);
+static_assert(std::movable<NotExplicitlyEnabled>);
+static_assert(std::default_initializable<NotExplicitlyEnabled>);
+static_assert(!std::ranges::enable_view<NotExplicitlyEnabled>);
+static_assert(!std::ranges::view<NotExplicitlyEnabled>);
+
+// The type has everything else, but it's not a range
+struct NotARange : std::ranges::view_base {
+  NotARange() = default;
+  NotARange(NotARange&&) = default;
+  NotARange& operator=(NotARange&&) = default;
+};
+static_assert(!std::ranges::range<NotARange>);
+static_assert(std::movable<NotARange>);
+static_assert(std::default_initializable<NotARange>);
+static_assert(std::ranges::enable_view<NotARange>);
+static_assert(!std::ranges::view<NotARange>);
+
+// The type satisfies all requirements
+struct View : std::ranges::view_base {
+  View() = default;
+  View(View&&) = default;
+  View& operator=(View&&) = default;
+  friend int* begin(View&);
+  friend int* begin(View const&);
+  friend int* end(View&);
+  friend int* end(View const&);
+};
+static_assert(std::ranges::range<View>);
+static_assert(std::movable<View>);
+static_assert(std::default_initializable<View>);
+static_assert(std::ranges::enable_view<View>);
+static_assert(std::ranges::view<View>);

diff  --git a/libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp
new file mode 100644
index 0000000000000..cff99a19c08eb
--- /dev/null
+++ b/libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <ranges>
+
+// template<class T>
+// concept view = ...;
+
+#include <ranges>
+
+#include "test_macros.h"
+
+struct View : std::ranges::view_base {
+  View() = default;
+  View(View&&) = default;
+  View& operator=(View&&) = default;
+  friend int* begin(View&);
+  friend int* begin(View const&);
+  friend int* end(View&);
+  friend int* end(View const&);
+};
+
+namespace subsume_range {
+  template <std::ranges::view>
+  constexpr bool test() { return true; }
+  template <std::ranges::range>
+  constexpr bool test() { return false; }
+  static_assert(test<View>());
+}
+
+namespace subsume_movable {
+  template <std::ranges::view>
+  constexpr bool test() { return true; }
+  template <std::movable>
+  constexpr bool test() { return false; }
+  static_assert(test<View>());
+}
+
+namespace subsume_default_initializable {
+  template <std::ranges::view>
+  constexpr bool test() { return true; }
+  template <std::default_initializable>
+  constexpr bool test() { return false; }
+  static_assert(test<View>());
+}

diff  --git a/libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp b/libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp
new file mode 100644
index 0000000000000..94a996d1e9e0b
--- /dev/null
+++ b/libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <ranges>
+
+// struct view_base { };
+
+#include <ranges>
+#include <type_traits>
+
+static_assert(std::is_empty_v<std::ranges::view_base>);
+static_assert(std::is_trivial_v<std::ranges::view_base>);
+
+// Make sure we can inherit from it, as it's intended (that wouldn't be the
+// case if e.g. it was marked as final).
+struct View : std::ranges::view_base { };

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 2a6f17749b89d..044acfceb9153 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
@@ -22,7 +22,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<std::cmatch>, std::cmatch::iterator>);
 static_assert(stdr::common_range<std::cmatch>);
 static_assert(stdr::bidirectional_range<std::cmatch>);
+static_assert(!stdr::view<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::bidirectional_range<std::cmatch const>);
+static_assert(!stdr::view<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 7fd0eff2b6646..46b26bcd143d9 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
@@ -22,7 +22,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<std::string>, std::string::iterator>);
 static_assert(stdr::common_range<std::string>);
 static_assert(stdr::bidirectional_range<std::string>);
+static_assert(!stdr::view<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::bidirectional_range<std::string const>);
+static_assert(!stdr::view<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 21bd14e59ba8b..8f9da5ac99ff6 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
@@ -22,7 +22,9 @@ namespace stdr = std::ranges;
 static_assert(std::same_as<stdr::iterator_t<std::string_view>, std::string_view::iterator>);
 static_assert(stdr::common_range<std::string_view>);
 static_assert(stdr::bidirectional_range<std::string_view>);
+static_assert(!stdr::view<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::bidirectional_range<std::string_view const>);
+static_assert(!stdr::view<std::string_view const>);


        


More information about the libcxx-commits mailing list