Warning: This file is not a C or C++ file. It does not have highlighting.

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-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H
11#define _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H
12
13#include <__cxx03/__config>
14#include <__cxx03/__utility/move.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_PUSH_MACROS
21#include <__cxx03/__undef_macros>
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
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 _Tp
34accumulate(_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_STD
41
42_LIBCPP_POP_MACROS
43
44#endif // _LIBCPP___CXX03___NUMERIC_ACCUMULATE_H
45

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/__cxx03/__numeric/accumulate.h