Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __numeric / exclusive_scan.h
blobb6091f153a469aed850be85a20b4335ab5df7196
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
11 #define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
13 #include <__config>
14 #include <__functional/operations.h>
15 #include <__utility/move.h>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
19 #endif
21 _LIBCPP_PUSH_MACROS
22 #include <__undef_macros>
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 #if _LIBCPP_STD_VER >= 17
28 template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
29 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
30 exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
31 if (__first != __last) {
32 _Tp __tmp(__b(__init, *__first));
33 while (true) {
34 *__result = _VSTD::move(__init);
35 ++__result;
36 ++__first;
37 if (__first == __last)
38 break;
39 __init = _VSTD::move(__tmp);
40 __tmp = __b(__init, *__first);
43 return __result;
46 template <class _InputIterator, class _OutputIterator, class _Tp>
47 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
48 exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
49 return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
52 #endif // _LIBCPP_STD_VER >= 17
54 _LIBCPP_END_NAMESPACE_STD
56 _LIBCPP_POP_MACROS
58 #endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H