45 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H11#define _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H12 13#include <__cxx03/__config>14#include <__cxx03/__utility/move.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif19 20_LIBCPP_PUSH_MACROS21#include <__cxx03/__undef_macros>22 23_LIBCPP_BEGIN_NAMESPACE_STD24 25template <class _InputIterator, class _Tp>26_LIBCPP_HIDE_FROM_ABI _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) {27 for (; __first != __last; ++__first)28 __init = __init + *__first;29 return __init;30}31 32template <class _InputIterator, class _Tp, class _BinaryOperation>33_LIBCPP_HIDE_FROM_ABI _Tp34accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) {35 for (; __first != __last; ++__first)36 __init = __binary_op(__init, *__first);37 return __init;38}39 40_LIBCPP_END_NAMESPACE_STD41 42_LIBCPP_POP_MACROS43 44#endif // _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H45