Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/libcxx/include/__cxx03/__numeric/accumulate.h
213799 views
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
25
template <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
32
template <class _InputIterator, class _Tp, class _BinaryOperation>
33
_LIBCPP_HIDE_FROM_ABI _Tp
34
accumulate(_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
46