[libcxx-commits] [libcxx] c45f382 - Implement LWG-3646 std::ranges::view_interface::size returns a signed type
Igor Zhukov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 15 16:14:28 PST 2022
Author: Igor Zhukov
Date: 2022-12-16T07:14:00+07:00
New Revision: c45f382a12fc8ccc7324baad121ba5d262aab214
URL: https://github.com/llvm/llvm-project/commit/c45f382a12fc8ccc7324baad121ba5d262aab214
DIFF: https://github.com/llvm/llvm-project/commit/c45f382a12fc8ccc7324baad121ba5d262aab214.diff
LOG: Implement LWG-3646 std::ranges::view_interface::size returns a signed type
Reviewed By: Mordante, philnik, #libc
Differential Revision: https://reviews.llvm.org/D139791
Added:
Modified:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__ranges/view_interface.h
libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 756c6869fed24..c648938ac397d 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -186,6 +186,8 @@
"`3721 <https://wg21.link/LWG3721>`__","Allow an ``arg-id`` with a value of zero for ``width`` in ``std-format-spec``","July 2022","|Complete|","16.0","|format|"
"`3724 <https://wg21.link/LWG3724>`__","``decay-copy`` should be constrained","July 2022","|Complete|","14.0"
"","","","",""
+"`3646 <https://wg21.link/LWG3646>`__","``std::ranges::view_interface::size`` returns a signed type","November 2022","|Complete|","16.0"
+"","","","",""
"`3629 <https://wg21.link/LWG3629>`__","``make_error_code`` and ``make_error_condition`` are customization points","Not voted in","|Complete|","16.0",""
"`3631 <https://wg21.link/LWG3631>`__","``basic_format_arg(T&&)`` should use ``remove_cvref_t<T>`` throughout","Not voted in","|Complete|","15.0",""
"`3645 <https://wg21.link/LWG3645>`__","``resize_and_overwrite`` is overspecified to call its callback with lvalues","Not voted in","|Complete|","14.0",""
diff --git a/libcxx/include/__ranges/view_interface.h b/libcxx/include/__ranges/view_interface.h
index b89ee999f8cc9..b706c8d2580a5 100644
--- a/libcxx/include/__ranges/view_interface.h
+++ b/libcxx/include/__ranges/view_interface.h
@@ -100,7 +100,7 @@ class view_interface {
constexpr auto size()
requires forward_range<_D2> && sized_sentinel_for<sentinel_t<_D2>, iterator_t<_D2>>
{
- return ranges::end(__derived()) - ranges::begin(__derived());
+ return std::__to_unsigned_like(ranges::end(__derived()) - ranges::begin(__derived()));
}
template<class _D2 = _Derived>
@@ -108,7 +108,7 @@ class view_interface {
constexpr auto size() const
requires forward_range<const _D2> && sized_sentinel_for<sentinel_t<const _D2>, iterator_t<const _D2>>
{
- return ranges::end(__derived()) - ranges::begin(__derived());
+ return std::__to_unsigned_like(ranges::end(__derived()) - ranges::begin(__derived()));
}
template<class _D2 = _Derived>
diff --git a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
index 2c1c504a00170..830f3f77c29ec 100644
--- a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
@@ -233,12 +233,18 @@ constexpr bool testSize() {
static_assert(!SizeInvocable<NotSizedSentinel>);
static_assert( SizeInvocable<ForwardRange>);
+ using SignedSize = std::common_type_t<std::ptr
diff _t, std::make_signed_t<std::size_t>>;
ForwardRange forwardRange;
assert(forwardRange.size() == 8);
assert(static_cast<ForwardRange const&>(forwardRange).size() == 8);
assert(std::ranges::size(forwardRange) == 8);
+ static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange>())), std::size_t>);
+ static_assert(std::same_as<decltype(std::ranges::ssize(std::declval<ForwardRange>())), SignedSize>);
+
assert(std::ranges::size(static_cast<ForwardRange const&>(forwardRange)) == 8);
+ static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange const>())), std::size_t>);
+ static_assert(std::same_as<decltype(std::ranges::ssize(std::declval<ForwardRange const>())), SignedSize>);
SizeIsTen sizeTen;
assert(sizeTen.size() == 10);
More information about the libcxx-commits
mailing list