[libcxx-commits] [libcxx] [libc++] optimization on ranges::drop_view::begin (#72883) (PR #72929)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 14 07:49:46 PST 2023
================
@@ -104,7 +108,8 @@ namespace ranges {
constexpr auto begin() const
requires random_access_range<const _View> && sized_range<const _View>
{
- return ranges::next(ranges::begin(__base_), __count_, ranges::end(__base_));
+ range_difference_t<_View> __dist = ranges::distance(__base_);
+ return ranges::begin(__base_) + std::min(__count_, __dist);
----------------
huixie90 wrote:
> For my own edification, I attempted to answer this question ... it looks like the type is stripped of `const`/`&`?
>
> ```c++
> template <range _Rp>
> using range_difference_t = iter_difference_t<iterator_t<_Rp>>;
>
> // ...
>
> template <class _Ip>
> using iter_difference_t = typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,
> incrementable_traits<remove_cvref_t<_Ip> >,
> iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
> ```
I think this is unrelated. off course these traits needs to strip off `cvref`, but `iterator_t<_Rp>` and `iterator_t<const _Rp>` can well be two different types. (although one would argue that it is evil to let them have two different difference_type)
https://github.com/llvm/llvm-project/pull/72929
More information about the libcxx-commits
mailing list