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 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
11 #define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
12 
13 #include <__config>
14 #include <__functional/operations.h>
15 #include <__utility/move.h>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 #if _LIBCPP_STD_VER > 14
24 
25 template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
26 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
27 exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
28   if (__first != __last) {
29     _Tp __tmp(__b(__init, *__first));
30     while (true) {
31       *__result = _VSTD::move(__init);
32       ++__result;
33       ++__first;
34       if (__first == __last)
35         break;
36       __init = _VSTD::move(__tmp);
37       __tmp = __b(__init, *__first);
38     }
39   }
40   return __result;
41 }
42 
43 template <class _InputIterator, class _OutputIterator, class _Tp>
44 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
45 exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
46   return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
47 }
48 
49 #endif // _LIBCPP_STD_VER > 14
50 
51 _LIBCPP_END_NAMESPACE_STD
52 
53 #endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
54