[libcxx-commits] [libcxx] [libc++][ranges] implement `ranges::shift_left` (PR #83231)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 23 10:31:30 PST 2026


================
@@ -24,30 +29,42 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 20
 
-template <class _ForwardIterator>
-inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
-shift_left(_ForwardIterator __first,
-           _ForwardIterator __last,
-           typename iterator_traits<_ForwardIterator>::difference_type __n) {
+template <class _AlgPolicy, class _Iter, class _Sent>
+_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter>
+__shift_left(_Iter __first, _Sent __last, typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __n) {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__n >= 0, "__n must be greater than or equal to 0");
----------------
ldionne wrote:

```suggestion
  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "__n must be greater than or equal to 0");
```

I would suggest `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` since this may lead to OOB accesses below in `std::__move`. I would also add a test to ensure that we catch this when hardening is enabled.

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


More information about the libcxx-commits mailing list