[libcxx-commits] [libcxx] [libc++][ranges] implement `ranges::shift_left` (PR #83231)
Xiaoyang Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 4 23:55:29 PST 2024
================
@@ -24,30 +26,40 @@ _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>
+inline _LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter>
+__shift_left(_Iter __first, _Sent __last, typename iterator_traits<_Iter>::difference_type __n) {
+ _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last);
+
if (__n == 0) {
- return __last;
+ return {std::move(__first), std::move(__end)};
}
- _ForwardIterator __m = __first;
- if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
- if (__n >= __last - __first) {
- return __first;
+ _Iter __m = __first;
+ if constexpr (__has_random_access_iterator_category<_Iter>::value) {
----------------
xiaoyang-sde wrote:
Great! I refactored this function. More information: https://github.com/llvm/llvm-project/pull/83231#issuecomment-1978083955
https://github.com/llvm/llvm-project/pull/83231
More information about the libcxx-commits
mailing list