diff --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv --- a/libcxx/docs/OneRangesProposalStatus.csv +++ b/libcxx/docs/OneRangesProposalStatus.csv @@ -39,7 +39,7 @@ [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 --- 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 @@ 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 >; @@ -60,12 +69,12 @@ template 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_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 --- a/libcxx/include/__ranges/size.h +++ b/libcxx/include/__ranges/size.h @@ -26,11 +26,11 @@ #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 @@ 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 --- a/libcxx/include/ranges +++ b/libcxx/include/ranges @@ -50,6 +50,13 @@ 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 --- 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::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 --- 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::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 --- 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::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 --- 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::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::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 --- 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(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 --- 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(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 --- 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::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 --- 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::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 --- 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(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 --- 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(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 --- 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::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 --- 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::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 --- 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::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 --- 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::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 --- 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(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 --- 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(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 --- 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::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 --- 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 @@ 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 --- 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 @@ 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 @@ // 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 @@ 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 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 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 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 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 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 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 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 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 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 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 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 --- /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.view/view_base.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp rename from libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp rename to libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp --- a/libcxx/test/std/ranges/range.view/view_base.compile.pass.cpp +++ b/libcxx/test/std/ranges/range.req/range.sized/subsumption.compile.pass.cpp @@ -8,17 +8,21 @@ // UNSUPPORTED: c++03, c++11, c++14, c++17 // UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 -// - -// struct view_base { }; +// template +// concept sized_range; #include -#include -static_assert(std::is_empty_v); -static_assert(std::is_trivial_v); +template +consteval bool check_subsumption() { + return false; +} + +template +consteval bool check_subsumption() { + return true; +} -// 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 { }; +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 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 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 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 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 --- 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(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 --- 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(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 --- 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(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);