aboutsummaryrefslogtreecommitdiff
path: root/lib/libcxx/include/__algorithm/shift_left.h
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-02 10:45:56 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-02 10:45:56 -0700
commitdde0adcb363f3a3f306c0fc9eaec511cc3b74965 (patch)
tree9388d039a0b77211936c7264f5a3179f63ad51e6 /lib/libcxx/include/__algorithm/shift_left.h
parentc4cd592f0e1eeff5a4056796610d97010ae4e38c (diff)
parent7a2624c3e40e2386a4a8a775b839e1d67608ec42 (diff)
downloadzig-dde0adcb363f3a3f306c0fc9eaec511cc3b74965.tar.gz
zig-dde0adcb363f3a3f306c0fc9eaec511cc3b74965.zip
Merge branch 'llvm13'
Diffstat (limited to 'lib/libcxx/include/__algorithm/shift_left.h')
-rw-r--r--lib/libcxx/include/__algorithm/shift_left.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/libcxx/include/__algorithm/shift_left.h b/lib/libcxx/include/__algorithm/shift_left.h
new file mode 100644
index 0000000000..961b89cb00
--- /dev/null
+++ b/lib/libcxx/include/__algorithm/shift_left.h
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H
+#define _LIBCPP___ALGORITHM_SHIFT_LEFT_H
+
+#include <__config>
+#include <__algorithm/move.h>
+#include <__iterator/iterator_traits.h>
+#include <type_traits> // swap
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY constexpr
+_ForwardIterator
+shift_left(_ForwardIterator __first, _ForwardIterator __last,
+ typename iterator_traits<_ForwardIterator>::difference_type __n)
+{
+ if (__n == 0) {
+ return __last;
+ }
+
+ _ForwardIterator __m = __first;
+ if constexpr (__is_cpp17_random_access_iterator<_ForwardIterator>::value) {
+ if (__n >= __last - __first) {
+ return __first;
+ }
+ __m += __n;
+ } else {
+ for (; __n > 0; --__n) {
+ if (__m == __last) {
+ return __first;
+ }
+ ++__m;
+ }
+ }
+ return _VSTD::move(__m, __last, __first);
+}
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H