[libcxx-commits] [PATCH] D119151: [libc++] Casey's P/R for LWG3664 "LWG3392 broke std::ranges::distance(a, a+3)"

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 7 09:10:11 PST 2022


Quuxplusone created this revision.
Quuxplusone added reviewers: CaseyCarter, libc++.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

This seems equivalent to what we've got today, but doesn't re-evaluate `sized_sentinel_for`, so it's arguably easier on the compiler.
Casting `int(&)[10]` to `int* const&` strikes me as "clever", but I think it //works//.

Don't merge until LWG3664 is resolved, or at least seems likely to resolve in this direction. But let's poke buildkite with this and prove that it doesn't fail any of our existing regression tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119151

Files:
  libcxx/include/__iterator/distance.h


Index: libcxx/include/__iterator/distance.h
===================================================================
--- libcxx/include/__iterator/distance.h
+++ libcxx/include/__iterator/distance.h
@@ -74,12 +74,8 @@
 
   template<class _Ip, sized_sentinel_for<decay_t<_Ip>> _Sp>
   _LIBCPP_HIDE_FROM_ABI
-  constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const {
-    if constexpr (sized_sentinel_for<_Sp, __uncvref_t<_Ip>>) {
-      return __last - __first;
-    } else {
-      return __last - decay_t<_Ip>(__first);
-    }
+  constexpr iter_difference_t<decay_t<_Ip>> operator()(_Ip&& __first, _Sp __last) const {
+    return __last - static_cast<const decay_t<_Ip>&>(__first);
   }
 
   template<range _Rp>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119151.406491.patch
Type: text/x-patch
Size: 731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220207/5f00850d/attachment.bin>


More information about the libcxx-commits mailing list