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_INCLUSIVE_SCAN_H
11 #define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H
14 #include <__functional/operations.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__utility/move.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
22 _LIBCPP_BEGIN_NAMESPACE_STD
24 #if _LIBCPP_STD_VER >= 17
26 template <class _InputIterator
, class _OutputIterator
, class _Tp
, class _BinaryOp
>
27 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
28 inclusive_scan(_InputIterator __first
, _InputIterator __last
, _OutputIterator __result
, _BinaryOp __b
, _Tp __init
) {
29 for (; __first
!= __last
; ++__first
, (void)++__result
) {
30 __init
= __b(__init
, *__first
);
36 template <class _InputIterator
, class _OutputIterator
, class _BinaryOp
>
37 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
38 inclusive_scan(_InputIterator __first
, _InputIterator __last
, _OutputIterator __result
, _BinaryOp __b
) {
39 if (__first
!= __last
) {
40 typename iterator_traits
<_InputIterator
>::value_type __init
= *__first
;
42 if (++__first
!= __last
)
43 return std::inclusive_scan(__first
, __last
, __result
, __b
, __init
);
49 template <class _InputIterator
, class _OutputIterator
>
50 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
51 inclusive_scan(_InputIterator __first
, _InputIterator __last
, _OutputIterator __result
) {
52 return std::inclusive_scan(__first
, __last
, __result
, std::plus
<>());
55 #endif // _LIBCPP_STD_VER >= 17
57 _LIBCPP_END_NAMESPACE_STD
59 #endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H