Path: blob/main/contrib/llvm-project/libcxx/include/__numeric/partial_sum.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_PARTIAL_SUM_H10#define _LIBCPP___NUMERIC_PARTIAL_SUM_H1112#include <__config>13#include <__iterator/iterator_traits.h>14#include <__utility/move.h>1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif1920_LIBCPP_PUSH_MACROS21#include <__undef_macros>2223_LIBCPP_BEGIN_NAMESPACE_STD2425template <class _InputIterator, class _OutputIterator>26_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator27partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {28if (__first != __last) {29typename iterator_traits<_InputIterator>::value_type __t(*__first);30*__result = __t;31for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {32#if _LIBCPP_STD_VER >= 2033__t = std::move(__t) + *__first;34#else35__t = __t + *__first;36#endif37*__result = __t;38}39}40return __result;41}4243template <class _InputIterator, class _OutputIterator, class _BinaryOperation>44_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator45partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) {46if (__first != __last) {47typename iterator_traits<_InputIterator>::value_type __t(*__first);48*__result = __t;49for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {50#if _LIBCPP_STD_VER >= 2051__t = __binary_op(std::move(__t), *__first);52#else53__t = __binary_op(__t, *__first);54#endif55*__result = __t;56}57}58return __result;59}6061_LIBCPP_END_NAMESPACE_STD6263_LIBCPP_POP_MACROS6465#endif // _LIBCPP___NUMERIC_PARTIAL_SUM_H666768