2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
11 #define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
14 #include <__functional/operations.h>
15 #include <__utility/move.h>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
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
));
34 *__result
= _VSTD::move(__init
);
37 if (__first
== __last
)
39 __init
= _VSTD::move(__tmp
);
40 __tmp
= __b(__init
, *__first
);
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
58 #endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H