1*4824e7fdSDimitry Andric // -*- C++ -*- 2*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 3*4824e7fdSDimitry Andric // 4*4824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6*4824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4824e7fdSDimitry Andric // 8*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 9*4824e7fdSDimitry Andric 10*4824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H 11*4824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H 12*4824e7fdSDimitry Andric 13*4824e7fdSDimitry Andric #include <__config> 14*4824e7fdSDimitry Andric #include <__functional/operations.h> 15*4824e7fdSDimitry Andric #include <__iterator/iterator_traits.h> 16*4824e7fdSDimitry Andric #include <__utility/move.h> 17*4824e7fdSDimitry Andric 18*4824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19*4824e7fdSDimitry Andric # pragma GCC system_header 20*4824e7fdSDimitry Andric #endif 21*4824e7fdSDimitry Andric 22*4824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 23*4824e7fdSDimitry Andric 24*4824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 14 25*4824e7fdSDimitry Andric 26*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> 27*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator 28*4824e7fdSDimitry Andric inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) { 29*4824e7fdSDimitry Andric for (; __first != __last; ++__first, (void)++__result) { 30*4824e7fdSDimitry Andric __init = __b(__init, *__first); 31*4824e7fdSDimitry Andric *__result = __init; 32*4824e7fdSDimitry Andric } 33*4824e7fdSDimitry Andric return __result; 34*4824e7fdSDimitry Andric } 35*4824e7fdSDimitry Andric 36*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _BinaryOp> 37*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator 38*4824e7fdSDimitry Andric inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) { 39*4824e7fdSDimitry Andric if (__first != __last) { 40*4824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __init = *__first; 41*4824e7fdSDimitry Andric *__result++ = __init; 42*4824e7fdSDimitry Andric if (++__first != __last) 43*4824e7fdSDimitry Andric return _VSTD::inclusive_scan(__first, __last, __result, __b, __init); 44*4824e7fdSDimitry Andric } 45*4824e7fdSDimitry Andric 46*4824e7fdSDimitry Andric return __result; 47*4824e7fdSDimitry Andric } 48*4824e7fdSDimitry Andric 49*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator> 50*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first, 51*4824e7fdSDimitry Andric _InputIterator __last, 52*4824e7fdSDimitry Andric _OutputIterator __result) { 53*4824e7fdSDimitry Andric return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>()); 54*4824e7fdSDimitry Andric } 55*4824e7fdSDimitry Andric 56*4824e7fdSDimitry Andric #endif // _LIBCPP_STD_VER > 14 57*4824e7fdSDimitry Andric 58*4824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 59*4824e7fdSDimitry Andric 60*4824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H 61