Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:12

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H
0010 #define _LIBCPP___ALGORITHM_SHIFT_LEFT_H
0011 
0012 #include <__algorithm/move.h>
0013 #include <__config>
0014 #include <__iterator/iterator_traits.h>
0015 
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 #  pragma GCC system_header
0018 #endif
0019 
0020 _LIBCPP_PUSH_MACROS
0021 #include <__undef_macros>
0022 
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024 
0025 #if _LIBCPP_STD_VER >= 20
0026 
0027 template <class _ForwardIterator>
0028 inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
0029 shift_left(_ForwardIterator __first,
0030            _ForwardIterator __last,
0031            typename iterator_traits<_ForwardIterator>::difference_type __n) {
0032   if (__n == 0) {
0033     return __last;
0034   }
0035 
0036   _ForwardIterator __m = __first;
0037   if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
0038     if (__n >= __last - __first) {
0039       return __first;
0040     }
0041     __m += __n;
0042   } else {
0043     for (; __n > 0; --__n) {
0044       if (__m == __last) {
0045         return __first;
0046       }
0047       ++__m;
0048     }
0049   }
0050   return std::move(__m, __last, __first);
0051 }
0052 
0053 #endif // _LIBCPP_STD_VER >= 20
0054 
0055 _LIBCPP_END_NAMESPACE_STD
0056 
0057 _LIBCPP_POP_MACROS
0058 
0059 #endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H