[libcxx-commits] [libcxx] [libc++] optimization on ranges::drop_view::begin (#72883) (PR #72929)
Will Hawkins via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 13 11:44:21 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);
----------------
hawkinsw 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;
```
https://github.com/llvm/llvm-project/pull/72929
More information about the libcxx-commits
mailing list