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_TRANSFORM_INCLUSIVE_SCAN_H
11 #define _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
14 #include <__iterator/iterator_traits.h>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header
20 _LIBCPP_BEGIN_NAMESPACE_STD
22 #if _LIBCPP_STD_VER >= 17
24 template <class _InputIterator
, class _OutputIterator
, class _Tp
, class _BinaryOp
, class _UnaryOp
>
25 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
transform_inclusive_scan(
26 _InputIterator __first
, _InputIterator __last
, _OutputIterator __result
, _BinaryOp __b
, _UnaryOp __u
, _Tp __init
) {
27 for (; __first
!= __last
; ++__first
, (void)++__result
) {
28 __init
= __b(__init
, __u(*__first
));
35 template <class _InputIterator
, class _OutputIterator
, class _BinaryOp
, class _UnaryOp
>
36 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
transform_inclusive_scan(
37 _InputIterator __first
, _InputIterator __last
, _OutputIterator __result
, _BinaryOp __b
, _UnaryOp __u
) {
38 if (__first
!= __last
) {
39 typename iterator_traits
<_InputIterator
>::value_type __init
= __u(*__first
);
41 if (++__first
!= __last
)
42 return std::transform_inclusive_scan(__first
, __last
, __result
, __b
, __u
, __init
);
48 #endif // _LIBCPP_STD_VER >= 17
50 _LIBCPP_END_NAMESPACE_STD
52 #endif // _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H