[libcxx-commits] [libcxx] [libc++] optimization on ranges::drop_view::begin (#72883) (PR #72929)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 22 11:29:40 PST 2023


================
@@ -90,6 +90,10 @@ namespace ranges {
       requires (!(__simple_view<_View> &&
                   random_access_range<const _View> && sized_range<const _View>))
     {
+      if constexpr (random_access_range<_View> && sized_range<_View>) {
+        range_difference_t<_View> __dist = ranges::distance(__base_);
----------------
huixie90 wrote:

I was like why don't you use `ranges::size` here and that is exactly what you want to call since that is what is constrained on.  then I realised that oh you want to call `std::min` on two signed types so you used `ranges::distance` just for converting the types.  maybe 
```range_difference_t<_View> __dist = ranges::size(__base_);```
is the actual intent of the code?

https://github.com/llvm/llvm-project/pull/72929


More information about the libcxx-commits mailing list