diff --git a/libcxx/docs/Cxx2aStatusIssuesStatus.csv b/libcxx/docs/Cxx2aStatusIssuesStatus.csv --- a/libcxx/docs/Cxx2aStatusIssuesStatus.csv +++ b/libcxx/docs/Cxx2aStatusIssuesStatus.csv @@ -246,7 +246,7 @@ "`3323 `__","``*has-tuple-element*``\ helper concept needs ``convertible_to``\ ","Prague","","" "`3324 `__","Special-case ``std::strong/weak/partial_order``\ for pointers","Prague","","" "`3325 `__","Constrain return type of transformation function for ``transform_view``\ ","Prague","","" -"`3326 `__","``enable_view``\ has false positives","Prague","","" +"`3326 `__","``enable_view``\ has false positives","Prague","|In progress|","" "`3327 `__","Format alignment specifiers vs. text direction","Prague","","" "`3328 `__","Clarify that ``std::string``\ is not good for UTF-8","Prague","","" "`3329 `__","``totally_ordered_with``\ both directly and indirectly requires ``common_reference_with``\ ","Prague","|Complete|","13.0" diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h --- a/libcxx/include/__ranges/concepts.h +++ b/libcxx/include/__ranges/concepts.h @@ -10,6 +10,9 @@ #define _LIBCPP_RANGES_CONCEPTS_H #include <__config> +#include <__iterator/concepts.h> +#include <__ranges/access.h> +#include <__ranges/view.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -50,6 +53,18 @@ template using range_rvalue_reference_t = iter_rvalue_reference_t >; + // [range.view], views + + // `enable_view` defined in <__ranges/view.h> + // `view_base` defined in <__ranges/view.h> + + template + concept view = + range<_Tp> && + movable<_Tp> && + default_initializable<_Tp> && + enable_view<_Tp>; + // [range.refinements], other range refinements template concept input_range = range<_Tp> && input_iterator >; diff --git a/libcxx/include/__ranges/view.h b/libcxx/include/__ranges/view.h --- a/libcxx/include/__ranges/view.h +++ b/libcxx/include/__ranges/view.h @@ -11,7 +11,6 @@ #define _LIBCPP___RANGES_VIEW_H #include <__config> -#include <__ranges/concepts.h> #include @@ -33,13 +32,6 @@ 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 diff --git a/libcxx/include/span b/libcxx/include/span --- a/libcxx/include/span +++ b/libcxx/include/span @@ -22,6 +22,10 @@ template class span; +template + inline constexpr bool ranges::enable_view> = Extent == 0 || + Extent == dynamic_extent; + template inline constexpr bool ranges::enable_borrowed_range> = true; @@ -126,6 +130,7 @@ #include <__config> #include <__ranges/enable_borrowed_range.h> +#include <__ranges/view.h> #include // for array #include // for byte #include // for iterators @@ -528,6 +533,9 @@ }; #if !defined(_LIBCPP_HAS_NO_RANGES) +template +inline constexpr bool ranges::enable_view> = _Extent == 0 || _Extent == dynamic_extent; + template inline constexpr bool ranges::enable_borrowed_range > = true; #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -19,6 +19,9 @@ template> class basic_string_view; + template + inline constexpr bool ranges::enable_view> = true; + template inline constexpr bool ranges::enable_borrowed_range> = true; // C++20 @@ -183,6 +186,7 @@ #include <__config> #include <__ranges/enable_borrowed_range.h> +#include <__ranges/view.h> #include <__string> #include #include @@ -654,6 +658,9 @@ }; #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) +template +inline constexpr bool ranges::enable_view> = true; + template inline constexpr bool ranges::enable_borrowed_range > = true; #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) 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 --- 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,9 +23,9 @@ static_assert(std::same_as, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); -static_assert(!stdr::view); +static_assert(stdr::view && stdr::enable_view); static_assert(std::same_as, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); -static_assert(!stdr::view); +static_assert(!stdr::view && !stdr::enable_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 --- 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,9 +22,9 @@ static_assert(std::same_as, std::string_view::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); -static_assert(!stdr::view); +static_assert(stdr::view && stdr::enable_view); static_assert(std::same_as, std::string_view::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); -static_assert(!stdr::view); +static_assert(!stdr::view && !stdr::enable_view);