Path: blob/main/contrib/llvm-project/libcxx/include/__numeric/inclusive_scan.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H10#define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H1112#include <__config>13#include <__functional/operations.h>14#include <__iterator/iterator_traits.h>15#include <__utility/move.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223#if _LIBCPP_STD_VER >= 172425template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>26_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator27inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) {28for (; __first != __last; ++__first, (void)++__result) {29__init = __b(__init, *__first);30*__result = __init;31}32return __result;33}3435template <class _InputIterator, class _OutputIterator, class _BinaryOp>36_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator37inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) {38if (__first != __last) {39typename iterator_traits<_InputIterator>::value_type __init = *__first;40*__result++ = __init;41if (++__first != __last)42return std::inclusive_scan(__first, __last, __result, __b, __init);43}4445return __result;46}4748template <class _InputIterator, class _OutputIterator>49_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator50inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {51return std::inclusive_scan(__first, __last, __result, std::plus<>());52}5354#endif // _LIBCPP_STD_VER >= 175556_LIBCPP_END_NAMESPACE_STD5758#endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H596061