From: Christopher Di Bella Date: Thu, 13 May 2021 19:34:06 +0000 (+0000) Subject: [libcxx][ranges] adds concept `sized_range` and cleans up `ranges::size` X-Git-Tag: llvmorg-14-init~6164 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8fad6614923eea684f736e7d22fe54d5393f13f;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv index b17d972..09af79b 100644 --- a/libcxx/docs/OneRangesProposalStatus.csv +++ b/libcxx/docs/OneRangesProposalStatus.csv @@ -39,7 +39,7 @@ bidirectional_iterator: `D100278 `_", [range.access],"ranges::begin, end, cbegin, cend, rbegin, rend, crbegin, and crend",[iterator.concepts],Christopher Di Bella,`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 `_", +[range.sized],"ranges::sized_range","[range.primitives], [range.range]",Christopher Di Bella,"`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 `_ forward_range: `D100275 `_ diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h index 8c28df3..45dbfb5 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 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -50,6 +53,12 @@ namespace ranges { template using range_rvalue_reference_t = iter_rvalue_reference_t >; + // [range.sized] + template + 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 concept input_range = range<_Tp> && input_iterator >; @@ -61,11 +70,11 @@ namespace ranges { concept bidirectional_range = forward_range<_Tp> && bidirectional_iterator >; template - concept common_range = range<_Tp> && same_as, sentinel_t<_Tp> >; - - template concept random_access_range = bidirectional_range<_Tp> && random_access_iterator >; + + template + concept common_range = range<_Tp> && same_as, 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 555b14e..e947754 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 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<__difference _Tp> [[nodiscard]] constexpr __integer_like auto operator()(_Tp&& __t) const noexcept(noexcept(ranges::end(__t) - ranges::begin(__t))) { - return _VSTD::__to_unsigned_like>>( - 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 5401add..da443d7 100644 --- a/libcxx/include/ranges +++ b/libcxx/include/ranges @@ -50,6 +50,13 @@ namespace std::ranges { template using range_rvalue_reference_t = iter_rvalue_reference_t>; + // [range.sized] + template + inline constexpr bool disable_sized_range = false; + + template + concept sized_range = ...; + // [range.view], views template 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 8cf2edc..3e6f966 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); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); 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 8113a79..2c9d14e 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); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); 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 549b081..8c3f3a1 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); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); 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 987d46b..e0b878e 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); static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::bidirectional_range); @@ -33,3 +34,4 @@ static_assert(!stdr::random_access_range); static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 e62c086..fe51c8f 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); static_assert(std::same_as, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); - +static_assert(stdr::sized_range); static_assert(!stdr::view); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); +static_assert(stdr::sized_range); 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 22be606..3c2e6b0 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 20d3f2b..6413c96 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); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); static_assert(!stdr::view); +static_assert(!stdr::sized_range); 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); +static_assert(!stdr::sized_range); 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 76b73c7..ef0ea64 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); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(stdr::sized_range); 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 57200cd..da7f456 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 ecd1346..cd8f195 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, range::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 0dadf6f..85ecfed 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); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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); +static_assert(stdr::sized_range); 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 82828ae..386bd42 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); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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); +static_assert(stdr::sized_range); 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 5b0068e..b9b0743 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); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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); +static_assert(stdr::sized_range); 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 b47fda8..38a32d1 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); static_assert(stdr::forward_range); static_assert(!stdr::bidirectional_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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); +static_assert(stdr::sized_range); 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 b4fa79f..f51b44c 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, range::iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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::sized_range); 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 79632d9..a3dd4a3 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, fs::directo static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(!stdr::sized_range); static_assert(std::same_as, fs::directory_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(!stdr::sized_range); static_assert(std::same_as, fs::recursive_directory_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(!stdr::sized_range); static_assert(std::same_as, fs::recursive_directory_iterator>); static_assert(stdr::common_range); static_assert(stdr::input_range); static_assert(!stdr::view); +static_assert(!stdr::sized_range); 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 7868994..33ff858 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); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(!stdr::sized_range); static_assert(std::same_as, fs::path::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::bidirectional_range); static_assert(!stdr::view); static_assert(!stdr::random_access_range); +static_assert(!stdr::sized_range); 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 e0013f6..fc95c9c9 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 = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = true; static_assert(!std::is_invocable_v); 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 c5ff300..301a67c 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 = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = 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 = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = true; struct SizeFunctionDisabled { friend size_t size(SizeFunctionDisabled) { return 42; } }; -template<> -inline constexpr bool std::disable_sized_range = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = true; struct ImproperlyDisabledFunction { friend size_t size(ImproperlyDisabledFunction const&) { return 42; } }; -template<> -inline constexpr bool std::disable_sized_range = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = true; static_assert( std::is_invocable_v); static_assert( std::is_invocable_v); @@ -266,8 +266,8 @@ struct DisabledSizeRangeWithBeginEnd { constexpr size_t size() { return 1; } }; -template<> -inline constexpr bool std::disable_sized_range = true; +template <> +inline constexpr bool std::ranges::disable_sized_range = 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 0000000..ca03b8b --- /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 +// concept sized_range; + +#include + +#include "test_iterators.h" + +namespace stdr = std::ranges; + +static_assert(stdr::sized_range); +static_assert(stdr::sized_range); +static_assert(!stdr::sized_range); +static_assert(!stdr::sized_range); + +struct range_has_size { + bidirectional_iterator begin(); + bidirectional_iterator end(); + int size(); +}; +static_assert(stdr::sized_range); +static_assert(!stdr::sized_range); + +struct range_has_const_size { + bidirectional_iterator begin(); + bidirectional_iterator end(); + int size() const; +}; +static_assert(stdr::sized_range); +static_assert(!stdr::sized_range); + +struct const_range_has_size { + bidirectional_iterator begin() const; + bidirectional_iterator end() const; + int size(); +}; +static_assert(stdr::sized_range); +static_assert(stdr::range); +static_assert(!stdr::sized_range); + +struct const_range_has_const_size { + bidirectional_iterator begin() const; + bidirectional_iterator end() const; + int size() const; +}; +static_assert(stdr::sized_range); +static_assert(stdr::sized_range); + +struct sized_sentinel_range_has_size { + int* begin(); + int* end(); +}; +static_assert(stdr::sized_range); +static_assert(!stdr::sized_range); + +struct const_sized_sentinel_range_has_size { + int* begin() const; + int* end() const; +}; +static_assert(stdr::sized_range); +static_assert(stdr::sized_range); + +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); +static_assert(!stdr::sized_range); 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 0000000..854429f --- /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 +// concept sized_range; + +#include + +template +consteval bool check_subsumption() { + return false; +} + +template +consteval bool check_subsumption() { + return true; +} + +static_assert(check_subsumption()); 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 764d79b..4b9833c 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, std::cmatch::iterator> static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, std::cmatch::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 7d926ac..124a6fb 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, std::string::iterator> static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); static_assert(std::same_as, std::string::const_iterator>); static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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 b30f6b4..c36d4d0 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, std::string_view: static_assert(stdr::common_range); static_assert(stdr::random_access_range); static_assert(!stdr::view); +static_assert(stdr::sized_range); 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); // FIXME: string_view needs to be patched so this is true +static_assert(stdr::sized_range);