Path: blob/main/contrib/llvm-project/libcxx/include/__cxx03/__numeric/accumulate.h
213799 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___CXX03___NUMERIC_ACCUMULATE_H10#define _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H1112#include <__cxx03/__config>13#include <__cxx03/__utility/move.h>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_PUSH_MACROS20#include <__cxx03/__undef_macros>2122_LIBCPP_BEGIN_NAMESPACE_STD2324template <class _InputIterator, class _Tp>25_LIBCPP_HIDE_FROM_ABI _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) {26for (; __first != __last; ++__first)27__init = __init + *__first;28return __init;29}3031template <class _InputIterator, class _Tp, class _BinaryOperation>32_LIBCPP_HIDE_FROM_ABI _Tp33accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) {34for (; __first != __last; ++__first)35__init = __binary_op(__init, *__first);36return __init;37}3839_LIBCPP_END_NAMESPACE_STD4041_LIBCPP_POP_MACROS4243#endif // _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H444546