From 2021d272ad6c49e63deeb2314c8553da335284f6 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 28 Apr 2021 15:22:11 -0400 Subject: [PATCH] [libc++] Implement ranges::view Differential Revision: https://reviews.llvm.org/D101547 --- libcxx/docs/OneRangesProposalStatus.csv | 2 +- libcxx/include/CMakeLists.txt | 1 + libcxx/include/__ranges/view.h | 51 ++++++++++++ libcxx/include/ranges | 10 +++ .../map/range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../set/range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 8 +- .../range_concept_conformance.compile.pass.cpp | 2 + .../ranges/range.view/enable_view.compile.pass.cpp | 47 +++++++++++ .../std/ranges/range.view/view.compile.pass.cpp | 93 ++++++++++++++++++++++ .../range.view/view.subsumption.compile.pass.cpp | 53 ++++++++++++ .../ranges/range.view/view_base.compile.pass.cpp | 24 ++++++ .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + .../range_concept_conformance.compile.pass.cpp | 2 + 28 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 libcxx/include/__ranges/view.h create mode 100644 libcxx/test/std/ranges/range.view/enable_view.compile.pass.cpp create mode 100644 libcxx/test/std/ranges/range.view/view.compile.pass.cpp create mode 100644 libcxx/test/std/ranges/range.view/view.subsumption.compile.pass.cpp create mode 100644 libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp diff --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv index 7a78472..ed8d31c 100644 --- a/libcxx/docs/OneRangesProposalStatus.csv +++ b/libcxx/docs/OneRangesProposalStatus.csv @@ -40,7 +40,7 @@ bidirectional_iterator: `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 `_ forward_range: `D100275 `_ bidirectional_range: `D100278 `_", diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index 79981c5..953c176 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 0000000..11c0ae2 --- /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 + + +#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 +inline constexpr bool enable_view = derived_from<_Tp, view_base>; + +template +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 0328360..b74064c 100644 --- a/libcxx/include/ranges +++ b/libcxx/include/ranges @@ -47,6 +47,15 @@ namespace std::ranges { template using range_rvalue_reference_t = iter_rvalue_reference_t>; + // [range.view], views + template + inline constexpr bool enable_view = ...; + + struct view_base { }; + + template + concept view = ...; + // [range.refinements], other range refinements template 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 // Required by the standard. #include // Required by the standard. #include // 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 2995a52..cd2b299 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 f9d28d4..46975cd 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 d35995a..40db2fe 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 ec04408..30bae62 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); +static_assert(!stdr::view); 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 02ea3ca..7794dfe 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 ce8f709..bece152 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 a5a73a9..20d3f2b 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); 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 404d424..1996609 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 0ed3618..b6f3268 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 880f5bd..50620b2 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 dd50b31..0dadf6f 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); 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 0a6a10f..82828ae 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); 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 b244fce..5b0068e 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); 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 ab72da8..b47fda8 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); +static_assert(!stdr::view); 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 9234639..d0c4663 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 8b80681..79632d9 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, fs::directory_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); +static_assert(!stdr::view); static_assert(std::same_as, fs::directory_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); +static_assert(!stdr::view); static_assert(std::same_as, fs::recursive_directory_iterator>); static_assert(stdr::common_range); -static_assert(stdr::input_range); +static_assert(stdr::input_range); +static_assert(!stdr::view); static_assert(std::same_as, fs::recursive_directory_iterator>); static_assert(stdr::common_range); -static_assert(stdr::input_range); +static_assert(stdr::input_range); +static_assert(!stdr::view); 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 281679c..31a7070 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, fs::path::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, fs::path::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 0000000..2f7baab --- /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 + +// + +// template +// inline constexpr bool enable_view = ...; + +#include + +#include "test_macros.h" + +// Doesn't derive from view_base +struct Empty { }; +static_assert(!std::ranges::enable_view); + +// Derives from view_base, but privately +struct PrivateViewBase : private std::ranges::view_base { }; +static_assert(!std::ranges::enable_view); + +// Derives from view_base, but specializes enable_view to false +struct EnableViewFalse : std::ranges::view_base { }; +namespace std::ranges { template <> constexpr bool enable_view = false; } +static_assert(!std::ranges::enable_view); + + +// Derives from view_base +struct PublicViewBase : std::ranges::view_base { }; +static_assert(std::ranges::enable_view); + +// Does not derive from view_base, but specializes enable_view to true +struct EnableViewTrue { }; +namespace std::ranges { template <> constexpr bool enable_view = true; } +static_assert(std::ranges::enable_view); + + +// Make sure that enable_view is a bool, not some other contextually-convertible-to-bool type. +ASSERT_SAME_TYPE(decltype(std::ranges::enable_view), const bool); +ASSERT_SAME_TYPE(decltype(std::ranges::enable_view), 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 0000000..04e696d --- /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 + +// + +// template +// concept view = ...; + +#include + +#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); +static_assert(!std::movable); +static_assert(std::default_initializable); +static_assert(std::ranges::enable_view); +static_assert(!std::ranges::view); + +// 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); +static_assert(std::movable); +static_assert(!std::default_initializable); +static_assert(std::ranges::enable_view); +static_assert(!std::ranges::view); + +// 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); +static_assert(std::movable); +static_assert(std::default_initializable); +static_assert(!std::ranges::enable_view); +static_assert(!std::ranges::view); + +// 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); +static_assert(std::movable); +static_assert(std::default_initializable); +static_assert(std::ranges::enable_view); +static_assert(!std::ranges::view); + +// 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); +static_assert(std::movable); +static_assert(std::default_initializable); +static_assert(std::ranges::enable_view); +static_assert(std::ranges::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 0000000..cff99a1 --- /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 + +// + +// template +// concept view = ...; + +#include + +#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 + constexpr bool test() { return true; } + template + constexpr bool test() { return false; } + static_assert(test()); +} + +namespace subsume_movable { + template + constexpr bool test() { return true; } + template + constexpr bool test() { return false; } + static_assert(test()); +} + +namespace subsume_default_initializable { + template + constexpr bool test() { return true; } + template + constexpr bool test() { return false; } + static_assert(test()); +} 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 0000000..94a996d --- /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 + +// + +// struct view_base { }; + +#include +#include + +static_assert(std::is_empty_v); +static_assert(std::is_trivial_v); + +// 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 2a6f177..044acfc 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, std::cmatch::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, std::cmatch::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 7fd0eff..46b26bc 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, std::string::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, std::string::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); 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 21bd14e..8f9da5a 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, std::string_view::iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); static_assert(std::same_as, std::string_view::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); +static_assert(!stdr::view); -- 2.7.4